game: remove applying option for rulez random
[d2df-sdl.git] / src / game / g_monsters.pas
blobad887adfdd29d7e102c3a36069630eb0734437af
1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
16 {$M+}
17 {.$DEFINE D2F_DEBUG_MONS_MOVE}
18 unit g_monsters;
20 interface
22 uses
23 SysUtils, Classes,
24 mempool,
25 g_basic, e_graphics, g_phys, g_textures, g_grid,
26 g_saveload, g_panel, xprofiler;
28 const
29 MONSTATE_SLEEP = 0;
30 MONSTATE_GO = 1;
31 MONSTATE_RUN = 2;
32 MONSTATE_CLIMB = 3;
33 MONSTATE_DIE = 4;
34 MONSTATE_DEAD = 5;
35 MONSTATE_ATTACK = 6;
36 MONSTATE_SHOOT = 7;
37 MONSTATE_PAIN = 8;
38 MONSTATE_WAIT = 9;
39 MONSTATE_REVIVE = 10;
40 MONSTATE_RUNOUT = 11;
42 MON_BURN_TIME = 100;
44 { in mapdef now
45 BH_NORMAL = 0;
46 BH_KILLER = 1;
47 BH_MANIAC = 2;
48 BH_INSANE = 3;
49 BH_CANNIBAL = 4;
50 BH_GOOD = 5;
53 type
54 PMonster = ^TMonster;
55 TMonster = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
56 private
57 FMonsterType: Byte;
58 FUID: Word;
59 FDirection: TDirection;
60 FStartDirection: TDirection;
61 FStartX, FStartY: Integer;
62 FRemoved: Boolean;
63 FHealth: Integer;
64 FMaxHealth: Integer;
65 FState: Byte;
66 FCurAnim: Byte;
67 FAnim: Array of Array [TDirection.D_LEFT..TDirection.D_RIGHT] of TAnimation;
68 FTargetUID: Word;
69 FTargetTime: Integer;
70 FBehaviour: Byte;
71 FAmmo: Integer;
72 FPain: Integer;
73 FSleep: Integer;
74 FPainSound: Boolean;
75 FPainTicks: Integer;
76 FWaitAttackAnim: Boolean;
77 FChainFire: Boolean;
78 tx, ty: Integer;
79 FStartID: Integer;
80 FObj: TObj;
81 FBloodRed: Byte;
82 FBloodGreen: Byte;
83 FBloodBlue: Byte;
84 FBloodKind: Byte;
85 FShellTimer: Integer;
86 FShellType: Byte;
87 FFirePainTime: Integer;
88 FFireAttacker: Word;
89 vilefire: TAnimation;
90 mProxyId: Integer; // node in dyntree or -1
91 mArrIdx: Integer; // in gMonsters
93 FDieTriggers: Array of Integer;
94 FSpawnTrigger: Integer;
96 mNeedSend: Boolean; // for network
98 mEDamageType: Integer;
100 procedure Turn();
101 function findNewPrey(): Boolean;
102 procedure ActivateTriggers();
104 procedure setGameX (v: Integer); inline;
105 procedure setGameY (v: Integer); inline;
107 procedure doDamage (v: Integer);
109 public
110 FNoRespawn: Boolean;
111 FFireTime: Integer;
112 trapCheckFrameId: DWord; // for `g_weapons.CheckTrap()`
113 mplatCheckFrameId: LongWord;
115 constructor Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
116 destructor Destroy(); override;
117 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
118 function Collide(Panel: TPanel): Boolean; overload;
119 function Collide(X, Y: Integer): Boolean; overload;
120 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
121 function alive(): Boolean;
122 procedure SetHealth(aH: Integer);
123 procedure Push(vx, vy: Integer);
124 function Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
125 function Heal(Value: Word): Boolean;
126 procedure BFGHit();
127 procedure PreUpdate();
128 procedure Update();
129 procedure ClientUpdate();
130 procedure ClientAttack(wx, wy, atx, aty: Integer);
131 procedure SetDeadAnim;
132 procedure Draw();
133 procedure WakeUp();
134 procedure WakeUpSound();
135 procedure DieSound();
136 procedure PainSound();
137 procedure ActionSound();
138 procedure AddTrigger(t: Integer);
139 procedure ClearTriggers();
140 procedure Respawn();
141 procedure SaveState (st: TStream);
142 procedure LoadState (st: TStream);
143 procedure SetState(State: Byte; ForceAnim: Byte = 255);
144 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
145 procedure MakeBloodSimple(Count: Word);
146 procedure RevertAnim(R: Boolean = True);
147 function AnimIsReverse: Boolean;
148 function shoot(o: PObj; immediately: Boolean): Boolean;
149 function kick(o: PObj): Boolean;
150 procedure CatchFire(Attacker: Word; Timeout: Integer = MON_BURN_TIME);
151 procedure OnFireFlame(Times: DWORD = 1);
153 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
155 procedure setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline;
156 procedure moveBy (dx, dy: Integer); inline;
158 procedure getMapBox (out x, y, w, h: Integer); inline;
160 // get-and-clear
161 function gncNeedSend (): Boolean; inline;
162 procedure setDirty (); inline; // why `dirty`? 'cause i may introduce property `needSend` later
164 public
165 property Obj: TObj read FObj;
167 property proxyId: Integer read mProxyId;
168 property arrIdx: Integer read mArrIdx;
170 property MonsterType: Byte read FMonsterType;
171 property MonsterHealth: Integer read FHealth write FHealth;
172 property MonsterAmmo: Integer read FAmmo write FAmmo;
173 property MonsterTargetUID: Word read FTargetUID write FTargetUID;
174 property MonsterTargetTime: Integer read FTargetTime write FTargetTime;
175 property MonsterBehaviour: Byte read FBehaviour write FBehaviour;
176 property MonsterSleep: Integer read FSleep write FSleep;
177 property MonsterState: Byte read FState write FState;
178 property MonsterRemoved: Boolean read FRemoved write FRemoved;
179 property MonsterPain: Integer read FPain write FPain;
180 property MonsterAnim: Byte read FCurAnim write FCurAnim;
182 property UID: Word read FUID write FUID;
183 property SpawnTrigger: Integer read FSpawnTrigger write FSpawnTrigger;
185 property GameX: Integer read FObj.X write setGameX;
186 property GameY: Integer read FObj.Y write setGameY;
187 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
188 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
189 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
190 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
191 property GameDirection: TDirection read FDirection write FDirection;
193 property StartID: Integer read FStartID;
195 published
196 property eMonsterType: Byte read FMonsterType;
197 property eMonsterHealth: Integer read FHealth write FHealth;
198 property eMonsterAmmo: Integer read FAmmo write FAmmo;
199 property eMonsterTargetUID: Word read FTargetUID write FTargetUID;
200 property eMonsterTargetTime: Integer read FTargetTime write FTargetTime;
201 property eMonsterBehaviour: Byte read FBehaviour write FBehaviour;
202 property eMonsterSleep: Integer read FSleep write FSleep;
203 property eMonsterState: Byte read FState write FState;
204 property eMonsterRemoved: Boolean read FRemoved;
205 property eMonsterPain: Integer read FPain write FPain;
206 property eMonsterAnim: Byte read FCurAnim;
208 property eUID: Word read FUID;
209 property eSpawnTrigger: Integer read FSpawnTrigger;
211 property eGameX: Integer read FObj.X write setGameX;
212 property eGameY: Integer read FObj.Y write setGameY;
213 property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
214 property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
215 property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
216 property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
217 property eGameDirection: TDirection read FDirection write FDirection;
219 property eStartID: Integer read FStartID;
221 // set this before assigning something to `eDamage`
222 property eDamageType: Integer read mEDamageType write mEDamageType;
223 property eDamage: Integer write doDamage;
224 end;
227 // will be called from map loader
228 procedure g_Mons_InitTree (x, y, w, h: Integer);
230 procedure g_Monsters_LoadData ();
231 procedure g_Monsters_FreeData ();
232 procedure g_Monsters_Init ();
233 procedure g_Monsters_Free (clearGrid: Boolean=true);
234 function g_Monsters_Create (MonsterType: Byte; X, Y: Integer; Direction: TDirection;
235 AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
236 procedure g_Monsters_PreUpdate ();
237 procedure g_Monsters_Update ();
238 procedure g_Monsters_Draw ();
239 procedure g_Monsters_DrawHealth ();
240 function g_Monsters_ByUID (UID: Word): TMonster;
241 procedure g_Monsters_killedp ();
242 procedure g_Monsters_SaveState (st: TStream);
243 procedure g_Monsters_LoadState (st: TStream);
245 function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
246 function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
248 function g_Mons_TypeLo (): Integer; inline;
249 function g_Mons_TypeHi (): Integer; inline;
251 function g_Mons_TypeIdByName (const name: AnsiString): Integer;
252 function g_Mons_NameByTypeId (monType: Integer): AnsiString;
253 function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
256 type
257 TEachMonsterCB = function (mon: TMonster): Boolean is nested; // return `true` to stop
259 // throws on invalid uid
260 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
262 // can return null
263 function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
265 function g_Mons_TotalCount (): Integer; inline;
267 function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
269 function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
270 function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
272 function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
273 function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
275 function g_Mons_getNewTrapFrameId (): DWord; inline;
276 function g_Mons_getNewMPlatFrameId (): LongWord; inline;
280 type
281 TMonsAlongLineCB = function (mon: TMonster; tag: Integer): Boolean is nested;
283 function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
288 gmon_debug_use_sqaccel: Boolean = true;
291 //HACK!
292 procedure g_Mons_ProfilersBegin ();
293 procedure g_Mons_ProfilersEnd ();
295 procedure g_Mons_LOS_Start (); inline;
296 procedure g_Mons_LOS_End (); inline;
299 profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
302 type
303 TMonsterGrid = specialize TBodyGridBase<TMonster>;
306 monsGrid: TMonsterGrid = nil; // DO NOT USE! public for debugging only!
310 gmon_debug_think: Boolean = true;
311 gmon_debug_one_think_step: Boolean = false;
314 implementation
316 uses
317 e_log, e_texture, g_main, g_sound, g_gfx, g_player, g_game,
318 g_weapons, g_triggers, MAPDEF, g_items, g_options,
319 g_console, g_map, Math, g_menu, wadreader,
320 g_language, g_netmsg, idpool, utils, xstreams;
324 // ////////////////////////////////////////////////////////////////////////// //
325 procedure g_Mons_ProfilersBegin ();
326 begin
327 if (profMonsLOS = nil) then profMonsLOS := TProfiler.Create('LOS CALC', g_profile_history_size);
328 if (profMonsLOS <> nil) then profMonsLOS.mainBegin(g_profile_los);
329 if g_profile_los and (profMonsLOS <> nil) then
330 begin
331 profMonsLOS.sectionBegin('loscalc');
332 profMonsLOS.sectionEnd();
333 end;
334 end;
336 procedure g_Mons_ProfilersEnd ();
337 begin
338 if (profMonsLOS <> nil) and (g_profile_los) then profMonsLOS.mainEnd();
339 end;
341 procedure g_Mons_LOS_Start (); inline;
342 begin
343 if (profMonsLOS <> nil) then profMonsLOS.sectionBeginAccum('loscalc');
344 end;
346 procedure g_Mons_LOS_End (); inline;
347 begin
348 if (profMonsLOS <> nil) then profMonsLOS.sectionEnd();
349 end;
352 // ////////////////////////////////////////////////////////////////////////// //
354 monCheckTrapLastFrameId: DWord = 0;
355 monCheckMPlatLastFrameId: LongWord = 0;
358 procedure TMonster.getMapBox (out x, y, w, h: Integer); inline;
359 begin
360 x := FObj.X+FObj.Rect.X;
361 y := FObj.Y+FObj.Rect.Y;
362 w := FObj.Rect.Width;
363 h := FObj.Rect.Height;
364 end;
366 function TMonster.gncNeedSend (): Boolean; inline; begin result := mNeedSend; mNeedSend := false; end;
368 procedure TMonster.setDirty (); inline; begin mNeedSend := true; end;
371 // ////////////////////////////////////////////////////////////////////////// //
373 function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
374 begin
375 if not assigned(cb) then begin result := nil; exit; end;
376 result := monsGrid.forEachAlongLine(x0, y0, x1, y1, cb, -1, log);
377 end;
381 //WARNING! call this after monster position was changed, or coldet will not work right!
382 procedure TMonster.positionChanged ();
384 x, y, w, h: Integer;
385 nx, ny, nw, nh: Integer;
386 begin
387 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
388 //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);
389 {$ENDIF}
390 if (mProxyId = -1) then
391 begin
392 //mNeedSend := true;
393 mProxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
394 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
395 monsGrid.getBodyXY(mProxyId, x, y);
396 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);
397 {$ENDIF}
399 else
400 begin
401 monsGrid.getBodyDims(mProxyId, x, y, w, h);
402 getMapBox(nx, ny, nw, nh);
404 if (w <> nw) or (h <> nh) then
405 begin
406 //mNeedSend := true;
407 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
408 e_WriteLog(Format('monster #%d:(%u): resized; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
409 {$ENDIF}
410 monsGrid.moveResizeBody(mProxyId, nx, ny, nw, nh);
412 else if (x <> nx) or (y <> ny) then
413 begin
414 //mNeedSend := true;
415 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
416 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);
417 {$ENDIF}
418 monsGrid.moveBody(mProxyId, nx, ny);
420 else
421 begin
422 exit; // nothing to do
423 end;
424 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
425 monsGrid.getBodyXY(mProxyId, x, y);
426 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);
427 {$ENDIF}
428 end;
429 end;
432 // ////////////////////////////////////////////////////////////////////////// //
433 const
434 ANIM_SLEEP = 0;
435 ANIM_GO = 1;
436 ANIM_DIE = 2;
437 ANIM_MESS = 3;
438 ANIM_ATTACK = 4;
439 ANIM_ATTACK2 = 5;
440 ANIM_PAIN = 6;
442 MONSTER_SIGNATURE = $534E4F4D; // 'MONS'
444 // Òàáëèöà òèïîâ àíèìàöèè ìîíñòðîâ:
445 ANIMTABLE: Array [ANIM_SLEEP..ANIM_PAIN] of
446 record
447 name: String;
448 loop: Boolean;
449 end = ((name: 'SLEEP'; loop: True),
450 (name: 'GO'; loop: True),
451 (name: 'DIE'; loop: False),
452 (name: 'MESS'; loop: False),
453 (name: 'ATTACK'; loop: False),
454 (name: 'ATTACK2'; loop: False),
455 (name: 'PAIN'; loop: False));
457 // Òàáëèöà õàðàêòåðèñòèê ìîíñòðîâ:
458 MONSTERTABLE: Array [MONSTER_DEMON..MONSTER_MAN] of
459 record
460 Name: String;
461 Rect: TRectWH;
462 Health: Word;
463 RunVel: Byte;
464 MinPain: Byte;
465 Pain: Byte;
466 Jump: Byte;
467 end =
468 ((Name:'DEMON'; Rect:(X:7; Y:8; Width:50; Height:52); Health:60;
469 RunVel: 7; MinPain: 10; Pain: 20; Jump: 10),
471 (Name:'IMP'; Rect:(X:15; Y:10; Width:34; Height:50); Health:25;
472 RunVel: 3; MinPain: 0; Pain: 15; Jump: 10),
474 (Name:'ZOMBY'; Rect:(X:15; Y:8; Width:34; Height:52); Health:15;
475 RunVel: 3; MinPain: 0; Pain: 10; Jump: 10),
477 (Name:'SERG'; Rect:(X:15; Y:8; Width:34; Height:52); Health:20;
478 RunVel: 3; MinPain: 0; Pain: 10; Jump: 10),
480 (Name:'CYBER'; Rect:(X:24; Y:9; Width:80; Height:110); Health:500;
481 RunVel: 5; MinPain: 50; Pain: 70; Jump: 10),
483 (Name:'CGUN'; Rect:(X:15; Y:4; Width:34; Height:56); Health:60;
484 RunVel: 3; MinPain: 10; Pain: 20; Jump: 10),
486 (Name:'BARON'; Rect:(X:39; Y:32; Width:50; Height:64); Health:150;
487 RunVel: 3; MinPain: 30; Pain: 40; Jump: 10),
489 (Name:'KNIGHT'; Rect:(X:39; Y:32; Width:50; Height:64); Health:75;
490 RunVel: 3; MinPain: 30; Pain: 40; Jump: 10),
492 (Name:'CACO'; Rect:(X:34; Y:36; Width:60; Height:56); Health:100;
493 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
495 (Name:'SOUL'; Rect:(X:16; Y:14; Width:32; Height:36); Health:60;
496 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
498 (Name:'PAIN'; Rect:(X:34; Y:36; Width:60; Height:56); Health:100;
499 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
501 (Name:'SPIDER'; Rect:(X:23; Y:14; Width:210; Height:100); Health:500;
502 RunVel: 4; MinPain: 50; Pain: 70; Jump: 10),
504 (Name:'BSP'; Rect:(X:14; Y:17; Width:100; Height:42); Health:150;
505 RunVel: 4; MinPain: 0; Pain: 20; Jump: 10),
507 (Name:'MANCUB'; Rect:(X:28; Y:34; Width:72; Height:60); Health:200;
508 RunVel: 3; MinPain: 20; Pain: 40; Jump: 7),
510 (Name:'SKEL'; Rect:(X:30; Y:28; Width:68; Height:72); Health:200;
511 RunVel: 6; MinPain: 20; Pain: 40; Jump: 11),
513 (Name:'VILE'; Rect:(X:30; Y:28; Width:68; Height:72); Health:150;
514 RunVel: 7; MinPain: 10; Pain: 30; Jump: 12),
516 (Name:'FISH'; Rect:(X:6; Y:11; Width:20; Height:10); Health:35;
517 RunVel: 14; MinPain: 10; Pain: 20; Jump: 6),
519 (Name:'BARREL'; Rect:(X:20; Y:13; Width:24; Height:36); Health:20;
520 RunVel: 0; MinPain: 0; Pain: 0; Jump: 0),
522 (Name:'ROBO'; Rect:(X:30; Y:26; Width:68; Height:76); Health:20;
523 RunVel: 3; MinPain: 20; Pain: 40; Jump: 6),
525 (Name:'MAN'; Rect:(X:15; Y:6; Width:34; Height:52); Health:400;
526 RunVel: 8; MinPain: 50; Pain: 70; Jump: 10));
528 // Òàáëèöà ïàðàìåòðîâ àíèìàöèè ìîíñòðîâ:
529 MONSTER_ANIMTABLE: Array [MONSTER_DEMON..MONSTER_MAN] of
530 record
531 LeftAnim: Boolean;
532 wX, wY: Integer; // Îòêóäà âûëåòèò ïóëÿ
533 AnimSpeed: Array [ANIM_SLEEP..ANIM_PAIN] of Byte;
534 AnimDeltaRight: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
535 AnimDeltaLeft: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
536 end = // SLEEP GO DIE MESS ATTACK ATTACK2 PAIN
537 ((LeftAnim: False; wX: 54; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //DEMON
538 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));
539 AnimDeltaLeft: ((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))),
541 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //IMP
542 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));
543 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))),
545 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //ZOMBY
546 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));
547 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))),
549 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //SERG
550 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));
551 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))),
553 (LeftAnim: True; wX: 70; wY: 73; AnimSpeed:(3, 3, 3, 3, 3, 4, 3); //CYBER
554 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));
555 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))),
557 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 1, 0, 4); //CGUN
558 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));
559 AnimDeltaLeft: ((X: -1; Y: -2), (X: -1; Y: -2), (X: -2; Y: 0), (X: -2; Y: 0), (X: -1; Y: -4), (X: -1; Y: -4), (X: 2; Y: -4))),
561 (LeftAnim: True; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //BARON
562 AnimDeltaRight: ((X: 4; Y: 0), (X: 2; Y: 0), (X: -1; Y: -1), (X: -1; Y: -1), (X: 1; Y: 0), (X: 1; Y: 0), (X: -1; Y: 0));
563 AnimDeltaLeft: ((X: 0; Y: 0), (X: 2; Y: 0), (X: -1; Y: -1), (X: -1; Y: -1), (X: -2; Y: 0), (X: -2; Y: 0), (X: 1; Y: 0))),
565 (LeftAnim: True; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //KNIGHT
566 AnimDeltaRight: ((X: 4; Y: 0), (X: 2; Y: 0), (X: -1; Y: -1), (X: -1; Y: -1), (X: 1; Y: 0), (X: 1; Y: 0), (X: -1; Y: 0));
567 AnimDeltaLeft: ((X: 0; Y: 0), (X: 2; Y: 0), (X: -1; Y: -1), (X: -1; Y: -1), (X: -2; Y: 0), (X: -2; Y: 0), (X: 1; Y: 0))),
569 (LeftAnim: False; wX: 88; wY: 69; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //CACO
570 AnimDeltaRight: ((X: 0; Y: -4), (X: 0; Y: -4), (X: 0; Y: -5), (X: 0; Y: -5), (X: 0; Y: -4), (X: 0; Y: -4), (X: 0; Y: -4));
571 AnimDeltaLeft: ((X: 0; Y: -4), (X: 0; Y: -4), (X: 0; Y: -5), (X: 0; Y: -5), (X: 0; Y: -4), (X: 0; Y: -4), (X: 0; Y: -4))),
573 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 4, 1, 0, 4); //SOUL
574 AnimDeltaRight: ((X: 1; Y:-10), (X: 1; Y:-10), (X:-33; Y:-34), (X:-33; Y:-34), (X:-16; Y:-10), (X:-16; Y:-10), (X: -1; Y: -7));
575 AnimDeltaLeft: ((X: 1; Y:-10), (X: 1; Y:-10), (X:-33; Y:-34), (X:-33; Y:-34), (X:-16; Y:-10), (X:-16; Y:-10), (X: -1; Y: -7))),
577 (LeftAnim: False; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //PAIN
578 AnimDeltaRight: ((X: -1; Y: -3), (X: -1; Y: -3), (X: -3; Y: 0), (X: -3; Y: 0), (X: -1; Y: -3), (X: -1; Y: -3), (X: -1; Y: -4));
579 AnimDeltaLeft: ((X: -1; Y: -3), (X: -1; Y: -3), (X: -3; Y: 0), (X: -3; Y: 0), (X: -1; Y: -3), (X: -1; Y: -3), (X: -1; Y: -4))),
581 (LeftAnim: True; wX: 128; wY: 64; AnimSpeed:(3, 2, 4, 4, 1, 0, 4); //SPIDER
582 AnimDeltaRight: ((X: -4; Y: -4), (X: -4; Y: -4), (X: -2; Y: 8), (X: -2; Y: 8), (X: -3; Y: -3), (X: -3; Y: -3), (X: -3; Y: -4));
583 AnimDeltaLeft: ((X: -4; Y: -4), (X: -4; Y: -4), (X: -2; Y: 8), (X: -2; Y: 8), (X: -3; Y: -3), (X: -3; Y: -3), (X: 18; Y: -5))),
585 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 2, 3, 4, 1, 0, 4); //BSP
586 AnimDeltaRight: ((X: 0; Y: -1), (X: 0; Y: -1), (X: -3; Y: 5), (X: -3; Y: 5), (X: 7; Y: -1), (X: 7; Y: -1), (X: 1; Y: -3));
587 AnimDeltaLeft: ((X: 0; Y: -1), (X: 0; Y: -1), (X: -3; Y: 5), (X: -3; Y: 5), (X: 7; Y: -1), (X: 7; Y: -1), (X: 6; Y: -3))),
589 (LeftAnim: False; wX: 64; wY: 64; AnimSpeed:(3, 2, 2, 4, 2, 0, 4); //MANCUB
590 AnimDeltaRight: ((X: -2; Y: -7), (X: -2; Y: -7), (X: -4; Y: -2), (X: -4; Y: -2), (X: -4; Y: -7), (X: -4; Y: -7), (X:-14; Y: -7));
591 AnimDeltaLeft: ((X: -2; Y: -7), (X: -2; Y: -7), (X: -4; Y: -2), (X: -4; Y: -2), (X: -4; Y: -7), (X: -4; Y: -7), (X:-14; Y: -7))),
593 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 3, 3, 3, 3, 3, 3); //SKEL
594 AnimDeltaRight: ((X: -1; Y: 4), (X: -1; Y: 4), (X: -2; Y: 4), (X: -2; Y: 4), (X: -1; Y: 4), (X: 6; Y: 2), (X:-24; Y: 4));
595 AnimDeltaLeft: ((X: 1; Y: 4), (X: -1; Y: 4), (X: -2; Y: 4), (X: -2; Y: 4), (X: -2; Y: 2), (X: -5; Y: 4), (X: 26; Y: 4))),
597 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 3, 3, 3, 3, 3, 3); //VILE
598 AnimDeltaRight: ((X: 5; Y:-21), (X: 5; Y:-21), (X: 1; Y:-21), (X: 1; Y:-21), (X: 8; Y:-23), (X: -1; Y:-23), (X: 4; Y:-20));
599 AnimDeltaLeft: ((X: -8; Y:-21), (X: 5; Y:-21), (X: 1; Y:-21), (X: 1; Y:-21), (X:-10; Y:-24), (X: 3; Y:-23), (X: -4; Y:-22))),
601 (LeftAnim: False; wX: 8; wY: 8; AnimSpeed:(2, 2, 2, 2, 3, 0, 1); //FISH
602 AnimDeltaRight: ((X: -1; Y: 0), (X: -1; Y: 0), (X: -2; Y: -1), (X: -2; Y: -1), (X: -1; Y: -1), (X: -1; Y: -1), (X: -1; Y: -1));
603 AnimDeltaLeft: ((X: -1; Y: 0), (X: -1; Y: 0), (X: -2; Y: -1), (X: -2; Y: -1), (X: -1; Y: -1), (X: -1; Y: -1), (X: -1; Y: -1 ))),
605 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 0, 3, 0, 0, 0, 5); //BARREL
606 AnimDeltaRight: ((X: 0; Y:-15), (X: 0; Y:-15), (X: -1; Y:-15), (X: -1; Y:-15), (X: 0; Y:-15), (X: 0; Y:-15), (X: 0; Y:-15));
607 AnimDeltaLeft: ((X: 0; Y:-15), (X: 0; Y:-15), (X: -1; Y:-15), (X: -1; Y:-15), (X: 0; Y:-15), (X: 0; Y:-15), (X: 0; Y:-15))),
609 (LeftAnim: False; wX: 95; wY: 57; AnimSpeed:(1, 2, 1, 0, 1, 1, 0); //ROBO
610 AnimDeltaRight: ((X: -2; Y:-26), (X: -2; Y:-26), (X: 0; Y:-26), (X: 0; Y:-26), (X: 2; Y:-26), (X: 15; Y:-26), (X: -2; Y:-26));
611 AnimDeltaLeft: ((X: -2; Y:-26), (X: -2; Y:-26), (X: 0; Y:-26), (X: 0; Y:-26), (X: 2; Y:-26), (X: 15; Y:-26), (X: -2; Y:-26))),
613 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 2, 0, 5); //MAN
614 AnimDeltaRight: ((X: 0; Y: -6), (X: 0; Y: -6), (X: -2; Y: 0), (X: 2; Y: 0), (X: 1; Y: -6), (X: 1; Y: -6), (X: 0; Y: -6));
615 AnimDeltaLeft: ((X: 0; Y: -6), (X: 0; Y: -6), (X: -2; Y: 0), (X: 2; Y: 0), (X: 1; Y: -6), (X: 1; Y: -6), (X: 0; Y: -6))) );
617 MAX_ATM = 89; // Âðåìÿ îæèäàíèÿ ïîñëå ïîòåðè öåëè
618 MAX_SOUL = 512; // Îãðàíè÷åíèå Lost_Soul'îâ
621 // ////////////////////////////////////////////////////////////////////////// //
623 gMonsters: array of TMonster;
624 uidMap: array [0..65535] of TMonster; // monster knows it's index
625 freeInds: TIdPool = nil;
628 procedure clearUidMap ();
630 idx: Integer;
631 begin
632 for idx := 0 to High(uidMap) do uidMap[idx] := nil;
633 freeInds.clear();
634 end;
637 function g_Mons_getNewTrapFrameId (): DWord; inline;
639 f: Integer;
640 begin
641 Inc(monCheckTrapLastFrameId);
642 if (monCheckTrapLastFrameId = 0) then
643 begin
644 // wraparound
645 monCheckTrapLastFrameId := 1;
646 for f := 0 to High(gMonsters) do
647 begin
648 if (gMonsters[f] <> nil) then gMonsters[f].trapCheckFrameId := 0;
649 end;
650 end;
651 result := monCheckTrapLastFrameId;
652 end;
655 function g_Mons_getNewMPlatFrameId (): LongWord; inline;
657 f: Integer;
658 begin
659 Inc(monCheckMPlatLastFrameId);
660 if (monCheckMPlatLastFrameId = 0) then
661 begin
662 // wraparound
663 monCheckMPlatLastFrameId := 1;
664 for f := 0 to High(gMonsters) do
665 begin
666 if (gMonsters[f] <> nil) then gMonsters[f].mplatCheckFrameId := 0;
667 end;
668 end;
669 result := monCheckMPlatLastFrameId;
670 end;
674 pt_x: Integer = 0;
675 pt_xs: Integer = 1;
676 pt_y: Integer = 0;
677 pt_ys: Integer = 1;
678 soulcount: Integer = 0;
681 function allocMonster (): DWORD;
683 f, olen: Integer;
684 begin
685 result := freeInds.alloc();
686 if (result > High(gMonsters)) then
687 begin
688 olen := Length(gMonsters);
689 SetLength(gMonsters, result+64);
690 for f := olen to High(gMonsters) do gMonsters[f] := nil;
691 end;
692 end;
695 function IsFriend(a, b: Byte): Boolean;
696 begin
697 Result := True;
699 // Áî÷êà - âñåì äðóã:
700 if (a = MONSTER_BARREL) or (b = MONSTER_BARREL) then
701 Exit;
703 // Ìîíñòðû îäíîãî âèäà:
704 if a = b then
705 case a of
706 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
707 MONSTER_SOUL, MONSTER_PAIN, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
708 Exit; // Ýòè íå áüþò ñâîèõ
709 end;
711 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
712 if (a = MONSTER_SOUL) and (b = MONSTER_PAIN) then
713 Exit;
714 // Pain_Elemental íå ìîæåò ðàíèòü Lost_Soul'à:
715 if (b = MONSTER_SOUL) and (a = MONSTER_PAIN) then
716 Exit;
718 //  îñòàëüíûõ ñëó÷àÿõ - áóäóò áèòü äðóã äðóãà:
719 Result := False;
720 end;
723 function BehaviourDamage(SpawnerUID: Word; BH, SelfType: Byte): Boolean;
725 m: TMonster;
726 UIDType, MonsterType: Byte;
727 begin
728 Result := False;
729 MonsterType := 0;
731 UIDType := g_GetUIDType(SpawnerUID);
732 if UIDType = UID_MONSTER then
733 begin
734 m := g_Monsters_ByUID(SpawnerUID);
735 if m = nil then Exit;
736 MonsterType := m.FMonsterType;
737 end;
739 case BH of
740 BH_NORMAL: Result := (UIDType = UID_PLAYER) or
741 ((UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType)));
743 BH_KILLER: Result := UIDType = UID_PLAYER;
744 BH_MANIAC: Result := (UIDType = UID_PLAYER) or
745 ((UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType)));
747 BH_INSANE: Result := (UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType));
748 BH_CANNIBAL: Result := (UIDType = UID_MONSTER) and (MonsterType = SelfType);
749 end;
750 end;
753 function canShoot(m: Byte): Boolean;
754 begin
755 Result := False;
757 case m of
758 MONSTER_DEMON, MONSTER_FISH, MONSTER_BARREL:
759 Exit;
760 else
761 Result := True;
762 end;
763 end;
766 function isCorpse (o: PObj; immediately: Boolean): Integer;
769 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
770 begin
771 atag := atag; // shut up, fpc!
772 result := false; // don't stop
773 if (mon.FState = MONSTATE_DEAD) and g_Obj_Collide(o, @mon.FObj) then
774 begin
775 case mon.FMonsterType of // Íå âîñêðåñèòü:
776 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
777 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: exit;
778 end;
779 // Îñòàëüíûõ ìîæíî âîñêðåñèòü
780 result := true;
781 end;
782 end;
786 a: Integer;
787 mon: PMonster;
788 mres: TMonster = nil;
789 it: TMonsterGrid.Iter;
790 begin
791 result := -1;
793 // Åñëè íóæíà âåðîÿòíîñòü
794 if not immediately and (Random(8) <> 0) then exit;
796 // Èùåì ìåðòâûõ ìîíñòðîâ ïîáëèçîñòè
797 if gmon_debug_use_sqaccel then
798 begin
799 //mon := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height, monsCollCheck);
800 //if (mon <> nil) then result := mon.mArrIdx;
801 it := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height);
802 for mon in it do
803 begin
804 case mon.FMonsterType of // Íå âîñêðåñèòü:
805 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
806 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: begin end;
807 // Îñòàëüíûõ ìîæíî âîñêðåñèòü
808 else mres := mon^;
809 end;
810 if (mres <> nil) then break;
811 end;
812 it.release();
813 if (mres <> nil) then result := mres.mArrIdx;
815 else
816 begin
817 for a := 0 to High(gMonsters) do
818 begin
819 if (gMonsters[a] <> nil) and (gMonsters[a].FState = MONSTATE_DEAD) and g_Obj_Collide(o, @gMonsters[a].FObj) then
820 begin
821 case gMonsters[a].FMonsterType of // Íå âîñêðåñèòü:
822 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
823 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: Continue;
824 else // Îñòàëüíûõ ìîæíî âîñêðåñèòü
825 begin
826 Result := a;
827 Exit;
828 end;
829 end;
830 end;
831 end;
832 end;
833 end;
835 procedure g_Monsters_LoadData();
836 begin
837 e_WriteLog('Loading monsters data...', TMsgType.Notify);
839 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES], 133, False);
840 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_SLEEP', GameWAD+':MTEXTURES\BARREL_SLEEP', 64, 64, 3);
841 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_DIE', GameWAD+':MTEXTURES\BARREL_DIE', 64, 64, 4);
842 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_PAIN', GameWAD+':MTEXTURES\BARREL_PAIN', 64, 64, 1);
843 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_SLEEP', GameWAD+':MTEXTURES\ZOMBY_SLEEP', 64, 64, 2);
844 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_GO', GameWAD+':MTEXTURES\ZOMBY_GO', 64, 64, 4);
845 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_DIE', GameWAD+':MTEXTURES\ZOMBY_DIE', 64, 64, 6);
846 g_Game_StepLoading(6);
847 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_MESS', GameWAD+':MTEXTURES\ZOMBY_MESS', 64, 64, 9);
848 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK', GameWAD+':MTEXTURES\ZOMBY_ATTACK', 64, 64, 2);
849 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK_L', GameWAD+':MTEXTURES\ZOMBY_ATTACK_L', 64, 64, 2);
850 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_PAIN', GameWAD+':MTEXTURES\ZOMBY_PAIN', 64, 64, 1);
851 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_SLEEP', GameWAD+':MTEXTURES\SERG_SLEEP', 64, 64, 2);
852 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_GO', GameWAD+':MTEXTURES\SERG_GO', 64, 64, 4);
853 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_DIE', GameWAD+':MTEXTURES\SERG_DIE', 64, 64, 5);
854 g_Game_StepLoading(13);
855 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_MESS', GameWAD+':MTEXTURES\SERG_MESS', 64, 64, 9);
856 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK', GameWAD+':MTEXTURES\SERG_ATTACK', 64, 64, 2);
857 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK_L', GameWAD+':MTEXTURES\SERG_ATTACK_L', 64, 64, 2);
858 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_PAIN', GameWAD+':MTEXTURES\SERG_PAIN', 64, 64, 1);
859 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_SLEEP', GameWAD+':MTEXTURES\MAN_SLEEP', 64, 64, 2);
860 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_GO', GameWAD+':MTEXTURES\MAN_GO', 64, 64, 4);
861 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_DIE', GameWAD+':MTEXTURES\MAN_DIE', 64, 64, 7);
862 g_Game_StepLoading(20);
863 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_MESS', GameWAD+':MTEXTURES\MAN_MESS', 64, 64, 9);
864 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_ATTACK', GameWAD+':MTEXTURES\MAN_ATTACK', 64, 64, 2);
865 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_PAIN', GameWAD+':MTEXTURES\MAN_PAIN', 64, 64, 1);
866 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP', GameWAD+':MTEXTURES\CGUN_SLEEP', 64, 64, 2);
867 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP_L', GameWAD+':MTEXTURES\CGUN_SLEEP_L', 64, 64, 2);
868 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO', GameWAD+':MTEXTURES\CGUN_GO', 64, 64, 4);
869 g_Game_StepLoading(26);
870 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO_L', GameWAD+':MTEXTURES\CGUN_GO_L', 64, 64, 4);
871 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_DIE', GameWAD+':MTEXTURES\CGUN_DIE', 64, 64, 7);
872 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_MESS', GameWAD+':MTEXTURES\CGUN_MESS', 64, 64, 6);
873 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK', GameWAD+':MTEXTURES\CGUN_ATTACK', 64, 64, 2);
874 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK_L', GameWAD+':MTEXTURES\CGUN_ATTACK_L', 64, 64, 2);
875 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN', GameWAD+':MTEXTURES\CGUN_PAIN', 64, 64, 1);
876 g_Game_StepLoading(32);
877 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN_L', GameWAD+':MTEXTURES\CGUN_PAIN_L', 64, 64, 1);
878 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_SLEEP', GameWAD+':MTEXTURES\IMP_SLEEP', 64, 64, 2);
879 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_GO', GameWAD+':MTEXTURES\IMP_GO', 64, 64, 4);
880 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_DIE', GameWAD+':MTEXTURES\IMP_DIE', 64, 64, 5);
881 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_MESS', GameWAD+':MTEXTURES\IMP_MESS', 64, 64, 8);
882 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_ATTACK', GameWAD+':MTEXTURES\IMP_ATTACK', 64, 64, 3);
883 g_Game_StepLoading(38);
884 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_PAIN', GameWAD+':MTEXTURES\IMP_PAIN', 64, 64, 1);
885 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_SLEEP', GameWAD+':MTEXTURES\DEMON_SLEEP', 64, 64, 2);
886 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_GO', GameWAD+':MTEXTURES\DEMON_GO', 64, 64, 4);
887 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_DIE', GameWAD+':MTEXTURES\DEMON_DIE', 64, 64, 6);
888 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_ATTACK', GameWAD+':MTEXTURES\DEMON_ATTACK', 64, 64, 3);
889 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_PAIN', GameWAD+':MTEXTURES\DEMON_PAIN', 64, 64, 1);
890 g_Game_StepLoading(44);
891 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_SLEEP', GameWAD+':MTEXTURES\SOUL_SLEEP', 64, 64, 2);
892 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_GO', GameWAD+':MTEXTURES\SOUL_GO', 64, 64, 2);
893 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_PAIN', GameWAD+':MTEXTURES\SOUL_PAIN', 64, 64, 1);
894 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_ATTACK', GameWAD+':MTEXTURES\SOUL_ATTACK', 64, 64, 2);
895 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_DIE', GameWAD+':MTEXTURES\SOUL_DIE', 128, 128, 7);
896 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_SLEEP', GameWAD+':MTEXTURES\FISH_SLEEP', 32, 32, 2);
897 g_Game_StepLoading(50);
898 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_GO', GameWAD+':MTEXTURES\FISH_GO', 32, 32, 4);
899 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_PAIN', GameWAD+':MTEXTURES\FISH_PAIN', 32, 32, 3);
900 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_ATTACK', GameWAD+':MTEXTURES\FISH_ATTACK', 32, 32, 2);
901 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_DIE', GameWAD+':MTEXTURES\FISH_DIE', 32, 32, 1);
902 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_SLEEP', GameWAD+':MTEXTURES\SPIDER_SLEEP', 256, 128, 2);
903 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_GO', GameWAD+':MTEXTURES\SPIDER_GO', 256, 128, 6);
904 g_Game_StepLoading(56);
905 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN', GameWAD+':MTEXTURES\SPIDER_PAIN', 256, 128, 1);
906 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN_L', GameWAD+':MTEXTURES\SPIDER_PAIN_L', 256, 128, 1);
907 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_ATTACK', GameWAD+':MTEXTURES\SPIDER_ATTACK', 256, 128, 2);
908 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_DIE', GameWAD+':MTEXTURES\SPIDER_DIE', 256, 128, 10);
909 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_SLEEP', GameWAD+':MTEXTURES\BSP_SLEEP', 128, 64, 2);
910 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_GO', GameWAD+':MTEXTURES\BSP_GO', 128, 64, 6);
911 g_Game_StepLoading(62);
912 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN', GameWAD+':MTEXTURES\BSP_PAIN', 128, 64, 1);
913 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN_L', GameWAD+':MTEXTURES\BSP_PAIN_L', 128, 64, 1);
914 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_ATTACK', GameWAD+':MTEXTURES\BSP_ATTACK', 128, 64, 2);
915 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_DIE', GameWAD+':MTEXTURES\BSP_DIE', 128, 64, 7);
916 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_SLEEP', GameWAD+':MTEXTURES\CACO_SLEEP', 128, 128, 1);
917 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_GO', GameWAD+':MTEXTURES\CACO_GO', 128, 128, 1);
918 g_Game_StepLoading(68);
919 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_PAIN', GameWAD+':MTEXTURES\CACO_PAIN', 128, 128, 1);
920 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_ATTACK', GameWAD+':MTEXTURES\CACO_ATTACK', 128, 128, 6);
921 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_DIE', GameWAD+':MTEXTURES\CACO_DIE', 128, 128, 7);
922 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_SLEEP', GameWAD+':MTEXTURES\PAIN_SLEEP', 128, 128, 4);
923 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_GO', GameWAD+':MTEXTURES\PAIN_GO', 128, 128, 4);
924 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_PAIN', GameWAD+':MTEXTURES\PAIN_PAIN', 128, 128, 1);
925 g_Game_StepLoading(74);
926 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_ATTACK', GameWAD+':MTEXTURES\PAIN_ATTACK', 128, 128, 4);
927 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_DIE', GameWAD+':MTEXTURES\PAIN_DIE', 128, 128, 7);
928 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP', GameWAD+':MTEXTURES\BARON_SLEEP', 128, 128, 2);
929 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP_L', GameWAD+':MTEXTURES\BARON_SLEEP_L', 128, 128, 2);
930 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_GO', GameWAD+':MTEXTURES\BARON_GO', 128, 128, 4);
931 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN', GameWAD+':MTEXTURES\BARON_PAIN', 128, 128, 1);
932 g_Game_StepLoading(80);
933 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN_L', GameWAD+':MTEXTURES\BARON_PAIN_L', 128, 128, 1);
934 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK', GameWAD+':MTEXTURES\BARON_ATTACK', 128, 128, 3);
935 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK_L', GameWAD+':MTEXTURES\BARON_ATTACK_L', 128, 128, 3);
936 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_DIE', GameWAD+':MTEXTURES\BARON_DIE', 128, 128, 7);
937 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP', GameWAD+':MTEXTURES\KNIGHT_SLEEP', 128, 128, 2);
938 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP_L', GameWAD+':MTEXTURES\KNIGHT_SLEEP_L', 128, 128, 2);
939 g_Game_StepLoading(86);
940 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_GO', GameWAD+':MTEXTURES\KNIGHT_GO', 128, 128, 4);
941 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN', GameWAD+':MTEXTURES\KNIGHT_PAIN', 128, 128, 1);
942 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN_L', GameWAD+':MTEXTURES\KNIGHT_PAIN_L', 128, 128, 1);
943 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK', GameWAD+':MTEXTURES\KNIGHT_ATTACK', 128, 128, 3);
944 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK_L', GameWAD+':MTEXTURES\KNIGHT_ATTACK_L', 128, 128, 3);
945 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_DIE', GameWAD+':MTEXTURES\KNIGHT_DIE', 128, 128, 7);
946 g_Game_StepLoading(92);
947 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_SLEEP', GameWAD+':MTEXTURES\MANCUB_SLEEP', 128, 128, 2);
948 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_GO', GameWAD+':MTEXTURES\MANCUB_GO', 128, 128, 6);
949 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_PAIN', GameWAD+':MTEXTURES\MANCUB_PAIN', 128, 128, 1);
950 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_ATTACK', GameWAD+':MTEXTURES\MANCUB_ATTACK', 128, 128, 3);
951 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_DIE', GameWAD+':MTEXTURES\MANCUB_DIE', 128, 128, 10);
952 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP', GameWAD+':MTEXTURES\SKEL_SLEEP', 128, 128, 2);
953 g_Game_StepLoading(98);
954 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP_L', GameWAD+':MTEXTURES\SKEL_SLEEP_L', 128, 128, 2);
955 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_GO', GameWAD+':MTEXTURES\SKEL_GO', 128, 128, 6);
956 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN', GameWAD+':MTEXTURES\SKEL_PAIN', 128, 128, 1);
957 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN_L', GameWAD+':MTEXTURES\SKEL_PAIN_L', 128, 128, 1);
958 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK', GameWAD+':MTEXTURES\SKEL_ATTACK', 128, 128, 2);
959 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK_L', GameWAD+':MTEXTURES\SKEL_ATTACK_L', 128, 128, 2);
960 g_Game_StepLoading(104);
961 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2', GameWAD+':MTEXTURES\SKEL_ATTACK2', 128, 128, 2);
962 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2_L', GameWAD+':MTEXTURES\SKEL_ATTACK2_L', 128, 128, 2);
963 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_DIE', GameWAD+':MTEXTURES\SKEL_DIE', 128, 128, 5);
964 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP', GameWAD+':MTEXTURES\VILE_SLEEP', 128, 128, 2);
965 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP_L', GameWAD+':MTEXTURES\VILE_SLEEP_L', 128, 128, 2);
966 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_GO', GameWAD+':MTEXTURES\VILE_GO', 128, 128, 6);
967 g_Game_StepLoading(110);
968 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN', GameWAD+':MTEXTURES\VILE_PAIN', 128, 128, 1);
969 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN_L', GameWAD+':MTEXTURES\VILE_PAIN_L', 128, 128, 1);
970 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK', GameWAD+':MTEXTURES\VILE_ATTACK', 128, 128, 10);
971 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK_L', GameWAD+':MTEXTURES\VILE_ATTACK_L', 128, 128, 10);
972 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2', GameWAD+':MTEXTURES\VILE_ATTACK2', 128, 128, 3);
973 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2_L', GameWAD+':MTEXTURES\VILE_ATTACK2_L', 128, 128, 3);
974 g_Game_StepLoading(116);
975 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_DIE', GameWAD+':MTEXTURES\VILE_DIE', 128, 128, 9);
976 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_SLEEP', GameWAD+':MTEXTURES\ROBO_SLEEP', 128, 128, 1);
977 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_GO', GameWAD+':MTEXTURES\ROBO_GO', 128, 128, 12);
978 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK', GameWAD+':MTEXTURES\ROBO_ATTACK', 128, 128, 2);
979 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK2', GameWAD+':MTEXTURES\ROBO_ATTACK2', 128, 128, 4);
980 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_DIE', GameWAD+':MTEXTURES\ROBO_DIE', 128, 128, 1);
981 g_Game_StepLoading(122);
982 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP', GameWAD+':MTEXTURES\CYBER_SLEEP', 128, 128, 2);
983 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP_L', GameWAD+':MTEXTURES\CYBER_SLEEP_L', 128, 128, 2);
984 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO', GameWAD+':MTEXTURES\CYBER_GO', 128, 128, 4);
985 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO_L', GameWAD+':MTEXTURES\CYBER_GO_L', 128, 128, 4);
986 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN', GameWAD+':MTEXTURES\CYBER_PAIN', 128, 128, 1);
987 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN_L', GameWAD+':MTEXTURES\CYBER_PAIN_L', 128, 128, 1);
988 g_Game_StepLoading(128);
989 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK', GameWAD+':MTEXTURES\CYBER_ATTACK', 128, 128, 2);
990 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK_L', GameWAD+':MTEXTURES\CYBER_ATTACK_L', 128, 128, 2);
991 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2', GameWAD+':MTEXTURES\CYBER_ATTACK2', 128, 128, 2);
992 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2_L', GameWAD+':MTEXTURES\CYBER_ATTACK2_L', 128, 128, 2);
993 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_DIE', GameWAD+':MTEXTURES\CYBER_DIE', 128, 128, 9);
994 g_Game_StepLoading(133);
996 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_SOUNDS], 0, False);
998 g_Sound_CreateWADEx('SOUND_MONSTER_BARREL_DIE', GameWAD+':MSOUNDS\BARREL_DIE');
1000 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN', GameWAD+':MSOUNDS\PAIN');
1001 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN2', GameWAD+':MSOUNDS\PAIN2');
1002 g_Sound_CreateWADEx('SOUND_MONSTER_ACTION', GameWAD+':MSOUNDS\ACTION');
1003 g_Sound_CreateWADEx('SOUND_MONSTER_ACTION2', GameWAD+':MSOUNDS\ACTION2');
1004 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_1', GameWAD+':MSOUNDS\ALERT_1');
1005 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_2', GameWAD+':MSOUNDS\ALERT_2');
1006 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_3', GameWAD+':MSOUNDS\ALERT_3');
1007 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_1', GameWAD+':MSOUNDS\DIE_1');
1008 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_2', GameWAD+':MSOUNDS\DIE_2');
1009 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_3', GameWAD+':MSOUNDS\DIE_3');
1010 g_Sound_CreateWADEx('SOUND_MONSTER_SLOP', GameWAD+':MSOUNDS\SLOP');
1012 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_ATTACK', GameWAD+':MSOUNDS\DEMON_ATTACK');
1013 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_ALERT', GameWAD+':MSOUNDS\DEMON_ALERT');
1014 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_DIE', GameWAD+':MSOUNDS\DEMON_DIE');
1016 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ALERT_1', GameWAD+':MSOUNDS\IMP_ALERT_1');
1017 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ALERT_2', GameWAD+':MSOUNDS\IMP_ALERT_2');
1018 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_DIE_1', GameWAD+':MSOUNDS\IMP_DIE_1');
1019 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_DIE_2', GameWAD+':MSOUNDS\IMP_DIE_2');
1020 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ACTION', GameWAD+':MSOUNDS\IMP_ACTION');
1021 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ATTACK', GameWAD+':MSOUNDS\IMP_ATTACK');
1023 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_PAIN', GameWAD+':MSOUNDS\MAN_PAIN');
1024 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_ALERT', GameWAD+':MSOUNDS\MAN_ALERT');
1025 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_DIE', GameWAD+':MSOUNDS\MAN_DIE');
1026 g_Sound_CreateWADEx('SOUND_MONSTER_HAHA', GameWAD+':MSOUNDS\HAHA');
1027 g_Sound_CreateWADEx('SOUND_MONSTER_TRUP', GameWAD+':MSOUNDS\TRUP');
1029 g_Sound_CreateWADEx('SOUND_MONSTER_SOUL_ATTACK', GameWAD+':MSOUNDS\SOUL_ATTACK');
1030 g_Sound_CreateWADEx('SOUND_MONSTER_SOUL_DIE', GameWAD+':MSOUNDS\SOUL_DIE');
1032 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_ACTION', GameWAD+':MSOUNDS\BSP_ACTION');
1033 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_DIE', GameWAD+':MSOUNDS\BSP_DIE');
1034 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_ALERT', GameWAD+':MSOUNDS\BSP_ALERT');
1035 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_WALK', GameWAD+':MSOUNDS\BSP_WALK');
1037 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ACTION', GameWAD+':MSOUNDS\VILE_ACTION');
1038 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_PAIN', GameWAD+':MSOUNDS\VILE_PAIN');
1039 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_DIE', GameWAD+':MSOUNDS\VILE_DIE');
1040 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ALERT', GameWAD+':MSOUNDS\VILE_ALERT');
1041 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ATTACK', GameWAD+':MSOUNDS\VILE_ATTACK');
1043 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ACTION', GameWAD+':MSOUNDS\SKEL_ACTION');
1044 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_DIE', GameWAD+':MSOUNDS\SKEL_DIE');
1045 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ALERT', GameWAD+':MSOUNDS\SKEL_ALERT');
1046 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ATTACK', GameWAD+':MSOUNDS\SKEL_ATTACK');
1047 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_HIT', GameWAD+':MSOUNDS\SKEL_HIT');
1049 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_PAIN', GameWAD+':MSOUNDS\MANCUB_PAIN');
1050 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_DIE', GameWAD+':MSOUNDS\MANCUB_DIE');
1051 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_ALERT', GameWAD+':MSOUNDS\MANCUB_ALERT');
1052 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_ATTACK', GameWAD+':MSOUNDS\MANCUB_ATTACK');
1054 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_PAIN', GameWAD+':MSOUNDS\PAIN_PAIN');
1055 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_DIE', GameWAD+':MSOUNDS\PAIN_DIE');
1056 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_ALERT', GameWAD+':MSOUNDS\PAIN_ALERT');
1058 g_Sound_CreateWADEx('SOUND_MONSTER_BARON_DIE', GameWAD+':MSOUNDS\BARON_DIE');
1059 g_Sound_CreateWADEx('SOUND_MONSTER_BARON_ALERT', GameWAD+':MSOUNDS\BARON_ALERT');
1061 g_Sound_CreateWADEx('SOUND_MONSTER_CACO_DIE', GameWAD+':MSOUNDS\CACO_DIE');
1062 g_Sound_CreateWADEx('SOUND_MONSTER_CACO_ALERT', GameWAD+':MSOUNDS\CACO_ALERT');
1064 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_DIE', GameWAD+':MSOUNDS\CYBER_DIE');
1065 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_ALERT', GameWAD+':MSOUNDS\CYBER_ALERT');
1066 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_WALK', GameWAD+':MSOUNDS\CYBER_WALK');
1068 g_Sound_CreateWADEx('SOUND_MONSTER_KNIGHT_DIE', GameWAD+':MSOUNDS\KNIGHT_DIE');
1069 g_Sound_CreateWADEx('SOUND_MONSTER_KNIGHT_ALERT', GameWAD+':MSOUNDS\KNIGHT_ALERT');
1071 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_DIE', GameWAD+':MSOUNDS\SPIDER_DIE');
1072 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_ALERT', GameWAD+':MSOUNDS\SPIDER_ALERT');
1073 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_WALK', GameWAD+':MSOUNDS\SPIDER_WALK');
1075 g_Sound_CreateWADEx('SOUND_MONSTER_FISH_ATTACK', GameWAD+':MSOUNDS\FISH_ATTACK');
1077 freeInds := TIdPool.Create();
1078 clearUidMap();
1079 monCheckTrapLastFrameId := 0;
1080 monCheckMPlatLastFrameId := 0;
1081 end;
1083 procedure g_Monsters_FreeData();
1084 begin
1085 e_WriteLog('Releasing monsters data...', TMsgType.Notify);
1087 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_SLEEP');
1088 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_PAIN');
1089 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_DIE');
1090 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_SLEEP');
1091 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_GO');
1092 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_DIE');
1093 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_MESS');
1094 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK');
1095 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK_L');
1096 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_PAIN');
1097 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_SLEEP');
1098 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_GO');
1099 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_DIE');
1100 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_MESS');
1101 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK');
1102 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK_L');
1103 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_PAIN');
1104 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_SLEEP');
1105 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_GO');
1106 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_DIE');
1107 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_MESS');
1108 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_ATTACK');
1109 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_PAIN');
1110 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_SLEEP');
1111 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_SLEEP_L');
1112 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_GO');
1113 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_GO_L');
1114 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_DIE');
1115 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_MESS');
1116 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_ATTACK');
1117 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_ATTACK_L');
1118 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_PAIN');
1119 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_PAIN_L');
1120 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_SLEEP');
1121 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_GO');
1122 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_DIE');
1123 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_MESS');
1124 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_ATTACK');
1125 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_PAIN');
1126 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_SLEEP');
1127 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_GO');
1128 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_DIE');
1129 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_ATTACK');
1130 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_PAIN');
1131 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_SLEEP');
1132 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_GO');
1133 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_PAIN');
1134 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_ATTACK');
1135 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_DIE');
1136 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_SLEEP');
1137 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_GO');
1138 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_PAIN');
1139 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_ATTACK');
1140 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_DIE');
1141 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_SLEEP');
1142 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_GO');
1143 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_PAIN');
1144 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_PAIN_L');
1145 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_ATTACK');
1146 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_DIE');
1147 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_SLEEP');
1148 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_GO');
1149 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_PAIN');
1150 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_PAIN_L');
1151 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_ATTACK');
1152 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_DIE');
1153 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_SLEEP');
1154 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_GO');
1155 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_PAIN');
1156 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_ATTACK');
1157 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_DIE');
1158 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_SLEEP');
1159 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_GO');
1160 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_PAIN');
1161 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_ATTACK');
1162 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_DIE');
1163 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_SLEEP');
1164 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_SLEEP_L');
1165 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_GO');
1166 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_PAIN');
1167 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_PAIN_L');
1168 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_ATTACK');
1169 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_ATTACK_L');
1170 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_DIE');
1171 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_SLEEP');
1172 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_SLEEP_L');
1173 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_GO');
1174 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_PAIN');
1175 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_PAIN_L');
1176 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_ATTACK');
1177 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_ATTACK_L');
1178 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_DIE');
1179 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_SLEEP');
1180 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_GO');
1181 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_PAIN');
1182 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_ATTACK');
1183 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_DIE');
1184 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_SLEEP');
1185 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_SLEEP_L');
1186 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_GO');
1187 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_PAIN');
1188 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_PAIN_L');
1189 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK');
1190 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK_L');
1191 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK2');
1192 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK2_L');
1193 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_DIE');
1194 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_SLEEP');
1195 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_SLEEP_L');
1196 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_GO');
1197 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_PAIN');
1198 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_PAIN_L');
1199 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK');
1200 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK_L');
1201 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK2');
1202 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK2_L');
1203 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_DIE');
1204 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_SLEEP');
1205 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_GO');
1206 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_ATTACK');
1207 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_ATTACK2');
1208 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_DIE');
1209 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_SLEEP');
1210 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_SLEEP_L');
1211 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_GO');
1212 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_GO_L');
1213 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN');
1214 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN_L');
1215 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK');
1216 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK_L');
1217 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2');
1218 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2_L');
1219 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_DIE');
1221 g_Sound_Delete('SOUND_MONSTER_BARREL_DIE');
1223 g_Sound_Delete('SOUND_MONSTER_PAIN');
1224 g_Sound_Delete('SOUND_MONSTER_PAIN2');
1225 g_Sound_Delete('SOUND_MONSTER_ACTION');
1226 g_Sound_Delete('SOUND_MONSTER_ACTION2');
1227 g_Sound_Delete('SOUND_MONSTER_ALERT_1');
1228 g_Sound_Delete('SOUND_MONSTER_ALERT_2');
1229 g_Sound_Delete('SOUND_MONSTER_ALERT_3');
1230 g_Sound_Delete('SOUND_MONSTER_DIE_1');
1231 g_Sound_Delete('SOUND_MONSTER_DIE_2');
1232 g_Sound_Delete('SOUND_MONSTER_DIE_3');
1233 g_Sound_Delete('SOUND_MONSTER_SLOP');
1235 g_Sound_Delete('SOUND_MONSTER_DEMON_ATTACK');
1236 g_Sound_Delete('SOUND_MONSTER_DEMON_ALERT');
1237 g_Sound_Delete('SOUND_MONSTER_DEMON_DIE');
1239 g_Sound_Delete('SOUND_MONSTER_IMP_ALERT_1');
1240 g_Sound_Delete('SOUND_MONSTER_IMP_ALERT_2');
1241 g_Sound_Delete('SOUND_MONSTER_IMP_DIE_1');
1242 g_Sound_Delete('SOUND_MONSTER_IMP_DIE_2');
1243 g_Sound_Delete('SOUND_MONSTER_IMP_ACTION');
1244 g_Sound_Delete('SOUND_MONSTER_IMP_ATTACK');
1246 g_Sound_Delete('SOUND_MONSTER_MAN_PAIN');
1247 g_Sound_Delete('SOUND_MONSTER_MAN_ALERT');
1248 g_Sound_Delete('SOUND_MONSTER_MAN_DIE');
1249 g_Sound_Delete('SOUND_MONSTER_HAHA');
1250 g_Sound_Delete('SOUND_MONSTER_TRUP');
1252 g_Sound_Delete('SOUND_MONSTER_SOUL_ATTACK');
1253 g_Sound_Delete('SOUND_MONSTER_SOUL_DIE');
1255 g_Sound_Delete('SOUND_MONSTER_BSP_ACTION');
1256 g_Sound_Delete('SOUND_MONSTER_BSP_DIE');
1257 g_Sound_Delete('SOUND_MONSTER_BSP_ALERT');
1258 g_Sound_Delete('SOUND_MONSTER_BSP_WALK');
1260 g_Sound_Delete('SOUND_MONSTER_VILE_ACTION');
1261 g_Sound_Delete('SOUND_MONSTER_VILE_PAIN');
1262 g_Sound_Delete('SOUND_MONSTER_VILE_DIE');
1263 g_Sound_Delete('SOUND_MONSTER_VILE_ALERT');
1264 g_Sound_Delete('SOUND_MONSTER_VILE_ATTACK');
1266 g_Sound_Delete('SOUND_MONSTER_SKEL_ACTION');
1267 g_Sound_Delete('SOUND_MONSTER_SKEL_DIE');
1268 g_Sound_Delete('SOUND_MONSTER_SKEL_ALERT');
1269 g_Sound_Delete('SOUND_MONSTER_SKEL_ATTACK');
1270 g_Sound_Delete('SOUND_MONSTER_SKEL_HIT');
1272 g_Sound_Delete('SOUND_MONSTER_MANCUB_PAIN');
1273 g_Sound_Delete('SOUND_MONSTER_MANCUB_DIE');
1274 g_Sound_Delete('SOUND_MONSTER_MANCUB_ALERT');
1275 g_Sound_Delete('SOUND_MONSTER_MANCUB_ATTACK');
1277 g_Sound_Delete('SOUND_MONSTER_PAIN_PAIN');
1278 g_Sound_Delete('SOUND_MONSTER_PAIN_DIE');
1279 g_Sound_Delete('SOUND_MONSTER_PAIN_ALERT');
1281 g_Sound_Delete('SOUND_MONSTER_BARON_DIE');
1282 g_Sound_Delete('SOUND_MONSTER_BARON_ALERT');
1284 g_Sound_Delete('SOUND_MONSTER_CACO_DIE');
1285 g_Sound_Delete('SOUND_MONSTER_CACO_ALERT');
1287 g_Sound_Delete('SOUND_MONSTER_CYBER_DIE');
1288 g_Sound_Delete('SOUND_MONSTER_CYBER_ALERT');
1289 g_Sound_Delete('SOUND_MONSTER_CYBER_WALK');
1291 g_Sound_Delete('SOUND_MONSTER_KNIGHT_DIE');
1292 g_Sound_Delete('SOUND_MONSTER_KNIGHT_ALERT');
1294 g_Sound_Delete('SOUND_MONSTER_SPIDER_DIE');
1295 g_Sound_Delete('SOUND_MONSTER_SPIDER_ALERT');
1296 g_Sound_Delete('SOUND_MONSTER_SPIDER_WALK');
1298 g_Sound_Delete('SOUND_MONSTER_FISH_ATTACK');
1300 freeInds.Free();
1301 freeInds := nil;
1302 end;
1304 procedure g_Monsters_Init();
1305 begin
1306 soulcount := 0;
1307 end;
1309 procedure g_Monsters_Free (clearGrid: Boolean=true);
1311 a: Integer;
1312 begin
1313 e_LogWritefln('Cleared monster data (clearGrid=%s)', [clearGrid]);
1314 if (clearGrid) then
1315 begin
1316 monsGrid.Free();
1317 monsGrid := nil;
1318 end;
1319 for a := 0 to High(gMonsters) do gMonsters[a].Free();
1320 gMonsters := nil;
1321 clearUidMap();
1322 monCheckTrapLastFrameId := 0;
1323 monCheckMPlatLastFrameId := 0;
1324 end;
1327 // will be called from map loader
1328 procedure g_Mons_InitTree (x, y, w, h: Integer);
1329 begin
1330 monsGrid.Free();
1331 monsGrid := TMonsterGrid.Create(x, y, w, h);
1332 //clearUidMap(); // why not?
1333 e_LogWritefln('%s', ['Recreated monster tree']);
1334 end;
1337 function g_Monsters_Create(MonsterType: Byte; X, Y: Integer;
1338 Direction: TDirection; AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
1340 find_id: DWORD;
1341 mon: TMonster;
1342 begin
1343 result := nil;
1345 // Íåò òàêîãî ìîíñòðà
1346 if (MonsterType > MONSTER_MAN) or (MonsterType = 0) then exit;
1348 // Ñîáëþäàåì îãðàíè÷åíèå Lost_Soul'îâ
1349 if MonsterType = MONSTER_SOUL then
1350 begin
1351 if soulcount > MAX_SOUL then exit;
1352 soulcount := soulcount + 1;
1353 end;
1355 find_id := allocMonster();
1357 mon := TMonster.Create(MonsterType, find_id, ForcedUID);
1358 gMonsters[find_id] := mon;
1359 mon.mArrIdx := find_id;
1360 mon.mProxyId := -1;
1362 uidMap[mon.FUID] := mon;
1364 // Íàñòðàèâàåì ïîëîæåíèå
1365 with mon do
1366 begin
1367 if AdjCoord then
1368 begin
1369 FObj.X := X-FObj.Rect.X - (FObj.Rect.Width div 2);
1370 FObj.Y := Y-FObj.Rect.Y - FObj.Rect.Height;
1372 else
1373 begin
1374 FObj.X := X-FObj.Rect.X;
1375 FObj.Y := Y-FObj.Rect.Y;
1376 end;
1378 FDirection := Direction;
1379 FStartDirection := Direction;
1380 FStartX := GameX;
1381 FStartY := GameY;
1382 FObj.oldX := FObj.X;
1383 FObj.oldY := FObj.Y;
1384 end;
1386 mon.positionChanged();
1388 result := mon;
1389 end;
1391 procedure g_Monsters_killedp();
1393 a, h: Integer;
1394 begin
1395 if gMonsters = nil then
1396 Exit;
1398 // Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
1399 h := High(gMonsters);
1400 for a := 0 to h do
1401 begin
1402 if (gMonsters[a] <> nil) then
1403 begin
1404 with gMonsters[a] do
1405 begin
1406 if (FMonsterType = MONSTER_MAN) and
1407 (FState <> MONSTATE_DEAD) and
1408 (FState <> MONSTATE_SLEEP) and
1409 (FState <> MONSTATE_DIE) then
1410 begin
1411 g_Sound_PlayExAt('SOUND_MONSTER_TRUP', FObj.X, FObj.Y);
1412 Exit;
1413 end;
1414 end;
1415 end;
1416 end;
1417 end;
1419 procedure g_Monsters_PreUpdate();
1421 a: Integer;
1422 begin
1423 if gMonsters = nil then Exit;
1424 for a := 0 to High(gMonsters) do
1425 if (gMonsters[a] <> nil) and (not gMonsters[a].FRemoved) then
1426 gMonsters[a].PreUpdate();
1427 end;
1429 procedure g_Monsters_Update();
1431 a: Integer;
1432 begin
1433 // Öåëåóêàçàòåëü
1434 if gTime mod (GAME_TICK*2) = 0 then
1435 begin
1436 pt_x := pt_x+pt_xs;
1437 pt_y := pt_y+pt_ys;
1438 if abs(pt_x) > 246 then pt_xs := -pt_xs;
1439 if abs(pt_y) > 100 then pt_ys := -pt_ys;
1440 end;
1442 gMon := True; // Äëÿ ðàáîòû BlockMon'à
1444 if gmon_debug_think or gmon_debug_one_think_step then
1445 begin
1446 gmon_debug_one_think_step := false;
1447 for a := 0 to High(gMonsters) do
1448 begin
1449 if (gMonsters[a] = nil) then continue;
1450 if not gMonsters[a].FRemoved then
1451 begin
1452 if g_Game_IsClient then
1453 gMonsters[a].ClientUpdate()
1454 else
1455 gMonsters[a].Update();
1457 else
1458 begin
1459 gMonsters[a].Free();
1460 gMonsters[a] := nil;
1461 end;
1462 end;
1463 end;
1465 gMon := False;
1466 end;
1468 procedure g_Monsters_Draw();
1470 a: Integer;
1471 begin
1472 if gMonsters <> nil then
1473 begin
1474 for a := 0 to High(gMonsters) do
1475 begin
1476 if (gMonsters[a] <> nil) then gMonsters[a].Draw();
1477 end;
1478 end;
1479 end;
1481 procedure g_Monsters_DrawHealth();
1483 a: Integer;
1484 fW, fH: Byte;
1485 begin
1486 if gMonsters = nil then Exit;
1487 e_TextureFontGetSize(gStdFont, fW, fH);
1489 for a := 0 to High(gMonsters) do
1490 begin
1491 if gMonsters[a] <> nil then
1492 begin
1493 e_TextureFontPrint(gMonsters[a].FObj.X + gMonsters[a].FObj.Rect.X,
1494 gMonsters[a].FObj.Y + gMonsters[a].FObj.Rect.Y + gMonsters[a].FObj.Rect.Height - fH,
1495 IntToStr(gMonsters[a].FHealth), gStdFont);
1496 end;
1497 end;
1498 end;
1500 function g_Monsters_ByUID (UID: Word): TMonster;
1501 begin
1502 result := uidMap[UID];
1503 end;
1505 procedure g_Monsters_SaveState (st: TStream);
1507 count, i: Integer;
1508 begin
1509 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ
1510 count := 0;
1511 for i := 0 to High(gMonsters) do
1512 begin
1513 if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then count += 1;
1514 end;
1516 // Ñîõðàíÿåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1517 utils.writeInt(st, LongInt(pt_x));
1518 utils.writeInt(st, LongInt(pt_xs));
1519 utils.writeInt(st, LongInt(pt_y));
1520 utils.writeInt(st, LongInt(pt_ys));
1522 // Êîëè÷åñòâî ìîíñòðîâ
1523 utils.writeInt(st, LongInt(count));
1525 if (count = 0) then exit;
1527 // Ñîõðàíÿåì ìîíñòðîâ
1528 for i := 0 to High(gMonsters) do
1529 begin
1530 if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then
1531 begin
1532 // Òèï ìîíñòðà
1533 utils.writeInt(st, Byte(gMonsters[i].MonsterType));
1534 // Ñîõðàíÿåì äàííûå ìîíñòðà:
1535 gMonsters[i].SaveState(st);
1536 end;
1537 end;
1538 end;
1541 procedure g_Monsters_LoadState (st: TStream);
1543 count, a: Integer;
1544 b: Byte;
1545 mon: TMonster;
1546 begin
1547 assert(st <> nil);
1549 g_Monsters_Free(false);
1551 // Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1552 pt_x := utils.readLongInt(st);
1553 pt_xs := utils.readLongInt(st);
1554 pt_y := utils.readLongInt(st);
1555 pt_ys := utils.readLongInt(st);
1557 // Êîëè÷åñòâî ìîíñòðîâ
1558 count := utils.readLongInt(st);
1560 if (count = 0) then exit;
1561 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid monster count');
1563 // Çàãðóæàåì ìîíñòðîâ
1564 for a := 0 to count-1 do
1565 begin
1566 // Òèï ìîíñòðà
1567 b := utils.readByte(st);
1568 // Ñîçäàåì ìîíñòðà
1569 mon := g_Monsters_Create(b, 0, 0, TDirection.D_LEFT);
1570 if (mon = nil) then raise XStreamError.Create('g_Monsters_LoadState: ID = -1 (can''t create)');
1571 // Çàãðóæàåì äàííûå ìîíñòðà
1572 mon.LoadState(st);
1573 end;
1574 end;
1577 // ////////////////////////////////////////////////////////////////////////// //
1578 function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
1579 begin
1580 result := nil;
1581 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1582 begin
1583 result := g_Monsters_Create(monType, x, y, dir);
1584 end;
1585 end;
1588 function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
1589 begin
1590 result := g_Mons_SpawnAt(g_Mons_TypeIdByName(typeName), x, y, dir);
1591 end;
1595 // ////////////////////////////////////////////////////////////////////////// //
1596 function g_Mons_TypeLo (): Integer; inline; begin result := Low(MONSTERTABLE); end;
1597 function g_Mons_TypeHi (): Integer; inline; begin result := High(MONSTERTABLE); end;
1600 function g_Mons_TypeIdByName (const name: String): Integer;
1602 i: Integer;
1603 begin
1604 i := MONSTER_DEMON;
1605 while (i <= MONSTER_MAN) do
1606 begin
1607 if (CompareText(name, MONSTERTABLE[i].Name) = 0) then
1608 begin
1609 result := i;
1610 exit;
1611 end;
1612 Inc(i);
1613 end;
1614 result := -1;
1615 // HACK!
1616 if (CompareText(name, 'zombie') = 0) then result := MONSTER_ZOMBY;
1617 end;
1620 function g_Mons_NameByTypeId (monType: Integer): AnsiString;
1621 begin
1622 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1623 result := MONSTERTABLE[monType].Name
1624 else
1625 result := '?';
1626 end;
1629 function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
1630 begin
1631 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1632 Result := KilledByMonster[monType]
1633 else
1634 Result := '?';
1635 end;
1638 // ////////////////////////////////////////////////////////////////////////// //
1639 { T M o n s t e r : }
1641 procedure TMonster.setGameX (v: Integer); inline; begin FObj.X := v; positionChanged(); end;
1642 procedure TMonster.setGameY (v: Integer); inline; begin FObj.Y := v; positionChanged(); end;
1644 procedure TMonster.setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline; begin FObj.X := ax; FObj.Y := ay; if callPosChanged then positionChanged(); end;
1646 procedure TMonster.moveBy (dx, dy: Integer); inline;
1647 begin
1648 if (dx <> 0) or (dy <> 0) then
1649 begin
1650 FObj.X += dx;
1651 FObj.Y += dy;
1652 positionChanged();
1653 end;
1654 end;
1656 procedure TMonster.doDamage (v: Integer);
1657 begin
1658 if (v <= 0) then exit;
1659 if (v > 32767) then v := 32767;
1660 Damage(v, 0, 0, 0, mEDamageType);
1661 end;
1663 procedure TMonster.ActionSound();
1664 begin
1665 case FMonsterType of
1666 MONSTER_IMP:
1667 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ACTION', FObj.X, FObj.Y);
1668 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN,
1669 MONSTER_MANCUB:
1670 g_Sound_PlayExAt('SOUND_MONSTER_ACTION', FObj.X, FObj.Y);
1671 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1672 MONSTER_KNIGHT, MONSTER_PAIN, MONSTER_DEMON,
1673 MONSTER_SPIDER:
1674 g_Sound_PlayExAt('SOUND_MONSTER_ACTION2', FObj.X, FObj.Y);
1675 MONSTER_BSP:
1676 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ACTION', FObj.X, FObj.Y);
1677 MONSTER_VILE:
1678 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ACTION', FObj.X, FObj.Y);
1679 MONSTER_SKEL:
1680 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ACTION', FObj.X, FObj.Y);
1681 MONSTER_CYBER:
1683 MONSTER_MAN:
1684 g_Sound_PlayExAt('SOUND_MONSTER_HAHA', FObj.X, FObj.Y);
1685 end;
1686 end;
1688 procedure TMonster.PainSound();
1689 begin
1690 if FPainSound then
1691 Exit;
1693 FPainSound := True;
1694 FPainTicks := 20;
1696 case FMonsterType of
1697 MONSTER_IMP, MONSTER_ZOMBY, MONSTER_SERG,
1698 MONSTER_SKEL, MONSTER_CGUN:
1699 g_Sound_PlayExAt('SOUND_MONSTER_PAIN', FObj.X, FObj.Y);
1700 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1701 MONSTER_KNIGHT, MONSTER_DEMON, MONSTER_SPIDER,
1702 MONSTER_BSP, MONSTER_CYBER:
1703 g_Sound_PlayExAt('SOUND_MONSTER_PAIN2', FObj.X, FObj.Y);
1704 MONSTER_VILE:
1705 g_Sound_PlayExAt('SOUND_MONSTER_VILE_PAIN', FObj.X, FObj.Y);
1706 MONSTER_MANCUB:
1707 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_PAIN', FObj.X, FObj.Y);
1708 MONSTER_PAIN:
1709 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_PAIN', FObj.X, FObj.Y);
1710 MONSTER_MAN:
1711 g_Sound_PlayExAt('SOUND_MONSTER_MAN_PAIN', FObj.X, FObj.Y);
1712 end;
1713 end;
1715 procedure TMonster.DieSound();
1716 begin
1717 case FMonsterType of
1718 MONSTER_IMP:
1719 case Random(2) of
1720 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_1', FObj.X, FObj.Y);
1721 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_2', FObj.X, FObj.Y);
1722 end;
1723 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1724 case Random(3) of
1725 0: g_Sound_PlayExAt('SOUND_MONSTER_DIE_1', FObj.X, FObj.Y);
1726 1: g_Sound_PlayExAt('SOUND_MONSTER_DIE_2', FObj.X, FObj.Y);
1727 2: g_Sound_PlayExAt('SOUND_MONSTER_DIE_3', FObj.X, FObj.Y);
1728 end;
1729 MONSTER_DEMON:
1730 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_DIE', FObj.X, FObj.Y);
1731 MONSTER_BARREL:
1732 g_Sound_PlayExAt('SOUND_MONSTER_BARREL_DIE', FObj.X, FObj.Y);
1733 MONSTER_SOUL:
1734 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_DIE', FObj.X, FObj.Y);
1735 MONSTER_BSP:
1736 g_Sound_PlayExAt('SOUND_MONSTER_BSP_DIE', FObj.X, FObj.Y);
1737 MONSTER_VILE:
1738 g_Sound_PlayExAt('SOUND_MONSTER_VILE_DIE', FObj.X, FObj.Y);
1739 MONSTER_BARON:
1740 g_Sound_PlayExAt('SOUND_MONSTER_BARON_DIE', FObj.X, FObj.Y);
1741 MONSTER_CACO:
1742 g_Sound_PlayExAt('SOUND_MONSTER_CACO_DIE', FObj.X, FObj.Y);
1743 MONSTER_CYBER:
1744 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_DIE', FObj.X, FObj.Y);
1745 MONSTER_KNIGHT:
1746 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_DIE', FObj.X, FObj.Y);
1747 MONSTER_MANCUB:
1748 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_DIE', FObj.X, FObj.Y);
1749 MONSTER_PAIN:
1750 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_DIE', FObj.X, FObj.Y);
1751 MONSTER_SKEL:
1752 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_DIE', FObj.X, FObj.Y);
1753 MONSTER_SPIDER:
1754 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_DIE', FObj.X, FObj.Y);
1755 MONSTER_MAN:
1756 g_Sound_PlayExAt('SOUND_MONSTER_MAN_DIE', FObj.X, FObj.Y);
1757 end;
1758 end;
1760 procedure TMonster.WakeUpSound();
1761 begin
1762 case FMonsterType of
1763 MONSTER_IMP:
1764 case Random(2) of
1765 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_1', FObj.X, FObj.Y);
1766 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_2', FObj.X, FObj.Y);
1767 end;
1768 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1769 case Random(3) of
1770 0: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_1', FObj.X, FObj.Y);
1771 1: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_2', FObj.X, FObj.Y);
1772 2: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_3', FObj.X, FObj.Y);
1773 end;
1774 MONSTER_MAN:
1775 g_Sound_PlayExAt('SOUND_MONSTER_MAN_ALERT', FObj.X, FObj.Y);
1776 MONSTER_BSP:
1777 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ALERT', FObj.X, FObj.Y);
1778 MONSTER_VILE:
1779 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ALERT', FObj.X, FObj.Y);
1780 MONSTER_BARON:
1781 g_Sound_PlayExAt('SOUND_MONSTER_BARON_ALERT', FObj.X, FObj.Y);
1782 MONSTER_CACO:
1783 g_Sound_PlayExAt('SOUND_MONSTER_CACO_ALERT', FObj.X, FObj.Y);
1784 MONSTER_CYBER:
1785 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_ALERT', FObj.X, FObj.Y);
1786 MONSTER_KNIGHT:
1787 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_ALERT', FObj.X, FObj.Y);
1788 MONSTER_MANCUB:
1789 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ALERT', FObj.X, FObj.Y);
1790 MONSTER_PAIN:
1791 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_ALERT', FObj.X, FObj.Y);
1792 MONSTER_DEMON:
1793 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ALERT', FObj.X, FObj.Y);
1794 MONSTER_SKEL:
1795 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ALERT', FObj.X, FObj.Y);
1796 MONSTER_SPIDER:
1797 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_ALERT', FObj.X, FObj.Y);
1798 MONSTER_SOUL:
1800 end;
1801 end;
1803 procedure TMonster.BFGHit();
1804 begin
1805 if FMonsterType = MONSTER_FISH then
1806 Exit;
1808 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1809 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1810 {if g_Game_IsServer and g_Game_IsNet then
1811 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1812 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1813 0, NET_GFX_BFG);}
1814 end;
1816 function TMonster.Collide(X, Y: Integer; Width, Height: Word): Boolean;
1817 begin
1818 Result := g_Collide(FObj.X+FObj.Rect.X,
1819 FObj.Y+FObj.Rect.Y,
1820 FObj.Rect.Width,
1821 FObj.Rect.Height,
1822 X, Y,
1823 Width, Height);
1824 end;
1826 function TMonster.Collide(Panel: TPanel): Boolean;
1827 begin
1828 Result := g_Collide(FObj.X+FObj.Rect.X,
1829 FObj.Y+FObj.Rect.Y,
1830 FObj.Rect.Width,
1831 FObj.Rect.Height,
1832 Panel.X, Panel.Y,
1833 Panel.Width, Panel.Height);
1834 end;
1836 function TMonster.Collide(X, Y: Integer): Boolean;
1837 begin
1838 X := X - FObj.X - FObj.Rect.X;
1839 Y := Y - FObj.Y - FObj.Rect.Y;
1840 Result := (x >= 0) and (x <= FObj.Rect.Width) and
1841 (y >= 0) and (y <= FObj.Rect.Height);
1842 end;
1844 procedure TMonster.Respawn;
1845 begin
1846 FObj.Vel.X := 0;
1847 FObj.Vel.Y := 0;
1848 FObj.Accel.X := 0;
1849 FObj.Accel.Y := 0;
1850 FDirection := FStartDirection;
1851 {GameX}FObj.X := FStartX;
1852 {GameY}FObj.Y := FStartY;
1853 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
1854 FHealth := MONSTERTABLE[FMonsterType].Health;
1855 FAmmo := 0;
1856 FPain := 0;
1857 FTargetUID := 0;
1858 FTargetTime := 0;
1859 FDieTriggers := nil;
1860 FWaitAttackAnim := False;
1861 FChainFire := False;
1862 FShellTimer := -1;
1864 FState := MONSTATE_SLEEP;
1865 FCurAnim := ANIM_SLEEP;
1867 positionChanged(); // this updates spatial accelerators
1869 if g_Game_IsNet and g_Game_IsServer then
1870 begin
1871 MH_SEND_MonsterPos(FUID);
1872 MH_SEND_MonsterState(FUID);
1873 end;
1874 end;
1876 constructor TMonster.Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
1878 a: Integer;
1879 FramesID: DWORD = 0;
1880 s: String;
1881 res: Boolean;
1882 begin
1883 if ForcedUID < 0 then
1884 FUID := g_CreateUID(UID_MONSTER)
1885 else
1886 FUID := ForcedUID;
1888 FMonsterType := MonsterType;
1890 g_Obj_Init(@FObj);
1892 FState := MONSTATE_SLEEP;
1893 FCurAnim := ANIM_SLEEP;
1894 FHealth := MONSTERTABLE[MonsterType].Health;
1895 FMaxHealth := FHealth;
1896 FObj.Rect := MONSTERTABLE[MonsterType].Rect;
1897 FDieTriggers := nil;
1898 FSpawnTrigger := -1;
1899 FWaitAttackAnim := False;
1900 FChainFire := False;
1901 FStartID := aID;
1902 FNoRespawn := False;
1903 FShellTimer := -1;
1904 FBehaviour := BH_NORMAL;
1905 FFireTime := 0;
1906 FFirePainTime := 0;
1907 FFireAttacker := 0;
1908 mEDamageType := HIT_SOME;
1910 mProxyId := -1;
1911 mArrIdx := -1;
1912 trapCheckFrameId := 0;
1913 mplatCheckFrameId := 0;
1914 mNeedSend := false;
1916 if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
1917 FBloodKind := BLOOD_SPARKS
1918 else
1919 FBloodKind := BLOOD_NORMAL;
1920 if FMonsterType = MONSTER_CACO then
1921 begin
1922 FBloodRed := 0;
1923 FBloodGreen := 0;
1924 FBloodBlue := 150;
1926 else if FMonsterType in [MONSTER_BARON, MONSTER_KNIGHT] then
1927 begin
1928 FBloodRed := 0;
1929 FBloodGreen := 150;
1930 FBloodBlue := 0;
1932 else
1933 begin
1934 FBloodRed := 150;
1935 FBloodGreen := 0;
1936 FBloodBlue := 0;
1937 end;
1939 SetLength(FAnim, Length(ANIMTABLE));
1941 for a := 0 to High(FAnim) do
1942 begin
1943 FAnim[a, TDirection.D_LEFT] := nil;
1944 FAnim[a, TDirection.D_RIGHT] := nil;
1945 end;
1947 for a := ANIM_SLEEP to ANIM_PAIN do
1948 if (ANIMTABLE[a].name <> '') and
1949 (MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a] <> 0) then
1950 begin
1951 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1952 '_'+ANIMTABLE[a].name;
1954 res := g_Frames_Exists(s);
1956 if res then
1957 res := g_Frames_Get(FramesID, s);
1959 // Åñëè íåò òàêîé àíèìàöèè, òî ïðîáóåì çàìåíèòü åå íà àíèìàöèþ ñìåðòè:
1960 if (not res) then
1961 begin
1962 // Çàìåíÿåì òîëüêî ANIM_MESS íà ANIM_DIE:
1963 if a <> ANIM_MESS then
1964 Continue;
1966 if g_Frames_Get(FramesID, 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1967 '_'+ANIMTABLE[ANIM_DIE].name) then
1968 begin
1969 FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1970 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1971 FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1972 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1973 Continue;
1974 end;
1975 end;
1977 FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1978 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1980 // Åñëè åñòü îòäåëüíàÿ ëåâàÿ àíèìàöèÿ - çàãðóæàåì:
1981 if MONSTER_ANIMTABLE[MonsterType].LeftAnim then
1982 begin
1983 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1984 '_'+ANIMTABLE[a].name+'_L';
1985 if g_Frames_Exists(s) then
1986 g_Frames_Get(FramesID, s);
1987 end;
1989 FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1990 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1991 end;
1993 // Äëÿ êîëäóíà çàãðóæàåì òàêæå àíèìàöèþ îãíÿ:
1994 if MonsterType = MONSTER_VILE then
1995 begin
1996 g_Frames_Get(FramesID, 'FRAMES_FIRE');
1997 vilefire := TAnimation.Create(FramesID, True, 2);
1999 else
2000 vilefire := nil;
2001 end;
2003 function TMonster.Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
2005 c, it: Integer;
2006 p: TPlayer;
2007 begin
2008 Result := False;
2010 // Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
2011 if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
2013 // Óìèðàåò, óìåð èëè âîñêðåøàåòñÿ => óðîí äåëàòü íåêîìó:
2014 if (FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE) or (FState = MONSTATE_REVIVE) then
2015 Exit;
2017 // Ðûáó â âîäå áüåò òîêîì => ïàíèêà áåç óðîíà:
2018 if (t = HIT_ELECTRO) and (FMonsterType = MONSTER_FISH) and g_Game_IsServer then
2019 begin
2020 FSleep := 20;
2021 if Random(2) = 0 then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
2022 Result := True;
2023 SetState(MONSTATE_RUN);
2024 Exit;
2025 end;
2027 // Àð÷è íå ãîðÿò, ÷åðåïà óæå ãîðÿò
2028 if (t = HIT_FLAME) and (FMonsterType in [MONSTER_VILE, MONSTER_SOUL]) then
2029 begin
2030 // Ïðîñíóòüñÿ âñå-òàêè ñòîèò
2031 if FState = MONSTATE_SLEEP then
2032 SetState(MONSTATE_GO);
2033 Exit;
2034 end;
2036 // Ëîâóøêà óáèâàåò ñðàçó:
2037 if t = HIT_TRAP then
2038 FHealth := -100;
2040 // Ðîáîòó óðîíà íåò:
2041 if FMonsterType = MONSTER_ROBO then
2042 aDamage := 0;
2044 // Íàíîñèì óðîí:
2045 if g_Game_IsServer then Dec(FHealth, aDamage);
2047 // Óñèëèâàåì áîëü ìîíñòðà îò óðîíà:
2048 if FPain = 0 then
2049 FPain := 3;
2050 FPain := FPain+aDamage;
2052 // Åñëè áîëü ñóùåñòâåííàÿ, òî ìåíÿåì ñîñòîÿíèå íà áîëåâîå:
2053 if FState <> MONSTATE_PAIN then
2054 if (FPain >= MONSTERTABLE[FMonsterType].MinPain) and
2055 (FMonsterType <> MONSTER_BARREL) then
2056 SetState(MONSTATE_PAIN);
2058 // Åñëè ðàçðåøåíà êðîâü - ñîçäàåì áðûçãè êðîâè:
2059 if (gBloodCount > 0) then
2060 begin
2061 c := Min(aDamage, 200);
2062 c := c*gBloodCount - (aDamage div 4) + Random(c div 2);
2064 if (VelX = 0) and (VelY = 0) then
2065 MakeBloodSimple(c)
2066 else
2067 case t of
2068 HIT_TRAP, HIT_ACID, HIT_ELECTRO, HIT_FLAME: MakeBloodSimple(c);
2069 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, VelX, VelY);
2070 end;
2071 end;
2073 // Òåïåðü öåëü - óäàðèâøèé, åñëè òîëüêî íå ñàì ñåáÿ:
2074 if (SpawnerUID <> FUID) and (BehaviourDamage(SpawnerUID, FBehaviour, FMonsterType)) then
2075 begin
2076 FTargetUID := SpawnerUID;
2077 FTargetTime := 0;
2078 end;
2080 // Çäîðîâüå çàêîí÷èëîñü:
2081 if FHealth <= 0 then
2082 begin
2083 // Åñëè ýòî íå áî÷êà è óáèë èãðîê, òî åìó +1:
2084 if (FMonsterType <> MONSTER_BARREL) then
2085 begin
2086 if (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2087 begin
2088 p := g_Player_Get(SpawnerUID);
2089 if (p <> nil) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2090 begin
2091 p.MonsterKills := p.MonsterKills+1;
2092 if gGameSettings.GameMode = GM_COOP then
2093 p.Frags := p.Frags + 1;
2094 // Uncomment this if you want to double-kill monsters
2095 //p.FragCombo();
2096 end;
2097 end;
2098 if gLMSRespawn = LMS_RESPAWN_NONE then
2099 begin
2100 Inc(gCoopMonstersKilled);
2101 if g_Game_IsNet then
2102 MH_SEND_GameStats;
2103 end;
2104 end;
2106 // Âûáèðàåì ëóò:
2107 case FMonsterType of
2108 MONSTER_ZOMBY: c := ITEM_AMMO_BULLETS;
2109 MONSTER_SERG: c := ITEM_WEAPON_SHOTGUN1;
2110 MONSTER_CGUN: c := ITEM_WEAPON_CHAINGUN;
2111 MONSTER_MAN: c := ITEM_KEY_RED;
2112 else c := 0;
2113 end;
2115 // Áðîñàåì ëóò:
2116 if c <> 0 then
2117 begin
2118 it := g_Items_Create(FObj.X + (FObj.Rect.Width div 2),
2119 FObj.Y + (FObj.Rect.Height div 2),
2120 c, True, False);
2121 g_Items_SetDrop(it); // mark it as monster drop
2122 g_Obj_Push(g_Items_ObjByIdx(it), (FObj.Vel.X div 2)-3+Random(7),
2123 (FObj.Vel.Y div 2)-Random(4));
2124 //positionChanged(); // this updates spatial accelerators
2125 if g_Game_IsServer and g_Game_IsNet then
2126 MH_SEND_ItemSpawn(True, it);
2127 end;
2129 // Òðóï äàëüøå íå èäåò:
2130 FObj.Vel.X := 0;
2132 // Ó òðóïà ðàçìåðû ìåíüøå:
2133 if (FMonsterType <> MONSTER_FISH) and (FMonsterType <> MONSTER_PAIN) then
2134 begin
2135 FObj.Rect.Y := FObj.Rect.Y + FObj.Rect.Height-12;
2136 FObj.Rect.Height := 12;
2137 positionChanged();
2138 end;
2140 // Óðîí áûë ñèëüíûì => ñëàáûå - â êàøó:
2141 if (FHealth <= -30) and
2142 ((FMonsterType = MONSTER_IMP) or (FMonsterType = MONSTER_ZOMBY) or
2143 (FMonsterType = MONSTER_SERG) or (FMonsterType = MONSTER_CGUN) or
2144 (FMonsterType = MONSTER_MAN)) then
2145 begin
2146 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
2147 SetState(MONSTATE_DIE, ANIM_MESS);
2149 else
2150 begin
2151 DieSound();
2152 SetState(MONSTATE_DIE);
2153 end;
2155 // Àêòèâèðîâàòü òðèããåðû, æäóùèå ñìåðòè ýòîãî ìîíñòðà:
2156 if g_Game_IsServer then ActivateTriggers();
2158 FHealth := 0;
2160 else
2161 if FState = MONSTATE_SLEEP then
2162 begin // Ñïàë, ðàçáóäèëè íåñìåðòåëüíûì óäàðîì:
2163 FPain := MONSTERTABLE[FMonsterType].Pain;
2164 SetState(MONSTATE_GO);
2165 end;
2167 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
2168 Result := True;
2169 end;
2171 function TMonster.Heal(Value: Word): Boolean;
2172 begin
2173 Result := False;
2174 if g_Game_IsClient then
2175 Exit;
2176 if not alive then
2177 Exit;
2179 if FHealth < FMaxHealth then
2180 begin
2181 IncMax(FHealth, Value, FMaxHealth);
2182 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
2183 Result := True;
2184 end;
2185 end;
2187 destructor TMonster.Destroy();
2189 a: Integer;
2190 begin
2191 for a := 0 to High(FAnim) do
2192 begin
2193 FAnim[a, TDirection.D_LEFT].Free();
2194 FAnim[a, TDirection.D_RIGHT].Free();
2195 end;
2197 vilefire.Free();
2199 if (mProxyId <> -1) then
2200 begin
2201 if (monsGrid <> nil) then
2202 begin
2203 monsGrid.removeBody(mProxyId);
2204 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
2205 e_WriteLog(Format('monster #%d:(%u): removed from grid; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
2206 {$ENDIF}
2207 end;
2208 mProxyId := -1;
2209 end;
2211 if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then
2212 begin
2213 freeInds.release(mArrIdx);
2214 gMonsters[mArrIdx] := nil;
2215 end;
2216 mArrIdx := -1;
2218 uidMap[FUID] := nil;
2220 inherited Destroy();
2221 end;
2223 procedure TMonster.Draw();
2225 m: TMirrorType;
2226 dx, dy, c, fX, fY: Integer;
2227 o: TObj;
2228 begin
2229 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, 'TYPE: '+IntToStr(FMonsterType));
2230 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y+16, 'STATE: '+IntToStr(FState));
2232 FObj.lerp(gLerpFactor, fX, fY);
2234 // Åñëè êîëäóí ñòðåëÿåò, òî ðèñóåì îãîíü:
2235 if FMonsterType = MONSTER_VILE then
2236 if FState = MONSTATE_SHOOT then
2237 if GetPos(FTargetUID, @o) then
2238 vilefire.Draw(o.X+o.Rect.X+(o.Rect.Width div 2)-32,
2239 o.Y+o.Rect.Y+o.Rect.Height-128, TMirrorType.None);
2241 // Íå â îáëàñòè ðèñîâàíèÿ íå ðåñóåì:
2242 //FIXME!
2243 if (g_dbg_scale = 1.0) then
2244 begin
2245 if not g_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height,
2246 sX-128, sY-128, sWidth+256, sHeight+256) then
2247 Exit;
2248 end;
2250 // Ýòè ìîíñòðû, óìèðàÿ, íå îñòàâëÿþò òðóïîâ:
2251 if FState = MONSTATE_DEAD then
2252 case FMonsterType of
2253 MONSTER_BARREL, MONSTER_SOUL, MONSTER_PAIN: Exit;
2254 end;
2256 // Åñòü ÷òî ðèñîâàòü ïðè òåêóùåì ïîâåäåíèè:
2257 if FAnim[FCurAnim, FDirection] <> nil then
2258 begin
2259 // Åñëè íåò ëåâîé àíèìàöèè èëè îíà ñîâïàäàåò ñ ïðàâîé => îòðàæàåì ïðàâóþ:
2260 if (FDirection = TDirection.D_LEFT) and
2261 ((not MONSTER_ANIMTABLE[FMonsterType].LeftAnim) or
2262 (FAnim[FCurAnim, TDirection.D_LEFT].FramesID = FAnim[FCurAnim, TDirection.D_RIGHT].FramesID)) and
2263 (FMonsterType <> MONSTER_BARREL) then
2264 m := TMirrorType.Horizontal
2265 else
2266 m := TMirrorType.None;
2268 // Ëåâàÿ àíèìàöèÿ => ìåíÿåì ñìåùåíèå îòíîñèòåëüíî öåíòðà:
2269 if (FDirection = TDirection.D_LEFT) and
2270 (FMonsterType <> MONSTER_BARREL) then
2271 begin
2272 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].X;
2273 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].Y;
2275 if m = TMirrorType.Horizontal then
2276 begin // Íåò îòäåëüíîé ëåâîé àíèìàöèè
2277 // Ðàññòîÿíèå îò êðàÿ òåêñòóðû äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2278 c := (MONSTERTABLE[FMonsterType].Rect.X - dx) + MONSTERTABLE[FMonsterType].Rect.Width;
2279 // Ðàññòîÿíèå îò êðàÿ õèò áîêñà äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2280 dx := FAnim[FCurAnim, FDirection].Width - c - MONSTERTABLE[FMonsterType].Rect.X;
2281 // Ò.ê. äâèãàòü òåêñòóðó íóæíî áóäåò â ïðîòèâîïîëîæíîì íàïðàâëåíèè:
2282 dx := -dx;
2283 // Ýòî çíà÷èò: dX := -frameWidth - animDeltaX + hitX + hitWidth + hitX
2284 end;
2286 else // Ïðàâàÿ àíèìàöèÿ
2287 begin
2288 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].X;
2289 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].Y;
2290 end;
2292 // Ðèñóåì:
2293 FAnim[FCurAnim, FDirection].Draw(fX+dx, fY+dy, m);
2294 end;
2296 if g_debug_Frames then
2297 begin
2298 e_DrawQuad(FObj.X+FObj.Rect.X,
2299 FObj.Y+FObj.Rect.Y,
2300 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2301 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2302 0, 255, 0);
2303 end;
2304 end;
2306 procedure TMonster.MakeBloodSimple(Count: Word);
2307 begin
2308 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)+8,
2309 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2310 Count div 2, 3, -1, 16, (FObj.Rect.Height*2 div 3),
2311 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2312 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-8,
2313 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2314 Count div 2, -3, -1, 16, (FObj.Rect.Height*2) div 3,
2315 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2316 end;
2318 procedure TMonster.MakeBloodVector(Count: Word; VelX, VelY: Integer);
2319 begin
2320 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2321 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2322 Count, VelX, VelY, 16, (FObj.Rect.Height*2) div 3,
2323 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2324 end;
2326 procedure TMonster.Push(vx, vy: Integer);
2327 begin
2328 FObj.Accel.X := FObj.Accel.X + vx;
2329 FObj.Accel.Y := FObj.Accel.Y + vy;
2330 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2331 end;
2333 procedure TMonster.SetState(State: Byte; ForceAnim: Byte = 255);
2335 Anim: Byte;
2336 begin
2337 // Åñëè ñîñòîÿíèå = íà÷àëè óìèðàòü, à ýòîò ìîíñòð = Lost_Soul,
2338 // òî ñîáëþäàåì îãðàíè÷åíèå êîëè÷åñòâà Lost_Soul'îâ:
2339 if (State = MONSTATE_DIE) and (MonsterType = MONSTER_SOUL) then
2340 soulcount := soulcount-1;
2342 // Ïðèñìåðòè - íåëüçÿ ñðàçó íà÷èíàòü àòàêîâàòü èëè áåãàòü:
2343 case FState of
2344 MONSTATE_DIE, MONSTATE_DEAD, MONSTATE_REVIVE:
2345 if (State <> MONSTATE_DEAD) and (State <> MONSTATE_REVIVE) and
2346 (State <> MONSTATE_GO) then
2347 Exit;
2348 end;
2350 // Ñìåíà ñîñòîÿíèÿ:
2351 FState := State;
2353 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID, ForceAnim);
2355 // Íîâàÿ àíèìàöèÿ ïðè íîâîì ñîñòîÿíèè:
2356 case FState of
2357 MONSTATE_SLEEP: Anim := ANIM_SLEEP;
2358 MONSTATE_PAIN: Anim := ANIM_PAIN;
2359 MONSTATE_WAIT: Anim := ANIM_SLEEP;
2360 MONSTATE_CLIMB, MONSTATE_RUN, MONSTATE_RUNOUT, MONSTATE_GO: Anim := ANIM_GO;
2361 MONSTATE_SHOOT: Anim := ANIM_ATTACK;
2362 MONSTATE_ATTACK: Anim := ANIM_ATTACK;
2363 MONSTATE_DIE: Anim := ANIM_DIE;
2364 MONSTATE_REVIVE:
2365 begin // íà÷àëè âîñðåøàòüñÿ
2366 Anim := FCurAnim;
2367 FAnim[Anim, FDirection].Revert(True);
2369 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
2370 FHealth := MONSTERTABLE[FMonsterType].Health;
2371 FAmmo := 0;
2372 FPain := 0;
2373 end;
2374 else Exit;
2375 end;
2377 // Íàäî ñìåíèòü àíèìàöèþ íà íåñòàíäàðòíóþ:
2378 if ForceAnim <> 255 then
2379 Anim := ForceAnim;
2381 // Åñëè àíèìàöèÿ íîâàÿ - ïåðåçàïóñêàåì å¸:
2382 if FCurAnim <> Anim then
2383 if FAnim[Anim, FDirection] <> nil then
2384 begin
2385 FAnim[Anim, FDirection].Reset();
2386 FCurAnim := Anim;
2387 end;
2388 end;
2390 function TMonster.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
2392 TA: TAnimation;
2393 FramesID: DWORD;
2394 begin
2395 Result := False;
2397 //  òî÷êå íàçíà÷åíèÿ ñòåíà:
2398 if g_CollideLevel(X, Y, FObj.Rect.Width, FObj.Rect.Height) then
2399 begin
2400 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
2401 if g_Game_IsServer and g_Game_IsNet then
2402 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
2403 Exit;
2404 end;
2406 TA := nil;
2408 // Ýôôåêò òåëåïîðòà â ïîçèöèè ìîíñòðà:
2409 if not silent then
2410 begin
2411 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
2412 TA := TAnimation.Create(FramesID, False, 6);
2413 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', Obj.X, Obj.Y);
2414 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2415 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2417 if g_Game_IsServer and g_Game_IsNet then
2418 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2419 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 1,
2420 NET_GFX_TELE);
2421 end;
2423 FObj.X := X - FObj.Rect.X;
2424 FObj.Y := Y - FObj.Rect.Y;
2425 FObj.oldX := FObj.X; // don't interpolate after teleport
2426 FObj.oldY := FObj.Y;
2427 positionChanged();
2429 if dir = 1 then
2430 FDirection := TDirection.D_LEFT
2431 else
2432 if dir = 2 then
2433 FDirection := TDirection.D_RIGHT
2434 else
2435 if dir = 3 then
2436 begin // îáðàòíîå
2437 if FDirection = TDirection.D_RIGHT then
2438 FDirection := TDirection.D_LEFT
2439 else
2440 FDirection := TDirection.D_RIGHT;
2441 end;
2443 // Ýôôåêò òåëåïîðòà â òî÷êå íàçíà÷åíèÿ:
2444 if not silent and (TA <> nil) then
2445 begin
2446 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2447 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2448 TA.Free();
2450 if g_Game_IsServer and g_Game_IsNet then
2451 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2452 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 0,
2453 NET_GFX_TELE);
2454 end;
2456 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2457 Result := True;
2458 end;
2460 procedure TMonster.PreUpdate();
2461 begin
2462 FObj.oldX := FObj.X;
2463 FObj.oldY := FObj.Y;
2464 end;
2466 procedure TMonster.Update();
2468 a, b, sx, sy, wx, wy, oldvelx: Integer;
2469 st: Word;
2470 o, co: TObj;
2471 fall: Boolean;
2472 mon: TMonster;
2473 mit: PMonster;
2474 it: TMonsterGrid.Iter;
2475 label
2476 _end;
2477 begin
2478 fall := True;
2480 // Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
2481 if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
2483 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
2484 if FMonsterType = MONSTER_FISH then
2485 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
2486 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2487 fall := False;
2489 // Ëåòàþùèå ìîíòñðû:
2490 if ((FMonsterType = MONSTER_SOUL) or
2491 (FMonsterType = MONSTER_PAIN) or
2492 (FMonsterType = MONSTER_CACO)) and
2493 (FState <> MONSTATE_DIE) and
2494 (FState <> MONSTATE_DEAD) then
2495 fall := False;
2497 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
2498 if gTime mod (GAME_TICK*2) <> 0 then
2499 begin
2500 g_Obj_Move(@FObj, fall, True, True);
2501 positionChanged(); // this updates spatial accelerators
2502 Exit;
2503 end;
2505 if FPainTicks > 0 then
2506 Dec(FPainTicks)
2507 else
2508 FPainSound := False;
2510 // Äâèãàåìñÿ:
2511 st := g_Obj_Move(@FObj, fall, True, True);
2512 positionChanged(); // this updates spatial accelerators
2514 // Åñëè ãîðèì - ïîäæèãàåì äðóãèõ ìîíñòðîâ, íî íå íà 100 òèêîâ êàæäûé ðàç:
2515 if FFireTime > 0 then
2516 begin
2517 it := monsGrid.forEachInAABB(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
2518 for mit in it do
2519 if mit.UID <> FUID then
2520 mit.CatchFire(FFireAttacker, FFireTime);
2521 end;
2523 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
2524 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
2525 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
2526 begin
2527 FRemoved := True;
2528 if alive and (gLMSRespawn = LMS_RESPAWN_NONE) then
2529 begin
2530 Inc(gCoopMonstersKilled);
2531 if g_Game_IsNet then
2532 MH_SEND_GameStats;
2533 end;
2534 ActivateTriggers();
2535 Exit;
2536 end;
2538 oldvelx := FObj.Vel.X;
2540 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
2541 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
2542 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
2544 if FFireTime > 0 then
2545 begin
2546 if WordBool(st and MOVE_INWATER) then
2547 FFireTime := 0
2548 else
2549 begin
2550 OnFireFlame(1);
2551 FFireTime := FFireTime - 1;
2552 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2553 if FFirePainTime = 0 then
2554 begin
2555 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
2556 FFirePainTime := 18;
2558 else
2559 FFirePainTime := FFirePainTime - 1;
2560 end;
2561 end;
2563 // Ìåðòâûé íè÷åãî íå äåëàåò:
2564 if (FState = MONSTATE_DEAD) then
2565 goto _end;
2567 // AI ìîíñòðîâ âûêëþ÷åí:
2568 if g_debug_MonsterOff then
2569 begin
2570 FSleep := 1;
2571 if FState <> MONSTATE_SLEEP then
2572 SetState(MONSTATE_SLEEP);
2573 end;
2575 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
2576 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
2577 case FMonsterType of
2578 MONSTER_FISH:
2579 if Random(4) = 0 then
2580 g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2581 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2582 MONSTER_ROBO, MONSTER_BARREL:
2583 g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2584 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2585 else
2586 g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
2587 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
2588 end;
2590 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
2591 if FMonsterType = MONSTER_BARREL then
2592 begin
2593 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
2594 (FAnim[FCurAnim, FDirection].Counter = 0) then
2595 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2596 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
2597 60, FUID);
2598 end;
2600 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
2601 if FMonsterType = MONSTER_SOUL then
2602 if WordBool(st and MOVE_HITAIR) then
2603 g_Obj_SetSpeed(@FObj, 16);
2605 if FAmmo < 0 then
2606 FAmmo := FAmmo + 1;
2608 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
2609 if FObj.Vel.Y < 0 then
2610 if WordBool(st and MOVE_INWATER) then
2611 FObj.Vel.Y := -4;
2613 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
2614 FTargetTime := FTargetTime + 1;
2616 // Ãèëüçû
2617 if FShellTimer > -1 then
2618 if FShellTimer = 0 then
2619 begin
2620 if FShellType = SHELL_SHELL then
2621 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2622 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2623 GameVelX, GameVelY-2, SHELL_SHELL)
2624 else if FShellType = SHELL_DBLSHELL then
2625 begin
2626 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2627 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2628 GameVelX-1, GameVelY-2, SHELL_SHELL);
2629 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2630 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2631 GameVelX+1, GameVelY-2, SHELL_SHELL);
2632 end;
2633 FShellTimer := -1;
2634 end else Dec(FShellTimer);
2636 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
2637 if fall then
2638 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
2639 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
2640 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2641 FObj.Rect.Width, FObj.Rect.Height, 50) then
2642 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2643 (FObj.Accel.Y = 0) then
2644 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2646 case FState of
2647 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
2648 begin
2649 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
2650 if FPain >= MONSTERTABLE[FMonsterType].Pain then
2651 begin
2652 FPain := MONSTERTABLE[FMonsterType].Pain;
2653 if gSoundEffectsDF then PainSound();
2654 end;
2655 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
2656 PainSound();
2658 // Ñíèæàåì áîëü ñî âðåìåíåì:
2659 FPain := FPain - 5;
2661 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
2662 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
2663 begin
2664 FPain := 0;
2665 FAmmo := -9;
2666 SetState(MONSTATE_GO);
2667 end;
2668 end;
2670 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
2671 begin
2672 // Ñïèì:
2673 FSleep := FSleep + 1;
2675 // Ïðîñïàëè äîñòàòî÷íî:
2676 if FSleep >= 18 then
2677 FSleep := 0
2678 else // åùå ñïèì
2679 goto _end;
2681 // Íà èãðîêîâ èäóò òîëüêî îáû÷íûå ìîíñòðû, êèëëåðû è ìàíüÿêè
2682 if (FBehaviour = BH_NORMAL) or (FBehaviour = BH_KILLER) or (FBehaviour = BH_MANIAC) then
2683 // Åñëè åñòü èãðîê ðÿäîì, ïðîñûïàåìñÿ è èäåì ê íåìó:
2684 if (gPlayers <> nil) then
2685 for a := 0 to High(gPlayers) do
2686 if (gPlayers[a] <> nil) and (gPlayers[a].alive)
2687 and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
2688 with gPlayers[a] do
2689 if g_Look(@FObj, @Obj, FDirection) then
2690 begin
2691 FTargetUID := gPlayers[a].UID;
2692 FTargetTime := 0;
2693 WakeUpSound();
2694 SetState(MONSTATE_GO);
2695 Break;
2696 end;
2698 // Íà ìîíñòðîâ òÿíåò ìàíüÿêîâ, ïîåõàâøèõ è êàííèáàëîâ
2699 if (FTargetUID = 0) and ((FBehaviour = BH_MANIAC)
2700 or (FBehaviour = BH_INSANE) or (FBehaviour = BH_CANNIBAL)) then
2701 // Åñëè åñòü ïîäõîäÿùèé ìîíñòð ðÿäîì:
2702 if gMonsters <> nil then
2703 for a := 0 to High(gMonsters) do
2704 if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
2705 (gMonsters[a].FUID <> FUID) then
2706 begin
2707 // Ìàíüÿêè íàïàäàþò íà âñåõ ìîíñòðîâ, êðîìå äðóçåé
2708 if (FBehaviour = BH_MANIAC) and
2709 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2710 Continue;
2711 // Ïîåõàâøèå òàêæå, íî ìîãóò îáîçëèòüñÿ íà áî÷êó
2712 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL) and
2713 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2714 Continue;
2715 // Êàííèáàëû íàïàäàþò íà ñåáå ïîäîáíûõ
2716 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
2717 Continue;
2718 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
2719 begin
2720 FTargetUID := gMonsters[a].UID;
2721 FTargetTime := 0;
2722 WakeUpSound();
2723 SetState(MONSTATE_GO);
2724 Break;
2725 end;
2726 end;
2727 end;
2729 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
2730 begin
2731 // Æäåì:
2732 FSleep := FSleep - 1;
2734 // Âûæäàëè äîñòàòî÷íî - èäåì:
2735 if FSleep < 0 then
2736 SetState(MONSTATE_GO);
2737 end;
2739 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
2740 begin
2741 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2742 if WordBool(st and MOVE_BLOCK) then
2743 begin
2744 Turn();
2745 FSleep := 40;
2746 SetState(MONSTATE_RUNOUT);
2748 goto _end;
2749 end;
2751 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
2752 if (FMonsterType = MONSTER_VILE) then
2753 if isCorpse(@FObj, False) <> -1 then
2754 begin
2755 FObj.Vel.X := 0;
2756 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
2758 goto _end;
2759 end;
2761 // Öåëü ïîãèáëà èëè äàâíî æäåì:
2762 if (not GetPos(FTargetUID, @o)) or (FTargetTime > MAX_ATM) then
2763 if not findNewPrey() then
2764 begin // Íîâûõ öåëåé íåò
2765 FTargetUID := 0;
2766 o.X := FObj.X+pt_x;
2767 o.Y := FObj.Y+pt_y;
2768 o.Vel.X := 0;
2769 o.Vel.Y := 0;
2770 o.Accel.X := 0;
2771 o.Accel.Y := 0;
2772 o.Rect := _Rect(0, 0, 0, 1);
2774 else // Íîâàÿ öåëü åñòü - áåðåì åå êîîðäèíàòû
2775 GetPos(FTargetUID, @o);
2777 // Öåëü î÷åíü áëèçêî - ïèíàåì:
2778 if g_Obj_Collide(@FObj, @o) and (FTargetUID <> 0) then
2779 begin
2780 FTargetTime := 0;
2781 if (FMonsterType <> MONSTER_CYBER) or (Random(2) = 0) then
2782 begin
2783 if kick(@o) then
2784 goto _end;
2785 end;
2786 end;
2788 // Ðàññòîÿíèå äî öåëè:
2789 sx := o.X+o.Rect.X+(o.Rect.Width div 2)-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
2790 sy := o.Y+o.Rect.Y+(o.Rect.Height div 2)-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
2792 // Ïîâîðà÷èâàåìñÿ â ñòîðîíó öåëè:
2793 if sx > 0 then
2794 FDirection := TDirection.D_RIGHT
2795 else
2796 FDirection := TDirection.D_LEFT;
2798 // Åñëè ìîíñòð óìååò ñòðåëÿòü è åñòü ïî êîìó - ñòðåëÿåì:
2799 if canShoot(FMonsterType) and (FTargetUID <> 0) then
2800 if Abs(sx) > Abs(sy) then // óãîë âûñòðåëà óäîáíûé
2801 if shoot(@o, False) then
2802 goto _end;
2804 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
2805 if Abs(sx) < 40 then
2806 if FMonsterType <> MONSTER_FISH then
2807 begin
2808 FSleep := 15;
2809 SetState(MONSTATE_RUN);
2810 if Random(2) = 0 then
2811 FDirection := TDirection.D_LEFT
2812 else
2813 FDirection := TDirection.D_RIGHT;
2815 goto _end;
2816 end;
2818 // Óïåðëèñü â ñòåíó:
2819 if WordBool(st and MOVE_HITWALL) then
2820 begin
2821 if g_Triggers_PressR(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width,
2822 FObj.Rect.Height, FUID, ACTIVATE_MONSTERPRESS) <> nil then
2823 begin // Ñìîãëè íàæàòü êíîïêó - íåáîëüøîå îæèäàíèå
2824 FSleep := 4;
2825 SetState(MONSTATE_WAIT);
2827 goto _end;
2828 end;
2830 case FMonsterType of
2831 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
2832 else // Íå ëåòàþò:
2833 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2834 (FObj.Accel.Y = 0) then
2835 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
2836 // Ïðûæîê ÷åðåç ñòåíó:
2837 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2838 SetState(MONSTATE_CLIMB);
2839 end;
2840 end;
2842 goto _end;
2843 end;
2845 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
2846 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
2847 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
2848 begin
2849 if FMonsterType = MONSTER_FISH then
2850 begin // Ðûáà
2851 if not WordBool(st and MOVE_INWATER) then
2852 begin // Ðûáà âíå âîäû:
2853 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2854 begin // "Ñòîèò" òâåðäî
2855 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
2856 if FObj.Accel.Y = 0 then FObj.Vel.Y := -6;
2857 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
2858 end;
2860 // Ðûáå áîëüíî:
2861 SetState(MONSTATE_PAIN);
2862 FPain := FPain + 50;
2864 else // Ðûáà â âîäå
2865 begin
2866 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2867 if Abs(sy) > 8 then
2868 FObj.Vel.Y := g_basic.Sign(sy)*4
2869 else
2870 FObj.Vel.Y := 0;
2872 // Ðûáà ïëûâåò ââåðõ:
2873 if FObj.Vel.Y < 0 then
2874 if not g_Obj_CollideLiquid(@FObj, 0, -16) then
2875 begin
2876 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
2877 FObj.Vel.Y := 0;
2878 // Ïëàâàåì òóäà-ñþäà:
2879 if Random(2) = 0 then
2880 FDirection := TDirection.D_LEFT
2881 else
2882 FDirection := TDirection.D_RIGHT;
2883 FSleep := 20;
2884 SetState(MONSTATE_RUN);
2885 end;
2886 end;
2888 else // Ëåòàþùèå ìîíñòðû
2889 begin
2890 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2891 if Abs(sy) > 8 then
2892 FObj.Vel.Y := g_basic.Sign(sy)*4
2893 else
2894 FObj.Vel.Y := 0;
2895 end;
2897 else // "Íàçåìíûå" ìîíñòðû
2898 begin
2899 // Âîçìîæíî, ïèíàåì êóñêè:
2900 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
2901 begin
2902 b := Abs(FObj.Vel.X);
2903 if b > 1 then b := b * (Random(8 div b) + 1);
2904 for a := 0 to High(gGibs) do
2905 begin
2906 if gGibs[a].alive and
2907 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2908 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
2909 begin
2910 // Ïèíàåì êóñêè
2911 if FObj.Vel.X < 0 then
2912 begin
2913 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
2915 else
2916 begin
2917 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
2918 end;
2919 end;
2920 end;
2921 end;
2922 // Áîññû ìîãóò ïèíàòü òðóïû:
2923 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
2924 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
2925 begin
2926 b := Abs(FObj.Vel.X);
2927 if b > 1 then b := b * (Random(8 div b) + 1);
2928 for a := 0 to High(gCorpses) do
2929 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
2930 begin
2931 co := gCorpses[a].Obj;
2932 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2933 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
2934 // Ïèíàåì òðóïû
2935 if FObj.Vel.X < 0 then
2936 gCorpses[a].Damage(b*2, FUID, -b, Random(7)) // íàëåâî
2937 else
2938 gCorpses[a].Damage(b*2, FUID, b, Random(7)); // íàïðàâî
2939 end;
2940 end;
2941 // Åñëè öåëü âûñîêî, òî, âîçìîæíî, ïðûãàåì:
2942 if sy < -40 then
2943 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2944 // ñòîèò òâåðäî
2945 if (Random(4) = 0) and (FObj.Accel.Y = 0) then
2946 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2947 end;
2949 FSleep := FSleep + 1;
2951 // Èíîãäà ðû÷èì:
2952 if FSleep >= 8 then
2953 begin
2954 FSleep := 0;
2955 if Random(8) = 0 then
2956 ActionSound();
2957 end;
2959 // Áåæèì â âûáðàííóþ ñòîðîíó:
2960 if FDirection = TDirection.D_RIGHT then
2961 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2962 else
2963 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2965 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2966 if WordBool(st and MOVE_INWATER) then
2967 FObj.Vel.X := FObj.Vel.X div 2
2968 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2969 if FMonsterType = MONSTER_FISH then
2970 FObj.Vel.X := 0;
2971 end;
2973 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
2974 begin
2975 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2976 if WordBool(st and MOVE_BLOCK) then
2977 begin
2978 Turn();
2979 FSleep := 40;
2980 SetState(MONSTATE_RUNOUT);
2982 goto _end;
2983 end;
2985 FSleep := FSleep - 1;
2987 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
2988 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
2989 begin
2990 FSleep := 0;
2991 SetState(MONSTATE_GO);
2992 // Ñòåíà - èäåì îáðàòíî:
2993 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
2994 Turn();
2995 // Èíîãäà ðû÷èì:
2996 if Random(8) = 0 then
2997 ActionSound();
2998 end;
3000 // Áåæèì â âûáðàííóþ ñòîðîíó:
3001 if FDirection = TDirection.D_RIGHT then
3002 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3003 else
3004 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3006 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3007 if WordBool(st and MOVE_INWATER) then
3008 FObj.Vel.X := FObj.Vel.X div 2
3009 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3010 if FMonsterType = MONSTER_FISH then
3011 FObj.Vel.X := 0;
3012 end;
3014 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
3015 begin
3016 // Âûøëè èç ÁëîêÌîíà:
3017 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
3018 FSleep := 0;
3020 FSleep := FSleep - 1;
3022 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
3023 if FSleep <= -18 then
3024 begin
3025 FSleep := 0;
3026 SetState(MONSTATE_GO);
3027 // Ñòåíà/ÁëîêÌîí - èäåì îáðàòíî:
3028 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3029 Turn();
3030 // Èíîãäà ðû÷èì:
3031 if Random(8) = 0 then
3032 ActionSound();
3033 end;
3035 // Áåæèì â âûáðàííóþ ñòîðîíó:
3036 if FDirection = TDirection.D_RIGHT then
3037 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3038 else
3039 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3041 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3042 if WordBool(st and MOVE_INWATER) then
3043 FObj.Vel.X := FObj.Vel.X div 2
3044 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3045 if FMonsterType = MONSTER_FISH then
3046 FObj.Vel.X := 0;
3047 end;
3049 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
3050 begin
3051 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
3052 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
3053 (not WordBool(st and MOVE_HITWALL)) then
3054 begin
3055 FSleep := 0;
3056 SetState(MONSTATE_GO);
3058 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
3059 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3060 begin
3061 Turn();
3062 FSleep := 15;
3063 SetState(MONSTATE_RUN);
3064 end;
3065 end;
3067 // Áåæèì â âûáðàííóþ ñòîðîíó:
3068 if FDirection = TDirection.D_RIGHT then
3069 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3070 else
3071 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3073 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3074 if WordBool(st and MOVE_INWATER) then
3075 FObj.Vel.X := FObj.Vel.X div 2
3076 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3077 if FMonsterType = MONSTER_FISH then
3078 FObj.Vel.X := 0;
3079 end;
3081 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
3082 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
3083 begin
3084 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
3085 if FMonsterType = MONSTER_SOUL then
3086 begin
3087 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
3088 SetState(MONSTATE_GO);
3090 goto _end;
3091 end;
3093 // Çàìåäëÿåìñÿ ïðè àòàêå:
3094 if FMonsterType <> MONSTER_FISH then
3095 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3097 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
3098 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
3099 begin
3100 // Öåëü ïîãèáëà => èäåì äàëüøå:
3101 if not GetPos(FTargetUID, @o) then
3102 begin
3103 SetState(MONSTATE_GO);
3105 goto _end;
3106 end;
3108 // Öåëü íå âèäíî => èäåì äàëüøå:
3109 if not g_Look(@FObj, @o, FDirection) then
3110 begin
3111 SetState(MONSTATE_GO);
3113 goto _end;
3114 end;
3116 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
3117 if g_Obj_CollideWater(@o, 0, 0) then
3118 begin
3119 SetState(MONSTATE_GO);
3121 goto _end;
3122 end;
3124 // Æàðèì öåëü:
3125 tx := o.X+o.Rect.X+(o.Rect.Width div 2);
3126 ty := o.Y+o.Rect.Y+(o.Rect.Height div 2);
3127 g_Weapon_HitUID(FTargetUID, 2, FUID, HIT_SOME);