DEADSOFTWARE

Game: Use proper syntax of sets for game options instead of raw bitwise operations
[d2df-sdl.git] / src / game / g_monsters.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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.
6 *
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.
11 *
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/>.
14 *)
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;
51 }
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;
287 var
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;
298 var
299 profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
302 type
303 TMonsterGrid = specialize TBodyGridBase<TMonster>;
305 var
306 monsGrid: TMonsterGrid = nil; // DO NOT USE! public for debugging only!
309 var
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 // ////////////////////////////////////////////////////////////////////////// //
353 var
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 ();
383 var
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}
398 end
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);
411 end
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);
419 end
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 // ////////////////////////////////////////////////////////////////////////// //
622 var
623 gMonsters: array of TMonster;
624 uidMap: array [0..65535] of TMonster; // monster knows it's index
625 freeInds: TIdPool = nil;
628 procedure clearUidMap ();
629 var
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;
638 var
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;
656 var
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;
673 var
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;
682 var
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 // Pain_Elemental è Lost_Soul íå âîþþò äðóã ñ äðóãîì:
712 if [a, b] = [MONSTER_PAIN, MONSTER_SOUL] then
713 Exit;
715 //  îñòàëüíûõ ñëó÷àÿõ - áóäóò áèòü äðóã äðóãà:
716 Result := False;
717 end;
720 function BehaviourDamage(SpawnerUID: Word; BH, SelfType: Byte): Boolean;
721 var
722 m: TMonster;
723 UIDType, MonsterType: Byte;
724 begin
725 Result := False;
726 MonsterType := 0;
728 UIDType := g_GetUIDType(SpawnerUID);
729 if UIDType = UID_MONSTER then
730 begin
731 m := g_Monsters_ByUID(SpawnerUID);
732 if m = nil then Exit;
733 MonsterType := m.FMonsterType;
734 end;
736 case BH of
737 BH_NORMAL: Result := (UIDType = UID_PLAYER) or
738 ((UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType)));
740 BH_KILLER: Result := UIDType = UID_PLAYER;
741 BH_MANIAC: Result := (UIDType = UID_PLAYER) or
742 ((UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType)));
744 BH_INSANE: Result := (UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType));
745 BH_CANNIBAL: Result := (UIDType = UID_MONSTER) and (MonsterType = SelfType);
746 end;
747 end;
750 function canShoot(m: Byte): Boolean;
751 begin
752 Result := False;
754 case m of
755 MONSTER_DEMON, MONSTER_FISH, MONSTER_BARREL:
756 Exit;
757 else
758 Result := True;
759 end;
760 end;
763 function isCorpse (o: PObj; immediately: Boolean): Integer;
765 (*
766 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
767 begin
768 atag := atag; // shut up, fpc!
769 result := false; // don't stop
770 if (mon.FState = MONSTATE_DEAD) and g_Obj_Collide(o, @mon.FObj) then
771 begin
772 case mon.FMonsterType of // Íå âîñêðåñèòü:
773 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
774 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: exit;
775 end;
776 // Îñòàëüíûõ ìîæíî âîñêðåñèòü
777 result := true;
778 end;
779 end;
780 *)
782 var
783 a: Integer;
784 mon: PMonster;
785 mres: TMonster = nil;
786 it: TMonsterGrid.Iter;
787 begin
788 result := -1;
790 // Åñëè íóæíà âåðîÿòíîñòü
791 if not immediately and (Random(8) <> 0) then exit;
793 // Èùåì ìåðòâûõ ìîíñòðîâ ïîáëèçîñòè
794 if gmon_debug_use_sqaccel then
795 begin
796 //mon := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height, monsCollCheck);
797 //if (mon <> nil) then result := mon.mArrIdx;
798 it := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height);
799 for mon in it do
800 begin
801 case mon.FMonsterType of // Íå âîñêðåñèòü:
802 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
803 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: begin end;
804 // Îñòàëüíûõ ìîæíî âîñêðåñèòü
805 else mres := mon^;
806 end;
807 if (mres <> nil) then break;
808 end;
809 it.release();
810 if (mres <> nil) then result := mres.mArrIdx;
811 end
812 else
813 begin
814 for a := 0 to High(gMonsters) do
815 begin
816 if (gMonsters[a] <> nil) and (gMonsters[a].FState = MONSTATE_DEAD) and g_Obj_Collide(o, @gMonsters[a].FObj) then
817 begin
818 case gMonsters[a].FMonsterType of // Íå âîñêðåñèòü:
819 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
820 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: Continue;
821 else // Îñòàëüíûõ ìîæíî âîñêðåñèòü
822 begin
823 Result := a;
824 Exit;
825 end;
826 end;
827 end;
828 end;
829 end;
830 end;
832 procedure g_Monsters_LoadData();
833 begin
834 e_WriteLog('Loading monsters data...', TMsgType.Notify);
836 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES], 133, False);
837 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_SLEEP', GameWAD+':MTEXTURES\BARREL_SLEEP', 64, 64, 3);
838 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_DIE', GameWAD+':MTEXTURES\BARREL_DIE', 64, 64, 4);
839 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_PAIN', GameWAD+':MTEXTURES\BARREL_PAIN', 64, 64, 1);
840 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_SLEEP', GameWAD+':MTEXTURES\ZOMBY_SLEEP', 64, 64, 2);
841 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_GO', GameWAD+':MTEXTURES\ZOMBY_GO', 64, 64, 4);
842 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_DIE', GameWAD+':MTEXTURES\ZOMBY_DIE', 64, 64, 6);
843 g_Game_StepLoading(6);
844 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_MESS', GameWAD+':MTEXTURES\ZOMBY_MESS', 64, 64, 9);
845 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK', GameWAD+':MTEXTURES\ZOMBY_ATTACK', 64, 64, 2);
846 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK_L', GameWAD+':MTEXTURES\ZOMBY_ATTACK_L', 64, 64, 2);
847 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_PAIN', GameWAD+':MTEXTURES\ZOMBY_PAIN', 64, 64, 1);
848 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_SLEEP', GameWAD+':MTEXTURES\SERG_SLEEP', 64, 64, 2);
849 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_GO', GameWAD+':MTEXTURES\SERG_GO', 64, 64, 4);
850 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_DIE', GameWAD+':MTEXTURES\SERG_DIE', 64, 64, 5);
851 g_Game_StepLoading(13);
852 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_MESS', GameWAD+':MTEXTURES\SERG_MESS', 64, 64, 9);
853 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK', GameWAD+':MTEXTURES\SERG_ATTACK', 64, 64, 2);
854 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK_L', GameWAD+':MTEXTURES\SERG_ATTACK_L', 64, 64, 2);
855 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_PAIN', GameWAD+':MTEXTURES\SERG_PAIN', 64, 64, 1);
856 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_SLEEP', GameWAD+':MTEXTURES\MAN_SLEEP', 64, 64, 2);
857 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_GO', GameWAD+':MTEXTURES\MAN_GO', 64, 64, 4);
858 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_DIE', GameWAD+':MTEXTURES\MAN_DIE', 64, 64, 7);
859 g_Game_StepLoading(20);
860 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_MESS', GameWAD+':MTEXTURES\MAN_MESS', 64, 64, 9);
861 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_ATTACK', GameWAD+':MTEXTURES\MAN_ATTACK', 64, 64, 2);
862 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_PAIN', GameWAD+':MTEXTURES\MAN_PAIN', 64, 64, 1);
863 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP', GameWAD+':MTEXTURES\CGUN_SLEEP', 64, 64, 2);
864 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP_L', GameWAD+':MTEXTURES\CGUN_SLEEP_L', 64, 64, 2);
865 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO', GameWAD+':MTEXTURES\CGUN_GO', 64, 64, 4);
866 g_Game_StepLoading(26);
867 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO_L', GameWAD+':MTEXTURES\CGUN_GO_L', 64, 64, 4);
868 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_DIE', GameWAD+':MTEXTURES\CGUN_DIE', 64, 64, 7);
869 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_MESS', GameWAD+':MTEXTURES\CGUN_MESS', 64, 64, 6);
870 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK', GameWAD+':MTEXTURES\CGUN_ATTACK', 64, 64, 2);
871 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK_L', GameWAD+':MTEXTURES\CGUN_ATTACK_L', 64, 64, 2);
872 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN', GameWAD+':MTEXTURES\CGUN_PAIN', 64, 64, 1);
873 g_Game_StepLoading(32);
874 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN_L', GameWAD+':MTEXTURES\CGUN_PAIN_L', 64, 64, 1);
875 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_SLEEP', GameWAD+':MTEXTURES\IMP_SLEEP', 64, 64, 2);
876 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_GO', GameWAD+':MTEXTURES\IMP_GO', 64, 64, 4);
877 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_DIE', GameWAD+':MTEXTURES\IMP_DIE', 64, 64, 5);
878 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_MESS', GameWAD+':MTEXTURES\IMP_MESS', 64, 64, 8);
879 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_ATTACK', GameWAD+':MTEXTURES\IMP_ATTACK', 64, 64, 3);
880 g_Game_StepLoading(38);
881 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_PAIN', GameWAD+':MTEXTURES\IMP_PAIN', 64, 64, 1);
882 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_SLEEP', GameWAD+':MTEXTURES\DEMON_SLEEP', 64, 64, 2);
883 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_GO', GameWAD+':MTEXTURES\DEMON_GO', 64, 64, 4);
884 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_DIE', GameWAD+':MTEXTURES\DEMON_DIE', 64, 64, 6);
885 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_ATTACK', GameWAD+':MTEXTURES\DEMON_ATTACK', 64, 64, 3);
886 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_PAIN', GameWAD+':MTEXTURES\DEMON_PAIN', 64, 64, 1);
887 g_Game_StepLoading(44);
888 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_SLEEP', GameWAD+':MTEXTURES\SOUL_SLEEP', 64, 64, 2);
889 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_GO', GameWAD+':MTEXTURES\SOUL_GO', 64, 64, 2);
890 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_PAIN', GameWAD+':MTEXTURES\SOUL_PAIN', 64, 64, 1);
891 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_ATTACK', GameWAD+':MTEXTURES\SOUL_ATTACK', 64, 64, 2);
892 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_DIE', GameWAD+':MTEXTURES\SOUL_DIE', 128, 128, 7);
893 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_SLEEP', GameWAD+':MTEXTURES\FISH_SLEEP', 32, 32, 2);
894 g_Game_StepLoading(50);
895 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_GO', GameWAD+':MTEXTURES\FISH_GO', 32, 32, 4);
896 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_PAIN', GameWAD+':MTEXTURES\FISH_PAIN', 32, 32, 3);
897 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_ATTACK', GameWAD+':MTEXTURES\FISH_ATTACK', 32, 32, 2);
898 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_DIE', GameWAD+':MTEXTURES\FISH_DIE', 32, 32, 1);
899 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_SLEEP', GameWAD+':MTEXTURES\SPIDER_SLEEP', 256, 128, 2);
900 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_GO', GameWAD+':MTEXTURES\SPIDER_GO', 256, 128, 6);
901 g_Game_StepLoading(56);
902 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN', GameWAD+':MTEXTURES\SPIDER_PAIN', 256, 128, 1);
903 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN_L', GameWAD+':MTEXTURES\SPIDER_PAIN_L', 256, 128, 1);
904 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_ATTACK', GameWAD+':MTEXTURES\SPIDER_ATTACK', 256, 128, 2);
905 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_DIE', GameWAD+':MTEXTURES\SPIDER_DIE', 256, 128, 10);
906 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_SLEEP', GameWAD+':MTEXTURES\BSP_SLEEP', 128, 64, 2);
907 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_GO', GameWAD+':MTEXTURES\BSP_GO', 128, 64, 6);
908 g_Game_StepLoading(62);
909 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN', GameWAD+':MTEXTURES\BSP_PAIN', 128, 64, 1);
910 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN_L', GameWAD+':MTEXTURES\BSP_PAIN_L', 128, 64, 1);
911 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_ATTACK', GameWAD+':MTEXTURES\BSP_ATTACK', 128, 64, 2);
912 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_DIE', GameWAD+':MTEXTURES\BSP_DIE', 128, 64, 7);
913 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_SLEEP', GameWAD+':MTEXTURES\CACO_SLEEP', 128, 128, 1);
914 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_GO', GameWAD+':MTEXTURES\CACO_GO', 128, 128, 1);
915 g_Game_StepLoading(68);
916 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_PAIN', GameWAD+':MTEXTURES\CACO_PAIN', 128, 128, 1);
917 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_ATTACK', GameWAD+':MTEXTURES\CACO_ATTACK', 128, 128, 6);
918 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_DIE', GameWAD+':MTEXTURES\CACO_DIE', 128, 128, 7);
919 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_SLEEP', GameWAD+':MTEXTURES\PAIN_SLEEP', 128, 128, 4);
920 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_GO', GameWAD+':MTEXTURES\PAIN_GO', 128, 128, 4);
921 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_PAIN', GameWAD+':MTEXTURES\PAIN_PAIN', 128, 128, 1);
922 g_Game_StepLoading(74);
923 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_ATTACK', GameWAD+':MTEXTURES\PAIN_ATTACK', 128, 128, 4);
924 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_DIE', GameWAD+':MTEXTURES\PAIN_DIE', 128, 128, 7);
925 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP', GameWAD+':MTEXTURES\BARON_SLEEP', 128, 128, 2);
926 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP_L', GameWAD+':MTEXTURES\BARON_SLEEP_L', 128, 128, 2);
927 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_GO', GameWAD+':MTEXTURES\BARON_GO', 128, 128, 4);
928 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN', GameWAD+':MTEXTURES\BARON_PAIN', 128, 128, 1);
929 g_Game_StepLoading(80);
930 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN_L', GameWAD+':MTEXTURES\BARON_PAIN_L', 128, 128, 1);
931 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK', GameWAD+':MTEXTURES\BARON_ATTACK', 128, 128, 3);
932 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK_L', GameWAD+':MTEXTURES\BARON_ATTACK_L', 128, 128, 3);
933 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_DIE', GameWAD+':MTEXTURES\BARON_DIE', 128, 128, 7);
934 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP', GameWAD+':MTEXTURES\KNIGHT_SLEEP', 128, 128, 2);
935 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP_L', GameWAD+':MTEXTURES\KNIGHT_SLEEP_L', 128, 128, 2);
936 g_Game_StepLoading(86);
937 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_GO', GameWAD+':MTEXTURES\KNIGHT_GO', 128, 128, 4);
938 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN', GameWAD+':MTEXTURES\KNIGHT_PAIN', 128, 128, 1);
939 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN_L', GameWAD+':MTEXTURES\KNIGHT_PAIN_L', 128, 128, 1);
940 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK', GameWAD+':MTEXTURES\KNIGHT_ATTACK', 128, 128, 3);
941 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK_L', GameWAD+':MTEXTURES\KNIGHT_ATTACK_L', 128, 128, 3);
942 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_DIE', GameWAD+':MTEXTURES\KNIGHT_DIE', 128, 128, 7);
943 g_Game_StepLoading(92);
944 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_SLEEP', GameWAD+':MTEXTURES\MANCUB_SLEEP', 128, 128, 2);
945 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_GO', GameWAD+':MTEXTURES\MANCUB_GO', 128, 128, 6);
946 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_PAIN', GameWAD+':MTEXTURES\MANCUB_PAIN', 128, 128, 1);
947 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_ATTACK', GameWAD+':MTEXTURES\MANCUB_ATTACK', 128, 128, 3);
948 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_DIE', GameWAD+':MTEXTURES\MANCUB_DIE', 128, 128, 10);
949 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP', GameWAD+':MTEXTURES\SKEL_SLEEP', 128, 128, 2);
950 g_Game_StepLoading(98);
951 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP_L', GameWAD+':MTEXTURES\SKEL_SLEEP_L', 128, 128, 2);
952 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_GO', GameWAD+':MTEXTURES\SKEL_GO', 128, 128, 6);
953 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN', GameWAD+':MTEXTURES\SKEL_PAIN', 128, 128, 1);
954 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN_L', GameWAD+':MTEXTURES\SKEL_PAIN_L', 128, 128, 1);
955 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK', GameWAD+':MTEXTURES\SKEL_ATTACK', 128, 128, 2);
956 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK_L', GameWAD+':MTEXTURES\SKEL_ATTACK_L', 128, 128, 2);
957 g_Game_StepLoading(104);
958 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2', GameWAD+':MTEXTURES\SKEL_ATTACK2', 128, 128, 2);
959 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2_L', GameWAD+':MTEXTURES\SKEL_ATTACK2_L', 128, 128, 2);
960 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_DIE', GameWAD+':MTEXTURES\SKEL_DIE', 128, 128, 5);
961 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP', GameWAD+':MTEXTURES\VILE_SLEEP', 128, 128, 2);
962 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP_L', GameWAD+':MTEXTURES\VILE_SLEEP_L', 128, 128, 2);
963 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_GO', GameWAD+':MTEXTURES\VILE_GO', 128, 128, 6);
964 g_Game_StepLoading(110);
965 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN', GameWAD+':MTEXTURES\VILE_PAIN', 128, 128, 1);
966 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN_L', GameWAD+':MTEXTURES\VILE_PAIN_L', 128, 128, 1);
967 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK', GameWAD+':MTEXTURES\VILE_ATTACK', 128, 128, 10);
968 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK_L', GameWAD+':MTEXTURES\VILE_ATTACK_L', 128, 128, 10);
969 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2', GameWAD+':MTEXTURES\VILE_ATTACK2', 128, 128, 3);
970 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2_L', GameWAD+':MTEXTURES\VILE_ATTACK2_L', 128, 128, 3);
971 g_Game_StepLoading(116);
972 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_DIE', GameWAD+':MTEXTURES\VILE_DIE', 128, 128, 9);
973 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_SLEEP', GameWAD+':MTEXTURES\ROBO_SLEEP', 128, 128, 1);
974 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_GO', GameWAD+':MTEXTURES\ROBO_GO', 128, 128, 12);
975 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK', GameWAD+':MTEXTURES\ROBO_ATTACK', 128, 128, 2);
976 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK2', GameWAD+':MTEXTURES\ROBO_ATTACK2', 128, 128, 4);
977 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_DIE', GameWAD+':MTEXTURES\ROBO_DIE', 128, 128, 1);
978 g_Game_StepLoading(122);
979 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP', GameWAD+':MTEXTURES\CYBER_SLEEP', 128, 128, 2);
980 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP_L', GameWAD+':MTEXTURES\CYBER_SLEEP_L', 128, 128, 2);
981 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO', GameWAD+':MTEXTURES\CYBER_GO', 128, 128, 4);
982 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO_L', GameWAD+':MTEXTURES\CYBER_GO_L', 128, 128, 4);
983 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN', GameWAD+':MTEXTURES\CYBER_PAIN', 128, 128, 1);
984 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN_L', GameWAD+':MTEXTURES\CYBER_PAIN_L', 128, 128, 1);
985 g_Game_StepLoading(128);
986 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK', GameWAD+':MTEXTURES\CYBER_ATTACK', 128, 128, 2);
987 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK_L', GameWAD+':MTEXTURES\CYBER_ATTACK_L', 128, 128, 2);
988 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2', GameWAD+':MTEXTURES\CYBER_ATTACK2', 128, 128, 2);
989 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2_L', GameWAD+':MTEXTURES\CYBER_ATTACK2_L', 128, 128, 2);
990 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_DIE', GameWAD+':MTEXTURES\CYBER_DIE', 128, 128, 9);
991 g_Game_StepLoading(133);
993 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_SOUNDS], 0, False);
995 g_Sound_CreateWADEx('SOUND_MONSTER_BARREL_DIE', GameWAD+':MSOUNDS\BARREL_DIE');
997 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN', GameWAD+':MSOUNDS\PAIN');
998 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN2', GameWAD+':MSOUNDS\PAIN2');
999 g_Sound_CreateWADEx('SOUND_MONSTER_ACTION', GameWAD+':MSOUNDS\ACTION');
1000 g_Sound_CreateWADEx('SOUND_MONSTER_ACTION2', GameWAD+':MSOUNDS\ACTION2');
1001 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_1', GameWAD+':MSOUNDS\ALERT_1');
1002 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_2', GameWAD+':MSOUNDS\ALERT_2');
1003 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_3', GameWAD+':MSOUNDS\ALERT_3');
1004 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_1', GameWAD+':MSOUNDS\DIE_1');
1005 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_2', GameWAD+':MSOUNDS\DIE_2');
1006 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_3', GameWAD+':MSOUNDS\DIE_3');
1007 g_Sound_CreateWADEx('SOUND_MONSTER_SLOP', GameWAD+':MSOUNDS\SLOP');
1009 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_ATTACK', GameWAD+':MSOUNDS\DEMON_ATTACK');
1010 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_ALERT', GameWAD+':MSOUNDS\DEMON_ALERT');
1011 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_DIE', GameWAD+':MSOUNDS\DEMON_DIE');
1013 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ALERT_1', GameWAD+':MSOUNDS\IMP_ALERT_1');
1014 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ALERT_2', GameWAD+':MSOUNDS\IMP_ALERT_2');
1015 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_DIE_1', GameWAD+':MSOUNDS\IMP_DIE_1');
1016 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_DIE_2', GameWAD+':MSOUNDS\IMP_DIE_2');
1017 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ACTION', GameWAD+':MSOUNDS\IMP_ACTION');
1018 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ATTACK', GameWAD+':MSOUNDS\IMP_ATTACK');
1020 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_PAIN', GameWAD+':MSOUNDS\MAN_PAIN');
1021 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_ALERT', GameWAD+':MSOUNDS\MAN_ALERT');
1022 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_DIE', GameWAD+':MSOUNDS\MAN_DIE');
1023 g_Sound_CreateWADEx('SOUND_MONSTER_HAHA', GameWAD+':MSOUNDS\HAHA');
1024 g_Sound_CreateWADEx('SOUND_MONSTER_TRUP', GameWAD+':MSOUNDS\TRUP');
1026 g_Sound_CreateWADEx('SOUND_MONSTER_SOUL_ATTACK', GameWAD+':MSOUNDS\SOUL_ATTACK');
1027 g_Sound_CreateWADEx('SOUND_MONSTER_SOUL_DIE', GameWAD+':MSOUNDS\SOUL_DIE');
1029 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_ACTION', GameWAD+':MSOUNDS\BSP_ACTION');
1030 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_DIE', GameWAD+':MSOUNDS\BSP_DIE');
1031 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_ALERT', GameWAD+':MSOUNDS\BSP_ALERT');
1032 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_WALK', GameWAD+':MSOUNDS\BSP_WALK');
1034 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ACTION', GameWAD+':MSOUNDS\VILE_ACTION');
1035 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_PAIN', GameWAD+':MSOUNDS\VILE_PAIN');
1036 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_DIE', GameWAD+':MSOUNDS\VILE_DIE');
1037 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ALERT', GameWAD+':MSOUNDS\VILE_ALERT');
1038 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ATTACK', GameWAD+':MSOUNDS\VILE_ATTACK');
1040 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ACTION', GameWAD+':MSOUNDS\SKEL_ACTION');
1041 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_DIE', GameWAD+':MSOUNDS\SKEL_DIE');
1042 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ALERT', GameWAD+':MSOUNDS\SKEL_ALERT');
1043 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ATTACK', GameWAD+':MSOUNDS\SKEL_ATTACK');
1044 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_HIT', GameWAD+':MSOUNDS\SKEL_HIT');
1046 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_PAIN', GameWAD+':MSOUNDS\MANCUB_PAIN');
1047 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_DIE', GameWAD+':MSOUNDS\MANCUB_DIE');
1048 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_ALERT', GameWAD+':MSOUNDS\MANCUB_ALERT');
1049 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_ATTACK', GameWAD+':MSOUNDS\MANCUB_ATTACK');
1051 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_PAIN', GameWAD+':MSOUNDS\PAIN_PAIN');
1052 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_DIE', GameWAD+':MSOUNDS\PAIN_DIE');
1053 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_ALERT', GameWAD+':MSOUNDS\PAIN_ALERT');
1055 g_Sound_CreateWADEx('SOUND_MONSTER_BARON_DIE', GameWAD+':MSOUNDS\BARON_DIE');
1056 g_Sound_CreateWADEx('SOUND_MONSTER_BARON_ALERT', GameWAD+':MSOUNDS\BARON_ALERT');
1058 g_Sound_CreateWADEx('SOUND_MONSTER_CACO_DIE', GameWAD+':MSOUNDS\CACO_DIE');
1059 g_Sound_CreateWADEx('SOUND_MONSTER_CACO_ALERT', GameWAD+':MSOUNDS\CACO_ALERT');
1061 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_DIE', GameWAD+':MSOUNDS\CYBER_DIE');
1062 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_ALERT', GameWAD+':MSOUNDS\CYBER_ALERT');
1063 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_WALK', GameWAD+':MSOUNDS\CYBER_WALK');
1065 g_Sound_CreateWADEx('SOUND_MONSTER_KNIGHT_DIE', GameWAD+':MSOUNDS\KNIGHT_DIE');
1066 g_Sound_CreateWADEx('SOUND_MONSTER_KNIGHT_ALERT', GameWAD+':MSOUNDS\KNIGHT_ALERT');
1068 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_DIE', GameWAD+':MSOUNDS\SPIDER_DIE');
1069 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_ALERT', GameWAD+':MSOUNDS\SPIDER_ALERT');
1070 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_WALK', GameWAD+':MSOUNDS\SPIDER_WALK');
1072 g_Sound_CreateWADEx('SOUND_MONSTER_FISH_ATTACK', GameWAD+':MSOUNDS\FISH_ATTACK');
1074 freeInds := TIdPool.Create();
1075 clearUidMap();
1076 monCheckTrapLastFrameId := 0;
1077 monCheckMPlatLastFrameId := 0;
1078 end;
1080 procedure g_Monsters_FreeData();
1081 begin
1082 e_WriteLog('Releasing monsters data...', TMsgType.Notify);
1084 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_SLEEP');
1085 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_PAIN');
1086 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_DIE');
1087 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_SLEEP');
1088 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_GO');
1089 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_DIE');
1090 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_MESS');
1091 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK');
1092 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK_L');
1093 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_PAIN');
1094 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_SLEEP');
1095 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_GO');
1096 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_DIE');
1097 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_MESS');
1098 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK');
1099 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK_L');
1100 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_PAIN');
1101 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_SLEEP');
1102 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_GO');
1103 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_DIE');
1104 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_MESS');
1105 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_ATTACK');
1106 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_PAIN');
1107 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_SLEEP');
1108 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_SLEEP_L');
1109 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_GO');
1110 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_GO_L');
1111 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_DIE');
1112 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_MESS');
1113 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_ATTACK');
1114 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_ATTACK_L');
1115 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_PAIN');
1116 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_PAIN_L');
1117 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_SLEEP');
1118 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_GO');
1119 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_DIE');
1120 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_MESS');
1121 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_ATTACK');
1122 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_PAIN');
1123 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_SLEEP');
1124 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_GO');
1125 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_DIE');
1126 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_ATTACK');
1127 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_PAIN');
1128 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_SLEEP');
1129 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_GO');
1130 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_PAIN');
1131 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_ATTACK');
1132 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_DIE');
1133 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_SLEEP');
1134 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_GO');
1135 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_PAIN');
1136 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_ATTACK');
1137 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_DIE');
1138 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_SLEEP');
1139 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_GO');
1140 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_PAIN');
1141 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_PAIN_L');
1142 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_ATTACK');
1143 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_DIE');
1144 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_SLEEP');
1145 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_GO');
1146 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_PAIN');
1147 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_PAIN_L');
1148 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_ATTACK');
1149 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_DIE');
1150 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_SLEEP');
1151 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_GO');
1152 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_PAIN');
1153 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_ATTACK');
1154 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_DIE');
1155 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_SLEEP');
1156 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_GO');
1157 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_PAIN');
1158 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_ATTACK');
1159 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_DIE');
1160 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_SLEEP');
1161 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_SLEEP_L');
1162 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_GO');
1163 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_PAIN');
1164 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_PAIN_L');
1165 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_ATTACK');
1166 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_ATTACK_L');
1167 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_DIE');
1168 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_SLEEP');
1169 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_SLEEP_L');
1170 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_GO');
1171 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_PAIN');
1172 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_PAIN_L');
1173 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_ATTACK');
1174 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_ATTACK_L');
1175 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_DIE');
1176 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_SLEEP');
1177 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_GO');
1178 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_PAIN');
1179 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_ATTACK');
1180 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_DIE');
1181 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_SLEEP');
1182 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_SLEEP_L');
1183 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_GO');
1184 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_PAIN');
1185 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_PAIN_L');
1186 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK');
1187 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK_L');
1188 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK2');
1189 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK2_L');
1190 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_DIE');
1191 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_SLEEP');
1192 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_SLEEP_L');
1193 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_GO');
1194 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_PAIN');
1195 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_PAIN_L');
1196 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK');
1197 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK_L');
1198 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK2');
1199 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK2_L');
1200 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_DIE');
1201 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_SLEEP');
1202 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_GO');
1203 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_ATTACK');
1204 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_ATTACK2');
1205 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_DIE');
1206 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_SLEEP');
1207 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_SLEEP_L');
1208 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_GO');
1209 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_GO_L');
1210 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN');
1211 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN_L');
1212 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK');
1213 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK_L');
1214 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2');
1215 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2_L');
1216 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_DIE');
1218 g_Sound_Delete('SOUND_MONSTER_BARREL_DIE');
1220 g_Sound_Delete('SOUND_MONSTER_PAIN');
1221 g_Sound_Delete('SOUND_MONSTER_PAIN2');
1222 g_Sound_Delete('SOUND_MONSTER_ACTION');
1223 g_Sound_Delete('SOUND_MONSTER_ACTION2');
1224 g_Sound_Delete('SOUND_MONSTER_ALERT_1');
1225 g_Sound_Delete('SOUND_MONSTER_ALERT_2');
1226 g_Sound_Delete('SOUND_MONSTER_ALERT_3');
1227 g_Sound_Delete('SOUND_MONSTER_DIE_1');
1228 g_Sound_Delete('SOUND_MONSTER_DIE_2');
1229 g_Sound_Delete('SOUND_MONSTER_DIE_3');
1230 g_Sound_Delete('SOUND_MONSTER_SLOP');
1232 g_Sound_Delete('SOUND_MONSTER_DEMON_ATTACK');
1233 g_Sound_Delete('SOUND_MONSTER_DEMON_ALERT');
1234 g_Sound_Delete('SOUND_MONSTER_DEMON_DIE');
1236 g_Sound_Delete('SOUND_MONSTER_IMP_ALERT_1');
1237 g_Sound_Delete('SOUND_MONSTER_IMP_ALERT_2');
1238 g_Sound_Delete('SOUND_MONSTER_IMP_DIE_1');
1239 g_Sound_Delete('SOUND_MONSTER_IMP_DIE_2');
1240 g_Sound_Delete('SOUND_MONSTER_IMP_ACTION');
1241 g_Sound_Delete('SOUND_MONSTER_IMP_ATTACK');
1243 g_Sound_Delete('SOUND_MONSTER_MAN_PAIN');
1244 g_Sound_Delete('SOUND_MONSTER_MAN_ALERT');
1245 g_Sound_Delete('SOUND_MONSTER_MAN_DIE');
1246 g_Sound_Delete('SOUND_MONSTER_HAHA');
1247 g_Sound_Delete('SOUND_MONSTER_TRUP');
1249 g_Sound_Delete('SOUND_MONSTER_SOUL_ATTACK');
1250 g_Sound_Delete('SOUND_MONSTER_SOUL_DIE');
1252 g_Sound_Delete('SOUND_MONSTER_BSP_ACTION');
1253 g_Sound_Delete('SOUND_MONSTER_BSP_DIE');
1254 g_Sound_Delete('SOUND_MONSTER_BSP_ALERT');
1255 g_Sound_Delete('SOUND_MONSTER_BSP_WALK');
1257 g_Sound_Delete('SOUND_MONSTER_VILE_ACTION');
1258 g_Sound_Delete('SOUND_MONSTER_VILE_PAIN');
1259 g_Sound_Delete('SOUND_MONSTER_VILE_DIE');
1260 g_Sound_Delete('SOUND_MONSTER_VILE_ALERT');
1261 g_Sound_Delete('SOUND_MONSTER_VILE_ATTACK');
1263 g_Sound_Delete('SOUND_MONSTER_SKEL_ACTION');
1264 g_Sound_Delete('SOUND_MONSTER_SKEL_DIE');
1265 g_Sound_Delete('SOUND_MONSTER_SKEL_ALERT');
1266 g_Sound_Delete('SOUND_MONSTER_SKEL_ATTACK');
1267 g_Sound_Delete('SOUND_MONSTER_SKEL_HIT');
1269 g_Sound_Delete('SOUND_MONSTER_MANCUB_PAIN');
1270 g_Sound_Delete('SOUND_MONSTER_MANCUB_DIE');
1271 g_Sound_Delete('SOUND_MONSTER_MANCUB_ALERT');
1272 g_Sound_Delete('SOUND_MONSTER_MANCUB_ATTACK');
1274 g_Sound_Delete('SOUND_MONSTER_PAIN_PAIN');
1275 g_Sound_Delete('SOUND_MONSTER_PAIN_DIE');
1276 g_Sound_Delete('SOUND_MONSTER_PAIN_ALERT');
1278 g_Sound_Delete('SOUND_MONSTER_BARON_DIE');
1279 g_Sound_Delete('SOUND_MONSTER_BARON_ALERT');
1281 g_Sound_Delete('SOUND_MONSTER_CACO_DIE');
1282 g_Sound_Delete('SOUND_MONSTER_CACO_ALERT');
1284 g_Sound_Delete('SOUND_MONSTER_CYBER_DIE');
1285 g_Sound_Delete('SOUND_MONSTER_CYBER_ALERT');
1286 g_Sound_Delete('SOUND_MONSTER_CYBER_WALK');
1288 g_Sound_Delete('SOUND_MONSTER_KNIGHT_DIE');
1289 g_Sound_Delete('SOUND_MONSTER_KNIGHT_ALERT');
1291 g_Sound_Delete('SOUND_MONSTER_SPIDER_DIE');
1292 g_Sound_Delete('SOUND_MONSTER_SPIDER_ALERT');
1293 g_Sound_Delete('SOUND_MONSTER_SPIDER_WALK');
1295 g_Sound_Delete('SOUND_MONSTER_FISH_ATTACK');
1297 freeInds.Free();
1298 freeInds := nil;
1299 end;
1301 procedure g_Monsters_Init();
1302 begin
1303 soulcount := 0;
1304 end;
1306 procedure g_Monsters_Free (clearGrid: Boolean=true);
1307 var
1308 a: Integer;
1309 begin
1310 e_LogWritefln('Cleared monster data (clearGrid=%s)', [clearGrid]);
1311 if (clearGrid) then
1312 begin
1313 monsGrid.Free();
1314 monsGrid := nil;
1315 end;
1316 for a := 0 to High(gMonsters) do gMonsters[a].Free();
1317 gMonsters := nil;
1318 clearUidMap();
1319 monCheckTrapLastFrameId := 0;
1320 monCheckMPlatLastFrameId := 0;
1321 end;
1324 // will be called from map loader
1325 procedure g_Mons_InitTree (x, y, w, h: Integer);
1326 begin
1327 monsGrid.Free();
1328 monsGrid := TMonsterGrid.Create(x, y, w, h);
1329 //clearUidMap(); // why not?
1330 e_LogWritefln('%s', ['Recreated monster tree']);
1331 end;
1334 function g_Monsters_Create(MonsterType: Byte; X, Y: Integer;
1335 Direction: TDirection; AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
1336 var
1337 find_id: DWORD;
1338 mon: TMonster;
1339 begin
1340 result := nil;
1342 // Íåò òàêîãî ìîíñòðà
1343 if (MonsterType > MONSTER_MAN) or (MonsterType = 0) then exit;
1345 // Ñîáëþäàåì îãðàíè÷åíèå Lost_Soul'îâ
1346 if MonsterType = MONSTER_SOUL then
1347 begin
1348 if soulcount > MAX_SOUL then exit;
1349 soulcount += 1;
1350 end;
1352 find_id := allocMonster();
1354 mon := TMonster.Create(MonsterType, find_id, ForcedUID);
1355 gMonsters[find_id] := mon;
1356 mon.mArrIdx := find_id;
1357 mon.mProxyId := -1;
1359 uidMap[mon.FUID] := mon;
1361 // Íàñòðàèâàåì ïîëîæåíèå
1362 with mon do
1363 begin
1364 if AdjCoord then
1365 begin
1366 FObj.X := X-FObj.Rect.X - (FObj.Rect.Width div 2);
1367 FObj.Y := Y-FObj.Rect.Y - FObj.Rect.Height;
1368 end
1369 else
1370 begin
1371 FObj.X := X-FObj.Rect.X;
1372 FObj.Y := Y-FObj.Rect.Y;
1373 end;
1375 FDirection := Direction;
1376 FStartDirection := Direction;
1377 FStartX := GameX;
1378 FStartY := GameY;
1379 FObj.oldX := FObj.X;
1380 FObj.oldY := FObj.Y;
1381 end;
1383 mon.positionChanged();
1385 result := mon;
1386 end;
1388 procedure g_Monsters_killedp();
1389 var
1390 a, h: Integer;
1391 begin
1392 if gMonsters = nil then
1393 Exit;
1395 // Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
1396 h := High(gMonsters);
1397 for a := 0 to h do
1398 begin
1399 if (gMonsters[a] <> nil) then
1400 begin
1401 with gMonsters[a] do
1402 begin
1403 if (FMonsterType = MONSTER_MAN) and
1404 (FState <> MONSTATE_DEAD) and
1405 (FState <> MONSTATE_SLEEP) and
1406 (FState <> MONSTATE_DIE) then
1407 begin
1408 g_Sound_PlayExAt('SOUND_MONSTER_TRUP', FObj.X, FObj.Y);
1409 Exit;
1410 end;
1411 end;
1412 end;
1413 end;
1414 end;
1416 procedure g_Monsters_PreUpdate();
1417 var
1418 a: Integer;
1419 begin
1420 if gMonsters = nil then Exit;
1421 for a := 0 to High(gMonsters) do
1422 if (gMonsters[a] <> nil) and (not gMonsters[a].FRemoved) then
1423 gMonsters[a].PreUpdate();
1424 end;
1426 procedure g_Monsters_Update();
1427 var
1428 a: Integer;
1429 begin
1430 // Öåëåóêàçàòåëü
1431 if gTime mod (GAME_TICK*2) = 0 then
1432 begin
1433 pt_x := pt_x+pt_xs;
1434 pt_y := pt_y+pt_ys;
1435 if abs(pt_x) > 246 then pt_xs := -pt_xs;
1436 if abs(pt_y) > 100 then pt_ys := -pt_ys;
1437 end;
1439 gMon := True; // Äëÿ ðàáîòû BlockMon'à
1441 if gmon_debug_think or gmon_debug_one_think_step then
1442 begin
1443 gmon_debug_one_think_step := false;
1444 for a := 0 to High(gMonsters) do
1445 begin
1446 if (gMonsters[a] = nil) then continue;
1447 if not gMonsters[a].FRemoved then
1448 begin
1449 if g_Game_IsClient then
1450 gMonsters[a].ClientUpdate()
1451 else
1452 gMonsters[a].Update();
1453 end
1454 else
1455 begin
1456 gMonsters[a].Free();
1457 gMonsters[a] := nil;
1458 end;
1459 end;
1460 end;
1462 gMon := False;
1463 end;
1465 procedure g_Monsters_Draw();
1466 var
1467 a: Integer;
1468 begin
1469 if gMonsters <> nil then
1470 begin
1471 for a := 0 to High(gMonsters) do
1472 begin
1473 if (gMonsters[a] <> nil) then gMonsters[a].Draw();
1474 end;
1475 end;
1476 end;
1478 procedure g_Monsters_DrawHealth();
1479 var
1480 a: Integer;
1481 fW, fH: Byte;
1482 begin
1483 if gMonsters = nil then Exit;
1484 e_TextureFontGetSize(gStdFont, fW, fH);
1486 for a := 0 to High(gMonsters) do
1487 begin
1488 if gMonsters[a] <> nil then
1489 begin
1490 e_TextureFontPrint(gMonsters[a].FObj.X + gMonsters[a].FObj.Rect.X,
1491 gMonsters[a].FObj.Y + gMonsters[a].FObj.Rect.Y + gMonsters[a].FObj.Rect.Height - fH,
1492 IntToStr(gMonsters[a].FHealth), gStdFont);
1493 end;
1494 end;
1495 end;
1497 function g_Monsters_ByUID (UID: Word): TMonster;
1498 begin
1499 result := uidMap[UID];
1500 end;
1502 procedure g_Monsters_SaveState (st: TStream);
1503 var
1504 count, i: Integer;
1505 begin
1506 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ
1507 count := 0;
1508 for i := 0 to High(gMonsters) do
1509 begin
1510 if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then count += 1;
1511 end;
1513 // Ñîõðàíÿåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1514 utils.writeInt(st, LongInt(pt_x));
1515 utils.writeInt(st, LongInt(pt_xs));
1516 utils.writeInt(st, LongInt(pt_y));
1517 utils.writeInt(st, LongInt(pt_ys));
1519 // Êîëè÷åñòâî ìîíñòðîâ
1520 utils.writeInt(st, LongInt(count));
1522 if (count = 0) then exit;
1524 // Ñîõðàíÿåì ìîíñòðîâ
1525 for i := 0 to High(gMonsters) do
1526 begin
1527 if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then
1528 begin
1529 // Òèï ìîíñòðà
1530 utils.writeInt(st, Byte(gMonsters[i].MonsterType));
1531 // Ñîõðàíÿåì äàííûå ìîíñòðà:
1532 gMonsters[i].SaveState(st);
1533 end;
1534 end;
1535 end;
1538 procedure g_Monsters_LoadState (st: TStream);
1539 var
1540 count, a: Integer;
1541 b: Byte;
1542 mon: TMonster;
1543 begin
1544 assert(st <> nil);
1546 g_Monsters_Free(false);
1548 // Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1549 pt_x := utils.readLongInt(st);
1550 pt_xs := utils.readLongInt(st);
1551 pt_y := utils.readLongInt(st);
1552 pt_ys := utils.readLongInt(st);
1554 // Êîëè÷åñòâî ìîíñòðîâ
1555 count := utils.readLongInt(st);
1557 if (count = 0) then exit;
1558 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid monster count');
1560 // Çàãðóæàåì ìîíñòðîâ
1561 for a := 0 to count-1 do
1562 begin
1563 // Òèï ìîíñòðà
1564 b := utils.readByte(st);
1565 // Ñîçäàåì ìîíñòðà
1566 mon := g_Monsters_Create(b, 0, 0, TDirection.D_LEFT);
1567 if (mon = nil) then raise XStreamError.Create('g_Monsters_LoadState: ID = -1 (can''t create)');
1568 // Çàãðóæàåì äàííûå ìîíñòðà
1569 mon.LoadState(st);
1570 end;
1571 end;
1574 // ////////////////////////////////////////////////////////////////////////// //
1575 function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
1576 begin
1577 result := nil;
1578 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1579 begin
1580 result := g_Monsters_Create(monType, x, y, dir);
1581 end;
1582 end;
1585 function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
1586 begin
1587 result := g_Mons_SpawnAt(g_Mons_TypeIdByName(typeName), x, y, dir);
1588 end;
1592 // ////////////////////////////////////////////////////////////////////////// //
1593 function g_Mons_TypeLo (): Integer; inline; begin result := Low(MONSTERTABLE); end;
1594 function g_Mons_TypeHi (): Integer; inline; begin result := High(MONSTERTABLE); end;
1597 function g_Mons_TypeIdByName (const name: String): Integer;
1598 var
1599 i: Integer;
1600 begin
1601 i := MONSTER_DEMON;
1602 while (i <= MONSTER_MAN) do
1603 begin
1604 if (CompareText(name, MONSTERTABLE[i].Name) = 0) then
1605 begin
1606 result := i;
1607 exit;
1608 end;
1609 Inc(i);
1610 end;
1611 result := -1;
1612 // HACK!
1613 if (CompareText(name, 'zombie') = 0) then result := MONSTER_ZOMBY;
1614 end;
1617 function g_Mons_NameByTypeId (monType: Integer): AnsiString;
1618 begin
1619 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1620 result := MONSTERTABLE[monType].Name
1621 else
1622 result := '?';
1623 end;
1626 function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
1627 begin
1628 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1629 Result := KilledByMonster[monType]
1630 else
1631 Result := '?';
1632 end;
1635 // ////////////////////////////////////////////////////////////////////////// //
1636 { T M o n s t e r : }
1638 procedure TMonster.setGameX (v: Integer); inline; begin FObj.X := v; positionChanged(); end;
1639 procedure TMonster.setGameY (v: Integer); inline; begin FObj.Y := v; positionChanged(); end;
1641 procedure TMonster.setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline; begin FObj.X := ax; FObj.Y := ay; if callPosChanged then positionChanged(); end;
1643 procedure TMonster.moveBy (dx, dy: Integer); inline;
1644 begin
1645 if (dx <> 0) or (dy <> 0) then
1646 begin
1647 FObj.X += dx;
1648 FObj.Y += dy;
1649 positionChanged();
1650 end;
1651 end;
1653 procedure TMonster.doDamage (v: Integer);
1654 begin
1655 if (v <= 0) then exit;
1656 if (v > 32767) then v := 32767;
1657 Damage(v, 0, 0, 0, mEDamageType);
1658 end;
1660 procedure TMonster.ActionSound();
1661 begin
1662 case FMonsterType of
1663 MONSTER_IMP:
1664 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ACTION', FObj.X, FObj.Y);
1665 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN,
1666 MONSTER_MANCUB:
1667 g_Sound_PlayExAt('SOUND_MONSTER_ACTION', FObj.X, FObj.Y);
1668 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1669 MONSTER_KNIGHT, MONSTER_PAIN, MONSTER_DEMON,
1670 MONSTER_SPIDER:
1671 g_Sound_PlayExAt('SOUND_MONSTER_ACTION2', FObj.X, FObj.Y);
1672 MONSTER_BSP:
1673 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ACTION', FObj.X, FObj.Y);
1674 MONSTER_VILE:
1675 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ACTION', FObj.X, FObj.Y);
1676 MONSTER_SKEL:
1677 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ACTION', FObj.X, FObj.Y);
1678 MONSTER_CYBER:
1680 MONSTER_MAN:
1681 g_Sound_PlayExAt('SOUND_MONSTER_HAHA', FObj.X, FObj.Y);
1682 end;
1683 end;
1685 procedure TMonster.PainSound();
1686 begin
1687 if FPainSound then
1688 Exit;
1690 FPainSound := True;
1691 FPainTicks := 20;
1693 case FMonsterType of
1694 MONSTER_IMP, MONSTER_ZOMBY, MONSTER_SERG,
1695 MONSTER_SKEL, MONSTER_CGUN:
1696 g_Sound_PlayExAt('SOUND_MONSTER_PAIN', FObj.X, FObj.Y);
1697 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1698 MONSTER_KNIGHT, MONSTER_DEMON, MONSTER_SPIDER,
1699 MONSTER_BSP, MONSTER_CYBER:
1700 g_Sound_PlayExAt('SOUND_MONSTER_PAIN2', FObj.X, FObj.Y);
1701 MONSTER_VILE:
1702 g_Sound_PlayExAt('SOUND_MONSTER_VILE_PAIN', FObj.X, FObj.Y);
1703 MONSTER_MANCUB:
1704 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_PAIN', FObj.X, FObj.Y);
1705 MONSTER_PAIN:
1706 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_PAIN', FObj.X, FObj.Y);
1707 MONSTER_MAN:
1708 g_Sound_PlayExAt('SOUND_MONSTER_MAN_PAIN', FObj.X, FObj.Y);
1709 end;
1710 end;
1712 procedure TMonster.DieSound();
1713 begin
1714 case FMonsterType of
1715 MONSTER_IMP:
1716 case Random(2) of
1717 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_1', FObj.X, FObj.Y);
1718 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_2', FObj.X, FObj.Y);
1719 end;
1720 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1721 case Random(3) of
1722 0: g_Sound_PlayExAt('SOUND_MONSTER_DIE_1', FObj.X, FObj.Y);
1723 1: g_Sound_PlayExAt('SOUND_MONSTER_DIE_2', FObj.X, FObj.Y);
1724 2: g_Sound_PlayExAt('SOUND_MONSTER_DIE_3', FObj.X, FObj.Y);
1725 end;
1726 MONSTER_DEMON:
1727 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_DIE', FObj.X, FObj.Y);
1728 MONSTER_BARREL:
1729 g_Sound_PlayExAt('SOUND_MONSTER_BARREL_DIE', FObj.X, FObj.Y);
1730 MONSTER_SOUL:
1731 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_DIE', FObj.X, FObj.Y);
1732 MONSTER_BSP:
1733 g_Sound_PlayExAt('SOUND_MONSTER_BSP_DIE', FObj.X, FObj.Y);
1734 MONSTER_VILE:
1735 g_Sound_PlayExAt('SOUND_MONSTER_VILE_DIE', FObj.X, FObj.Y);
1736 MONSTER_BARON:
1737 g_Sound_PlayExAt('SOUND_MONSTER_BARON_DIE', FObj.X, FObj.Y);
1738 MONSTER_CACO:
1739 g_Sound_PlayExAt('SOUND_MONSTER_CACO_DIE', FObj.X, FObj.Y);
1740 MONSTER_CYBER:
1741 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_DIE', FObj.X, FObj.Y);
1742 MONSTER_KNIGHT:
1743 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_DIE', FObj.X, FObj.Y);
1744 MONSTER_MANCUB:
1745 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_DIE', FObj.X, FObj.Y);
1746 MONSTER_PAIN:
1747 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_DIE', FObj.X, FObj.Y);
1748 MONSTER_SKEL:
1749 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_DIE', FObj.X, FObj.Y);
1750 MONSTER_SPIDER:
1751 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_DIE', FObj.X, FObj.Y);
1752 MONSTER_MAN:
1753 g_Sound_PlayExAt('SOUND_MONSTER_MAN_DIE', FObj.X, FObj.Y);
1754 end;
1755 end;
1757 procedure TMonster.WakeUpSound();
1758 begin
1759 case FMonsterType of
1760 MONSTER_IMP:
1761 case Random(2) of
1762 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_1', FObj.X, FObj.Y);
1763 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_2', FObj.X, FObj.Y);
1764 end;
1765 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1766 case Random(3) of
1767 0: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_1', FObj.X, FObj.Y);
1768 1: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_2', FObj.X, FObj.Y);
1769 2: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_3', FObj.X, FObj.Y);
1770 end;
1771 MONSTER_MAN:
1772 g_Sound_PlayExAt('SOUND_MONSTER_MAN_ALERT', FObj.X, FObj.Y);
1773 MONSTER_BSP:
1774 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ALERT', FObj.X, FObj.Y);
1775 MONSTER_VILE:
1776 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ALERT', FObj.X, FObj.Y);
1777 MONSTER_BARON:
1778 g_Sound_PlayExAt('SOUND_MONSTER_BARON_ALERT', FObj.X, FObj.Y);
1779 MONSTER_CACO:
1780 g_Sound_PlayExAt('SOUND_MONSTER_CACO_ALERT', FObj.X, FObj.Y);
1781 MONSTER_CYBER:
1782 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_ALERT', FObj.X, FObj.Y);
1783 MONSTER_KNIGHT:
1784 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_ALERT', FObj.X, FObj.Y);
1785 MONSTER_MANCUB:
1786 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ALERT', FObj.X, FObj.Y);
1787 MONSTER_PAIN:
1788 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_ALERT', FObj.X, FObj.Y);
1789 MONSTER_DEMON:
1790 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ALERT', FObj.X, FObj.Y);
1791 MONSTER_SKEL:
1792 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ALERT', FObj.X, FObj.Y);
1793 MONSTER_SPIDER:
1794 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_ALERT', FObj.X, FObj.Y);
1795 MONSTER_SOUL:
1797 end;
1798 end;
1800 procedure TMonster.BFGHit();
1801 begin
1802 if FMonsterType = MONSTER_FISH then
1803 Exit;
1805 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1806 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1807 {if g_Game_IsServer and g_Game_IsNet then
1808 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1809 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1810 0, NET_GFX_BFG);}
1811 end;
1813 function TMonster.Collide(X, Y: Integer; Width, Height: Word): Boolean;
1814 begin
1815 Result := g_Collide(FObj.X+FObj.Rect.X,
1816 FObj.Y+FObj.Rect.Y,
1817 FObj.Rect.Width,
1818 FObj.Rect.Height,
1819 X, Y,
1820 Width, Height);
1821 end;
1823 function TMonster.Collide(Panel: TPanel): Boolean;
1824 begin
1825 Result := g_Collide(FObj.X+FObj.Rect.X,
1826 FObj.Y+FObj.Rect.Y,
1827 FObj.Rect.Width,
1828 FObj.Rect.Height,
1829 Panel.X, Panel.Y,
1830 Panel.Width, Panel.Height);
1831 end;
1833 function TMonster.Collide(X, Y: Integer): Boolean;
1834 begin
1835 X := X - FObj.X - FObj.Rect.X;
1836 Y := Y - FObj.Y - FObj.Rect.Y;
1837 Result := (x >= 0) and (x <= FObj.Rect.Width) and
1838 (y >= 0) and (y <= FObj.Rect.Height);
1839 end;
1841 procedure TMonster.Respawn;
1842 begin
1843 FObj.Vel.X := 0;
1844 FObj.Vel.Y := 0;
1845 FObj.Accel.X := 0;
1846 FObj.Accel.Y := 0;
1847 FDirection := FStartDirection;
1848 {GameX}FObj.X := FStartX;
1849 {GameY}FObj.Y := FStartY;
1850 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
1851 FHealth := MONSTERTABLE[FMonsterType].Health;
1852 FAmmo := 0;
1853 FPain := 0;
1854 FTargetUID := 0;
1855 FTargetTime := 0;
1856 FDieTriggers := nil;
1857 FWaitAttackAnim := False;
1858 FChainFire := False;
1859 FShellTimer := -1;
1861 FState := MONSTATE_SLEEP;
1862 FCurAnim := ANIM_SLEEP;
1864 positionChanged(); // this updates spatial accelerators
1866 if g_Game_IsNet and g_Game_IsServer then
1867 begin
1868 MH_SEND_MonsterPos(FUID);
1869 MH_SEND_MonsterState(FUID);
1870 end;
1871 end;
1873 constructor TMonster.Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
1874 var
1875 a: Integer;
1876 FramesID: DWORD = 0;
1877 s: String;
1878 res: Boolean;
1879 begin
1880 if ForcedUID < 0 then
1881 FUID := g_CreateUID(UID_MONSTER)
1882 else
1883 FUID := ForcedUID;
1885 FMonsterType := MonsterType;
1887 g_Obj_Init(@FObj);
1889 FState := MONSTATE_SLEEP;
1890 FCurAnim := ANIM_SLEEP;
1891 FHealth := MONSTERTABLE[MonsterType].Health;
1892 FMaxHealth := FHealth;
1893 FObj.Rect := MONSTERTABLE[MonsterType].Rect;
1894 FDieTriggers := nil;
1895 FSpawnTrigger := -1;
1896 FWaitAttackAnim := False;
1897 FChainFire := False;
1898 FStartID := aID;
1899 FNoRespawn := False;
1900 FShellTimer := -1;
1901 FBehaviour := BH_NORMAL;
1902 FFireTime := 0;
1903 FFirePainTime := 0;
1904 FFireAttacker := 0;
1905 mEDamageType := HIT_SOME;
1907 mProxyId := -1;
1908 mArrIdx := -1;
1909 trapCheckFrameId := 0;
1910 mplatCheckFrameId := 0;
1911 mNeedSend := false;
1913 if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
1914 FBloodKind := BLOOD_SPARKS
1915 else
1916 FBloodKind := BLOOD_NORMAL;
1917 if FMonsterType = MONSTER_CACO then
1918 begin
1919 FBloodRed := 0;
1920 FBloodGreen := 0;
1921 FBloodBlue := 150;
1922 end
1923 else if FMonsterType in [MONSTER_BARON, MONSTER_KNIGHT] then
1924 begin
1925 FBloodRed := 0;
1926 FBloodGreen := 150;
1927 FBloodBlue := 0;
1928 end
1929 else
1930 begin
1931 FBloodRed := 150;
1932 FBloodGreen := 0;
1933 FBloodBlue := 0;
1934 end;
1936 SetLength(FAnim, Length(ANIMTABLE));
1938 for a := 0 to High(FAnim) do
1939 begin
1940 FAnim[a, TDirection.D_LEFT] := nil;
1941 FAnim[a, TDirection.D_RIGHT] := nil;
1942 end;
1944 for a := ANIM_SLEEP to ANIM_PAIN do
1945 if (ANIMTABLE[a].name <> '') and
1946 (MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a] <> 0) then
1947 begin
1948 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1949 '_'+ANIMTABLE[a].name;
1951 res := g_Frames_Exists(s);
1953 if res then
1954 res := g_Frames_Get(FramesID, s);
1956 // Åñëè íåò òàêîé àíèìàöèè, òî ïðîáóåì çàìåíèòü åå íà àíèìàöèþ ñìåðòè:
1957 if (not res) then
1958 begin
1959 // Çàìåíÿåì òîëüêî ANIM_MESS íà ANIM_DIE:
1960 if a <> ANIM_MESS then
1961 Continue;
1963 if g_Frames_Get(FramesID, 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1964 '_'+ANIMTABLE[ANIM_DIE].name) then
1965 begin
1966 FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1967 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1968 FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1969 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1970 Continue;
1971 end;
1972 end;
1974 FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1975 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1977 // Åñëè åñòü îòäåëüíàÿ ëåâàÿ àíèìàöèÿ - çàãðóæàåì:
1978 if MONSTER_ANIMTABLE[MonsterType].LeftAnim then
1979 begin
1980 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1981 '_'+ANIMTABLE[a].name+'_L';
1982 if g_Frames_Exists(s) then
1983 g_Frames_Get(FramesID, s);
1984 end;
1986 FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1987 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1988 end;
1990 // Äëÿ êîëäóíà çàãðóæàåì òàêæå àíèìàöèþ îãíÿ:
1991 if MonsterType = MONSTER_VILE then
1992 begin
1993 g_Frames_Get(FramesID, 'FRAMES_FIRE');
1994 vilefire := TAnimation.Create(FramesID, True, 2);
1995 end
1996 else
1997 vilefire := nil;
1998 end;
2000 function TMonster.Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
2001 var
2002 c, it: Integer;
2003 p: TPlayer;
2004 begin
2005 Result := False;
2007 // Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
2008 if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
2010 // Óìèðàåò, óìåð èëè âîñêðåøàåòñÿ => óðîí äåëàòü íåêîìó:
2011 if (FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE) or (FState = MONSTATE_REVIVE) then
2012 Exit;
2014 // Ðûáó â âîäå áüåò òîêîì => ïàíèêà áåç óðîíà:
2015 if (t = HIT_ELECTRO) and (FMonsterType = MONSTER_FISH) and g_Game_IsServer then
2016 begin
2017 FSleep := 20;
2018 if Random(2) = 0 then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
2019 Result := True;
2020 SetState(MONSTATE_RUN);
2021 Exit;
2022 end;
2024 // Àð÷è íå ãîðÿò, ÷åðåïà óæå ãîðÿò
2025 if (t = HIT_FLAME) and (FMonsterType in [MONSTER_VILE, MONSTER_SOUL]) then
2026 begin
2027 // Ïðîñíóòüñÿ âñå-òàêè ñòîèò
2028 if FState = MONSTATE_SLEEP then
2029 SetState(MONSTATE_GO);
2030 Exit;
2031 end;
2033 // Ëîâóøêà óáèâàåò ñðàçó:
2034 if t = HIT_TRAP then
2035 FHealth := -100;
2037 // Ðîáîòó óðîíà íåò:
2038 if FMonsterType = MONSTER_ROBO then
2039 aDamage := 0;
2041 // Íàíîñèì óðîí:
2042 if g_Game_IsServer then Dec(FHealth, aDamage);
2044 // Óñèëèâàåì áîëü ìîíñòðà îò óðîíà:
2045 if FPain = 0 then
2046 FPain := 3;
2047 FPain := FPain+aDamage;
2049 // Åñëè áîëü ñóùåñòâåííàÿ, òî ìåíÿåì ñîñòîÿíèå íà áîëåâîå:
2050 if FState <> MONSTATE_PAIN then
2051 if (FPain >= MONSTERTABLE[FMonsterType].MinPain) and
2052 (FMonsterType <> MONSTER_BARREL) then
2053 SetState(MONSTATE_PAIN);
2055 // Åñëè ðàçðåøåíà êðîâü - ñîçäàåì áðûçãè êðîâè:
2056 if (gBloodCount > 0) then
2057 begin
2058 c := Min(aDamage, 200);
2059 c := c*gBloodCount - (aDamage div 4) + Random(c div 2);
2061 if (VelX = 0) and (VelY = 0) then
2062 MakeBloodSimple(c)
2063 else
2064 case t of
2065 HIT_TRAP, HIT_ACID, HIT_ELECTRO, HIT_FLAME: MakeBloodSimple(c);
2066 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, VelX, VelY);
2067 end;
2068 end;
2070 // Òåïåðü öåëü - óäàðèâøèé, åñëè òîëüêî íå ñàì ñåáÿ:
2071 if (SpawnerUID <> FUID) and (BehaviourDamage(SpawnerUID, FBehaviour, FMonsterType)) then
2072 begin
2073 FTargetUID := SpawnerUID;
2074 FTargetTime := 0;
2075 end;
2077 // Çäîðîâüå çàêîí÷èëîñü:
2078 if FHealth <= 0 then
2079 begin
2080 // Åñëè ýòî íå áî÷êà è óáèë èãðîê, òî åìó +1:
2081 if (FMonsterType <> MONSTER_BARREL) then
2082 begin
2083 if (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2084 begin
2085 p := g_Player_Get(SpawnerUID);
2086 if (p <> nil) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2087 begin
2088 p.MonsterKills := p.MonsterKills+1;
2089 if gGameSettings.GameMode = GM_COOP then
2090 p.Frags := p.Frags + 1;
2091 // Uncomment this if you want to double-kill monsters
2092 //p.FragCombo();
2093 end;
2094 end;
2095 if gLMSRespawn = LMS_RESPAWN_NONE then
2096 begin
2097 Inc(gCoopMonstersKilled);
2098 if g_Game_IsNet then
2099 MH_SEND_GameStats;
2100 end;
2101 end;
2103 // Âûáèðàåì ëóò:
2104 case FMonsterType of
2105 MONSTER_ZOMBY: c := ITEM_AMMO_BULLETS;
2106 MONSTER_SERG: c := ITEM_WEAPON_SHOTGUN1;
2107 MONSTER_CGUN: c := ITEM_WEAPON_CHAINGUN;
2108 MONSTER_MAN: c := ITEM_KEY_RED;
2109 else c := 0;
2110 end;
2112 // Áðîñàåì ëóò:
2113 if c <> 0 then
2114 begin
2115 it := g_Items_Create(FObj.X + (FObj.Rect.Width div 2),
2116 FObj.Y + (FObj.Rect.Height div 2),
2117 c, True, False);
2118 g_Items_SetDrop(it); // mark it as monster drop
2119 g_Obj_Push(g_Items_ObjByIdx(it), (FObj.Vel.X div 2)-3+Random(7),
2120 (FObj.Vel.Y div 2)-Random(4));
2121 //positionChanged(); // this updates spatial accelerators
2122 if g_Game_IsServer and g_Game_IsNet then
2123 MH_SEND_ItemSpawn(True, it);
2124 end;
2126 // Òðóï äàëüøå íå èäåò:
2127 FObj.Vel.X := 0;
2129 // Ó òðóïà ðàçìåðû ìåíüøå:
2130 if (FMonsterType <> MONSTER_FISH) and (FMonsterType <> MONSTER_PAIN) then
2131 begin
2132 FObj.Rect.Y := FObj.Rect.Y + FObj.Rect.Height-12;
2133 FObj.Rect.Height := 12;
2134 positionChanged();
2135 end;
2137 // Óðîí áûë ñèëüíûì => ñëàáûå - â êàøó:
2138 if (FHealth <= -30) and
2139 ((FMonsterType = MONSTER_IMP) or (FMonsterType = MONSTER_ZOMBY) or
2140 (FMonsterType = MONSTER_SERG) or (FMonsterType = MONSTER_CGUN) or
2141 (FMonsterType = MONSTER_MAN)) then
2142 begin
2143 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
2144 SetState(MONSTATE_DIE, ANIM_MESS);
2145 end
2146 else
2147 begin
2148 DieSound();
2149 SetState(MONSTATE_DIE);
2150 end;
2152 // Àêòèâèðîâàòü òðèããåðû, æäóùèå ñìåðòè ýòîãî ìîíñòðà:
2153 if g_Game_IsServer then ActivateTriggers();
2155 FHealth := 0;
2156 end
2157 else
2158 if FState = MONSTATE_SLEEP then
2159 begin // Ñïàë, ðàçáóäèëè íåñìåðòåëüíûì óäàðîì:
2160 FPain := MONSTERTABLE[FMonsterType].Pain;
2161 SetState(MONSTATE_GO);
2162 end;
2164 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
2165 Result := True;
2166 end;
2168 function TMonster.Heal(Value: Word): Boolean;
2169 begin
2170 Result := False;
2171 if g_Game_IsClient then
2172 Exit;
2173 if not alive then
2174 Exit;
2176 if FHealth < FMaxHealth then
2177 begin
2178 IncMax(FHealth, Value, FMaxHealth);
2179 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
2180 Result := True;
2181 end;
2182 end;
2184 destructor TMonster.Destroy();
2185 var
2186 a: Integer;
2187 begin
2188 for a := 0 to High(FAnim) do
2189 begin
2190 FAnim[a, TDirection.D_LEFT].Free();
2191 FAnim[a, TDirection.D_RIGHT].Free();
2192 end;
2194 vilefire.Free();
2196 if (mProxyId <> -1) then
2197 begin
2198 if (monsGrid <> nil) then
2199 begin
2200 monsGrid.removeBody(mProxyId);
2201 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
2202 e_WriteLog(Format('monster #%d:(%u): removed from grid; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
2203 {$ENDIF}
2204 end;
2205 mProxyId := -1;
2206 end;
2208 if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then
2209 begin
2210 freeInds.release(mArrIdx);
2211 gMonsters[mArrIdx] := nil;
2212 end;
2213 mArrIdx := -1;
2215 uidMap[FUID] := nil;
2217 inherited Destroy();
2218 end;
2220 procedure TMonster.Draw();
2221 var
2222 m: TMirrorType;
2223 dx, dy, c, fX, fY: Integer;
2224 o: TObj;
2225 begin
2226 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, 'TYPE: '+IntToStr(FMonsterType));
2227 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y+16, 'STATE: '+IntToStr(FState));
2229 FObj.lerp(gLerpFactor, fX, fY);
2231 // Åñëè êîëäóí ñòðåëÿåò, òî ðèñóåì îãîíü:
2232 if FMonsterType = MONSTER_VILE then
2233 if FState = MONSTATE_SHOOT then
2234 if GetPos(FTargetUID, @o) then
2235 vilefire.Draw(o.X+o.Rect.X+(o.Rect.Width div 2)-32,
2236 o.Y+o.Rect.Y+o.Rect.Height-128, TMirrorType.None);
2238 // Íå â îáëàñòè ðèñîâàíèÿ íå ðåñóåì:
2239 //FIXME!
2240 if (g_dbg_scale = 1.0) then
2241 begin
2242 if not g_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height,
2243 sX-128, sY-128, sWidth+256, sHeight+256) then
2244 Exit;
2245 end;
2247 // Ýòè ìîíñòðû, óìèðàÿ, íå îñòàâëÿþò òðóïîâ:
2248 if FState = MONSTATE_DEAD then
2249 case FMonsterType of
2250 MONSTER_BARREL, MONSTER_SOUL, MONSTER_PAIN: Exit;
2251 end;
2253 // Åñòü ÷òî ðèñîâàòü ïðè òåêóùåì ïîâåäåíèè:
2254 if FAnim[FCurAnim, FDirection] <> nil then
2255 begin
2256 // Åñëè íåò ëåâîé àíèìàöèè èëè îíà ñîâïàäàåò ñ ïðàâîé => îòðàæàåì ïðàâóþ:
2257 if (FDirection = TDirection.D_LEFT) and
2258 ((not MONSTER_ANIMTABLE[FMonsterType].LeftAnim) or
2259 (FAnim[FCurAnim, TDirection.D_LEFT].FramesID = FAnim[FCurAnim, TDirection.D_RIGHT].FramesID)) and
2260 (FMonsterType <> MONSTER_BARREL) then
2261 m := TMirrorType.Horizontal
2262 else
2263 m := TMirrorType.None;
2265 // Ëåâàÿ àíèìàöèÿ => ìåíÿåì ñìåùåíèå îòíîñèòåëüíî öåíòðà:
2266 if (FDirection = TDirection.D_LEFT) and
2267 (FMonsterType <> MONSTER_BARREL) then
2268 begin
2269 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].X;
2270 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].Y;
2272 if m = TMirrorType.Horizontal then
2273 begin // Íåò îòäåëüíîé ëåâîé àíèìàöèè
2274 // Ðàññòîÿíèå îò êðàÿ òåêñòóðû äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2275 c := (MONSTERTABLE[FMonsterType].Rect.X - dx) + MONSTERTABLE[FMonsterType].Rect.Width;
2276 // Ðàññòîÿíèå îò êðàÿ õèò áîêñà äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2277 dx := FAnim[FCurAnim, FDirection].Width - c - MONSTERTABLE[FMonsterType].Rect.X;
2278 // Ò.ê. äâèãàòü òåêñòóðó íóæíî áóäåò â ïðîòèâîïîëîæíîì íàïðàâëåíèè:
2279 dx := -dx;
2280 // Ýòî çíà÷èò: dX := -frameWidth - animDeltaX + hitX + hitWidth + hitX
2281 end;
2282 end
2283 else // Ïðàâàÿ àíèìàöèÿ
2284 begin
2285 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].X;
2286 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].Y;
2287 end;
2289 // Ðèñóåì:
2290 FAnim[FCurAnim, FDirection].Draw(fX+dx, fY+dy, m);
2291 end;
2293 if g_debug_Frames then
2294 begin
2295 e_DrawQuad(FObj.X+FObj.Rect.X,
2296 FObj.Y+FObj.Rect.Y,
2297 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2298 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2299 0, 255, 0);
2300 end;
2301 end;
2303 procedure TMonster.MakeBloodSimple(Count: Word);
2304 begin
2305 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)+8,
2306 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2307 Count div 2, 3, -1, 16, (FObj.Rect.Height*2 div 3),
2308 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2309 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-8,
2310 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2311 Count div 2, -3, -1, 16, (FObj.Rect.Height*2) div 3,
2312 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2313 end;
2315 procedure TMonster.MakeBloodVector(Count: Word; VelX, VelY: Integer);
2316 begin
2317 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2318 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2319 Count, VelX, VelY, 16, (FObj.Rect.Height*2) div 3,
2320 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2321 end;
2323 procedure TMonster.Push(vx, vy: Integer);
2324 begin
2325 FObj.Accel.X := FObj.Accel.X + vx;
2326 FObj.Accel.Y := FObj.Accel.Y + vy;
2327 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2328 end;
2330 procedure TMonster.SetState(State: Byte; ForceAnim: Byte = 255);
2331 var
2332 Anim: Byte;
2333 begin
2334 // Åñëè ñîñòîÿíèå = íà÷àëè óìèðàòü, à ýòîò ìîíñòð = Lost_Soul,
2335 // òî ñîáëþäàåì îãðàíè÷åíèå êîëè÷åñòâà Lost_Soul'îâ:
2336 if (State = MONSTATE_DIE) and (MonsterType = MONSTER_SOUL) then
2337 soulcount := soulcount-1;
2339 // Ïðèñìåðòè - íåëüçÿ ñðàçó íà÷èíàòü àòàêîâàòü èëè áåãàòü:
2340 case FState of
2341 MONSTATE_DIE, MONSTATE_DEAD, MONSTATE_REVIVE:
2342 if (State <> MONSTATE_DEAD) and (State <> MONSTATE_REVIVE) and
2343 (State <> MONSTATE_GO) then
2344 Exit;
2345 end;
2347 // Ñìåíà ñîñòîÿíèÿ:
2348 FState := State;
2350 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID, ForceAnim);
2352 // Íîâàÿ àíèìàöèÿ ïðè íîâîì ñîñòîÿíèè:
2353 case FState of
2354 MONSTATE_SLEEP: Anim := ANIM_SLEEP;
2355 MONSTATE_PAIN: Anim := ANIM_PAIN;
2356 MONSTATE_WAIT: Anim := ANIM_SLEEP;
2357 MONSTATE_CLIMB, MONSTATE_RUN, MONSTATE_RUNOUT, MONSTATE_GO: Anim := ANIM_GO;
2358 MONSTATE_SHOOT: Anim := ANIM_ATTACK;
2359 MONSTATE_ATTACK: Anim := ANIM_ATTACK;
2360 MONSTATE_DIE: Anim := ANIM_DIE;
2361 MONSTATE_REVIVE:
2362 begin // íà÷àëè âîñêðåøàòüñÿ
2363 Anim := FCurAnim;
2364 FAnim[Anim, FDirection].Revert(True);
2366 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
2367 FHealth := MONSTERTABLE[FMonsterType].Health;
2368 FAmmo := 0;
2369 FPain := 0;
2370 end;
2371 else Exit;
2372 end;
2374 // Íàäî ñìåíèòü àíèìàöèþ íà íåñòàíäàðòíóþ:
2375 if ForceAnim <> 255 then
2376 Anim := ForceAnim;
2378 // Åñëè àíèìàöèÿ íîâàÿ - ïåðåçàïóñêàåì å¸:
2379 if FCurAnim <> Anim then
2380 if FAnim[Anim, FDirection] <> nil then
2381 begin
2382 FAnim[Anim, FDirection].Reset();
2383 FCurAnim := Anim;
2384 end;
2385 end;
2387 function TMonster.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
2388 var
2389 TA: TAnimation;
2390 FramesID: DWORD;
2391 begin
2392 Result := False;
2394 //  òî÷êå íàçíà÷åíèÿ ñòåíà:
2395 if g_CollideLevel(X, Y, FObj.Rect.Width, FObj.Rect.Height) then
2396 begin
2397 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
2398 if g_Game_IsServer and g_Game_IsNet then
2399 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
2400 Exit;
2401 end;
2403 TA := nil;
2405 // Ýôôåêò òåëåïîðòà â ïîçèöèè ìîíñòðà:
2406 if not silent then
2407 begin
2408 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
2409 TA := TAnimation.Create(FramesID, False, 6);
2410 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', Obj.X, Obj.Y);
2411 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2412 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2414 if g_Game_IsServer and g_Game_IsNet then
2415 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2416 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 1,
2417 NET_GFX_TELE);
2418 end;
2420 FObj.X := X - FObj.Rect.X;
2421 FObj.Y := Y - FObj.Rect.Y;
2422 FObj.oldX := FObj.X; // don't interpolate after teleport
2423 FObj.oldY := FObj.Y;
2424 positionChanged();
2426 if dir = 1 then
2427 FDirection := TDirection.D_LEFT
2428 else
2429 if dir = 2 then
2430 FDirection := TDirection.D_RIGHT
2431 else
2432 if dir = 3 then
2433 begin // îáðàòíîå
2434 if FDirection = TDirection.D_RIGHT then
2435 FDirection := TDirection.D_LEFT
2436 else
2437 FDirection := TDirection.D_RIGHT;
2438 end;
2440 // Ýôôåêò òåëåïîðòà â òî÷êå íàçíà÷åíèÿ:
2441 if not silent and (TA <> nil) then
2442 begin
2443 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2444 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2445 TA.Free();
2447 if g_Game_IsServer and g_Game_IsNet then
2448 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2449 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 0,
2450 NET_GFX_TELE);
2451 end;
2453 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2454 Result := True;
2455 end;
2457 procedure TMonster.PreUpdate();
2458 begin
2459 FObj.oldX := FObj.X;
2460 FObj.oldY := FObj.Y;
2461 end;
2463 procedure TMonster.Update();
2464 var
2465 a, b, sx, sy, wx, wy, oldvelx, i: Integer;
2466 st: Word;
2467 o, co: TObj;
2468 fall: Boolean;
2469 mon: TMonster;
2470 mit: PMonster;
2471 it: TMonsterGrid.Iter;
2472 label
2473 _end;
2474 begin
2475 fall := True;
2477 // Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
2478 if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
2480 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
2481 if FMonsterType = MONSTER_FISH then
2482 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
2483 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2484 fall := False;
2486 // Ëåòàþùèå ìîíñòðû:
2487 if ((FMonsterType = MONSTER_SOUL) or
2488 (FMonsterType = MONSTER_PAIN) or
2489 (FMonsterType = MONSTER_CACO)) and
2490 (FState <> MONSTATE_DIE) and
2491 (FState <> MONSTATE_DEAD) then
2492 fall := False;
2494 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
2495 if gTime mod (GAME_TICK*2) <> 0 then
2496 begin
2497 g_Obj_Move(@FObj, fall, True, True);
2498 positionChanged(); // this updates spatial accelerators
2499 Exit;
2500 end;
2502 if FPainTicks > 0 then
2503 Dec(FPainTicks)
2504 else
2505 FPainSound := False;
2507 // Äâèãàåìñÿ:
2508 st := g_Obj_Move(@FObj, fall, True, True);
2509 positionChanged(); // this updates spatial accelerators
2511 // Åñëè ãîðèì - ïîäæèãàåì äðóãèõ ìîíñòðîâ, íî íå íà 100 òèêîâ êàæäûé ðàç:
2512 if FFireTime > 0 then
2513 begin
2514 it := monsGrid.forEachInAABB(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
2515 for mit in it do
2516 if mit.UID <> FUID then
2517 mit.CatchFire(FFireAttacker, FFireTime);
2518 end;
2520 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
2521 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
2522 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
2523 begin
2524 FRemoved := True;
2525 if alive and (gLMSRespawn = LMS_RESPAWN_NONE) then
2526 begin
2527 Inc(gCoopMonstersKilled);
2528 if g_Game_IsNet then
2529 MH_SEND_GameStats;
2530 end;
2531 ActivateTriggers();
2532 Exit;
2533 end;
2535 oldvelx := FObj.Vel.X;
2537 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
2538 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
2539 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
2541 if FFireTime > 0 then
2542 begin
2543 if WordBool(st and MOVE_INWATER) then
2544 FFireTime := 0
2545 else
2546 begin
2547 OnFireFlame(1);
2548 FFireTime := FFireTime - 1;
2549 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2550 if FFirePainTime = 0 then
2551 begin
2552 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
2553 FFirePainTime := 18;
2554 end
2555 else
2556 FFirePainTime := FFirePainTime - 1;
2557 end;
2558 end;
2560 // Ìåðòâûé íè÷åãî íå äåëàåò:
2561 if (FState = MONSTATE_DEAD) then
2562 goto _end;
2564 // AI ìîíñòðîâ âûêëþ÷åí:
2565 if g_debug_MonsterOff then
2566 begin
2567 FSleep := 1;
2568 if FState <> MONSTATE_SLEEP then
2569 SetState(MONSTATE_SLEEP);
2570 end;
2572 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
2573 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
2574 case FMonsterType of
2575 MONSTER_FISH:
2576 if Random(4) = 0 then
2577 g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2578 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2579 MONSTER_ROBO, MONSTER_BARREL:
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 else
2583 g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
2584 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
2585 end;
2587 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
2588 if FMonsterType = MONSTER_BARREL then
2589 begin
2590 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
2591 (FAnim[FCurAnim, FDirection].Counter = 0) then
2592 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2593 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
2594 60, FUID);
2595 end;
2597 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
2598 if FMonsterType = MONSTER_SOUL then
2599 if WordBool(st and MOVE_HITAIR) then
2600 g_Obj_SetSpeed(@FObj, 16);
2602 if FAmmo < 0 then
2603 FAmmo := FAmmo + 1;
2605 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
2606 if FObj.Vel.Y < 0 then
2607 if WordBool(st and MOVE_INWATER) then
2608 FObj.Vel.Y := -4;
2610 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
2611 FTargetTime := FTargetTime + 1;
2613 // Ãèëüçû
2614 if FShellTimer > -1 then
2615 if FShellTimer = 0 then
2616 begin
2617 if FShellType = SHELL_SHELL then
2618 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2619 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2620 GameVelX, GameVelY-2, SHELL_SHELL)
2621 else if FShellType = SHELL_DBLSHELL then
2622 begin
2623 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2624 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2625 GameVelX-1, GameVelY-2, SHELL_SHELL);
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 end;
2630 FShellTimer := -1;
2631 end else Dec(FShellTimer);
2633 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
2634 if fall then
2635 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
2636 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
2637 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2638 FObj.Rect.Width, FObj.Rect.Height, 50) then
2639 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2640 (FObj.Accel.Y = 0) then
2641 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2643 case FState of
2644 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
2645 begin
2646 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
2647 if FPain >= MONSTERTABLE[FMonsterType].Pain then
2648 begin
2649 FPain := MONSTERTABLE[FMonsterType].Pain;
2650 if gSoundEffectsDF then PainSound();
2651 end;
2652 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
2653 PainSound();
2655 // Ñíèæàåì áîëü ñî âðåìåíåì:
2656 FPain := FPain - 5;
2658 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
2659 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
2660 begin
2661 FPain := 0;
2662 FAmmo := -9;
2663 SetState(MONSTATE_GO);
2664 end;
2665 end;
2667 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
2668 begin
2669 // Ñïèì:
2670 FSleep := FSleep + 1;
2672 // Ïðîñïàëè äîñòàòî÷íî:
2673 if FSleep >= 18 then
2674 FSleep := 0
2675 else // åùå ñïèì
2676 goto _end;
2678 // Íà èãðîêîâ èäóò òîëüêî îáû÷íûå ìîíñòðû, êèëëåðû è ìàíüÿêè
2679 if (FBehaviour = BH_NORMAL) or (FBehaviour = BH_KILLER) or (FBehaviour = BH_MANIAC) then
2680 // Åñëè åñòü èãðîê ðÿäîì, ïðîñûïàåìñÿ è èäåì ê íåìó:
2681 if (gPlayers <> nil) then
2682 for a := 0 to High(gPlayers) do
2683 if (gPlayers[a] <> nil) and (gPlayers[a].alive)
2684 and (not gPlayers[a].NoTarget) and (gPlayers[a].FPowerups[MR_INVIS] < gTime) then
2685 with gPlayers[a] do
2686 if g_Look(@FObj, @Obj, FDirection) then
2687 begin
2688 FTargetUID := gPlayers[a].UID;
2689 FTargetTime := 0;
2690 WakeUpSound();
2691 SetState(MONSTATE_GO);
2692 Break;
2693 end;
2695 // Íà ìîíñòðîâ òÿíåò ìàíüÿêîâ, ïîåõàâøèõ è êàííèáàëîâ
2696 if (FTargetUID = 0) and ((FBehaviour = BH_MANIAC)
2697 or (FBehaviour = BH_INSANE) or (FBehaviour = BH_CANNIBAL)) then
2698 // Åñëè åñòü ïîäõîäÿùèé ìîíñòð ðÿäîì:
2699 if gMonsters <> nil then
2700 for a := 0 to High(gMonsters) do
2701 if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
2702 (gMonsters[a].FUID <> FUID) then
2703 begin
2704 // Ìàíüÿêè íàïàäàþò íà âñåõ ìîíñòðîâ, êðîìå äðóçåé
2705 if (FBehaviour = BH_MANIAC) and
2706 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2707 Continue;
2708 // Ïîåõàâøèå òàêæå, íî ìîãóò îáîçëèòüñÿ íà áî÷êó
2709 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL) and
2710 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2711 Continue;
2712 // Êàííèáàëû íàïàäàþò íà ñåáå ïîäîáíûõ
2713 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
2714 Continue;
2715 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
2716 begin
2717 FTargetUID := gMonsters[a].UID;
2718 FTargetTime := 0;
2719 WakeUpSound();
2720 SetState(MONSTATE_GO);
2721 Break;
2722 end;
2723 end;
2724 end;
2726 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
2727 begin
2728 // Æäåì:
2729 FSleep := FSleep - 1;
2731 // Âûæäàëè äîñòàòî÷íî - èäåì:
2732 if FSleep < 0 then
2733 SetState(MONSTATE_GO);
2734 end;
2736 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
2737 begin
2738 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2739 if WordBool(st and MOVE_BLOCK) then
2740 begin
2741 Turn();
2742 FSleep := 40;
2743 SetState(MONSTATE_RUNOUT);
2745 goto _end;
2746 end;
2748 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
2749 if (FMonsterType = MONSTER_VILE) then
2750 if isCorpse(@FObj, False) <> -1 then
2751 begin
2752 FObj.Vel.X := 0;
2753 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
2755 goto _end;
2756 end;
2758 // Öåëü ïîãèáëà èëè äàâíî æäåì:
2759 if (not GetPos(FTargetUID, @o)) or (FTargetTime > MAX_ATM) then
2760 if not findNewPrey() then
2761 begin // Íîâûõ öåëåé íåò
2762 FTargetUID := 0;
2763 o.X := FObj.X+pt_x;
2764 o.Y := FObj.Y+pt_y;
2765 o.Vel.X := 0;
2766 o.Vel.Y := 0;
2767 o.Accel.X := 0;
2768 o.Accel.Y := 0;
2769 o.Rect := _Rect(0, 0, 0, 1);
2770 end
2771 else // Íîâàÿ öåëü åñòü - áåðåì åå êîîðäèíàòû
2772 GetPos(FTargetUID, @o);
2774 // Öåëü î÷åíü áëèçêî - ïèíàåì:
2775 if g_Obj_Collide(@FObj, @o) and (FTargetUID <> 0) then
2776 begin
2777 FTargetTime := 0;
2778 if (FMonsterType <> MONSTER_CYBER) or (Random(2) = 0) then
2779 begin
2780 if kick(@o) then
2781 goto _end;
2782 end;
2783 end;
2785 // Ðàññòîÿíèå äî öåëè:
2786 sx := o.X+o.Rect.X+(o.Rect.Width div 2)-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
2787 sy := o.Y+o.Rect.Y+(o.Rect.Height div 2)-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
2789 // Ïîâîðà÷èâàåìñÿ â ñòîðîíó öåëè:
2790 if sx > 0 then
2791 FDirection := TDirection.D_RIGHT
2792 else
2793 FDirection := TDirection.D_LEFT;
2795 // Åñëè ìîíñòð óìååò ñòðåëÿòü è åñòü ïî êîìó - ñòðåëÿåì:
2796 if canShoot(FMonsterType) and (FTargetUID <> 0) then
2797 if Abs(sx) > Abs(sy) then // óãîë âûñòðåëà óäîáíûé
2798 if shoot(@o, False) then
2799 goto _end;
2801 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
2802 if Abs(sx) < 40 then
2803 if FMonsterType <> MONSTER_FISH then
2804 begin
2805 FSleep := 15;
2806 SetState(MONSTATE_RUN);
2807 if Random(2) = 0 then
2808 FDirection := TDirection.D_LEFT
2809 else
2810 FDirection := TDirection.D_RIGHT;
2812 goto _end;
2813 end;
2815 // Óïåðëèñü â ñòåíó:
2816 if WordBool(st and MOVE_HITWALL) then
2817 begin
2818 if g_Triggers_PressR(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width,
2819 FObj.Rect.Height, FUID, ACTIVATE_MONSTERPRESS) <> nil then
2820 begin // Ñìîãëè íàæàòü êíîïêó - íåáîëüøîå îæèäàíèå
2821 FSleep := 4;
2822 SetState(MONSTATE_WAIT);
2824 goto _end;
2825 end;
2827 case FMonsterType of
2828 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
2829 else // Íå ëåòàþò:
2830 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2831 (FObj.Accel.Y = 0) then
2832 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
2833 // Ïðûæîê ÷åðåç ñòåíó:
2834 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2835 SetState(MONSTATE_CLIMB);
2836 end;
2837 end;
2839 goto _end;
2840 end;
2842 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
2843 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
2844 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
2845 begin
2846 if FMonsterType = MONSTER_FISH then
2847 begin // Ðûáà
2848 if not WordBool(st and MOVE_INWATER) then
2849 begin // Ðûáà âíå âîäû:
2850 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2851 begin // "Ñòîèò" òâåðäî
2852 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
2853 if FObj.Accel.Y = 0 then FObj.Vel.Y := -6;
2854 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
2855 end;
2857 // Ðûáå áîëüíî:
2858 SetState(MONSTATE_PAIN);
2859 FPain := FPain + 50;
2860 end
2861 else // Ðûáà â âîäå
2862 begin
2863 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2864 if Abs(sy) > 8 then
2865 FObj.Vel.Y := g_basic.Sign(sy)*4
2866 else
2867 FObj.Vel.Y := 0;
2869 // Ðûáà ïëûâåò ââåðõ:
2870 if FObj.Vel.Y < 0 then
2871 if not g_Obj_CollideLiquid(@FObj, 0, -16) then
2872 begin
2873 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
2874 FObj.Vel.Y := 0;
2875 // Ïëàâàåì òóäà-ñþäà:
2876 if Random(2) = 0 then
2877 FDirection := TDirection.D_LEFT
2878 else
2879 FDirection := TDirection.D_RIGHT;
2880 FSleep := 20;
2881 SetState(MONSTATE_RUN);
2882 end;
2883 end;
2884 end
2885 else // Ëåòàþùèå ìîíñòðû
2886 begin
2887 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2888 if Abs(sy) > 8 then
2889 FObj.Vel.Y := g_basic.Sign(sy)*4
2890 else
2891 FObj.Vel.Y := 0;
2892 end;
2893 end
2894 else // "Íàçåìíûå" ìîíñòðû
2895 begin
2896 // Âîçìîæíî, ïèíàåì êóñêè:
2897 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
2898 begin
2899 b := Abs(FObj.Vel.X);
2900 if b > 1 then b := b * (Random(8 div b) + 1);
2901 for a := 0 to High(gGibs) do
2902 begin
2903 if gGibs[a].alive and
2904 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2905 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
2906 begin
2907 // Ïèíàåì êóñêè
2908 if FObj.Vel.X < 0 then
2909 begin
2910 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
2911 end
2912 else
2913 begin
2914 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
2915 end;
2916 end;
2917 end;
2918 end;
2919 // Áîññû ìîãóò ïèíàòü òðóïû:
2920 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
2921 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
2922 begin
2923 b := Abs(FObj.Vel.X);
2924 if b > 1 then b := b * (Random(8 div b) + 1);
2925 for a := 0 to High(gCorpses) do
2926 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
2927 begin
2928 co := gCorpses[a].Obj;
2929 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2930 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
2931 // Ïèíàåì òðóïû
2932 if FObj.Vel.X < 0 then
2933 gCorpses[a].Damage(b*2, FUID, -b, Random(7)) // íàëåâî
2934 else
2935 gCorpses[a].Damage(b*2, FUID, b, Random(7)); // íàïðàâî
2936 end;
2937 end;
2938 // Åñëè öåëü âûñîêî, òî, âîçìîæíî, ïðûãàåì:
2939 if sy < -40 then
2940 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2941 // ñòîèò òâåðäî
2942 if (Random(4) = 0) and (FObj.Accel.Y = 0) then
2943 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2944 end;
2946 FSleep := FSleep + 1;
2948 // Èíîãäà ðû÷èì:
2949 if FSleep >= 8 then
2950 begin
2951 FSleep := 0;
2952 if Random(8) = 0 then
2953 ActionSound();
2954 end;
2956 // Áåæèì â âûáðàííóþ ñòîðîíó:
2957 if FDirection = TDirection.D_RIGHT then
2958 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2959 else
2960 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2962 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2963 if WordBool(st and MOVE_INWATER) then
2964 FObj.Vel.X := FObj.Vel.X div 2
2965 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2966 if FMonsterType = MONSTER_FISH then
2967 FObj.Vel.X := 0;
2968 end;
2970 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
2971 begin
2972 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2973 if WordBool(st and MOVE_BLOCK) then
2974 begin
2975 Turn();
2976 FSleep := 40;
2977 SetState(MONSTATE_RUNOUT);
2979 goto _end;
2980 end;
2982 FSleep := FSleep - 1;
2984 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
2985 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
2986 begin
2987 FSleep := 0;
2988 SetState(MONSTATE_GO);
2989 // Ñòåíà - èäåì îáðàòíî:
2990 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
2991 Turn();
2992 // Èíîãäà ðû÷èì:
2993 if Random(8) = 0 then
2994 ActionSound();
2995 end;
2997 // Áåæèì â âûáðàííóþ ñòîðîíó:
2998 if FDirection = TDirection.D_RIGHT then
2999 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3000 else
3001 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3003 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3004 if WordBool(st and MOVE_INWATER) then
3005 FObj.Vel.X := FObj.Vel.X div 2
3006 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3007 if FMonsterType = MONSTER_FISH then
3008 FObj.Vel.X := 0;
3009 end;
3011 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
3012 begin
3013 // Âûøëè èç ÁëîêÌîíà:
3014 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
3015 FSleep := 0;
3017 FSleep := FSleep - 1;
3019 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
3020 if FSleep <= -18 then
3021 begin
3022 FSleep := 0;
3023 SetState(MONSTATE_GO);
3024 // Ñòåíà/ÁëîêÌîí - èäåì îáðàòíî:
3025 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3026 Turn();
3027 // Èíîãäà ðû÷èì:
3028 if Random(8) = 0 then
3029 ActionSound();
3030 end;
3032 // Áåæèì â âûáðàííóþ ñòîðîíó:
3033 if FDirection = TDirection.D_RIGHT then
3034 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3035 else
3036 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3038 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3039 if WordBool(st and MOVE_INWATER) then
3040 FObj.Vel.X := FObj.Vel.X div 2
3041 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3042 if FMonsterType = MONSTER_FISH then
3043 FObj.Vel.X := 0;
3044 end;
3046 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
3047 begin
3048 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
3049 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
3050 (not WordBool(st and MOVE_HITWALL)) then
3051 begin
3052 FSleep := 0;
3053 SetState(MONSTATE_GO);
3055 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
3056 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3057 begin
3058 Turn();
3059 FSleep := 15;
3060 SetState(MONSTATE_RUN);
3061 end;
3062 end;
3064 // Áåæèì â âûáðàííóþ ñòîðîíó:
3065 if FDirection = TDirection.D_RIGHT then
3066 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3067 else
3068 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3070 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3071 if WordBool(st and MOVE_INWATER) then
3072 FObj.Vel.X := FObj.Vel.X div 2
3073 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3074 if FMonsterType = MONSTER_FISH then
3075 FObj.Vel.X := 0;
3076 end;
3078 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
3079 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
3080 begin
3081 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
3082 if FMonsterType = MONSTER_SOUL then
3083 begin
3084 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
3085 SetState(MONSTATE_GO);
3087 goto _end;
3088 end;
3090 // Çàìåäëÿåìñÿ ïðè àòàêå:
3091 if FMonsterType <> MONSTER_FISH then
3092 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3094 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
3095 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
3096 begin
3097 // Öåëü ïîãèáëà => èäåì äàëüøå:
3098 if not GetPos(FTargetUID, @o) then
3099 begin
3100 SetState(MONSTATE_GO);
3102 goto _end;
3103 end;
3105 // Öåëü íå âèäíî => èäåì äàëüøå:
3106 if not g_Look(@FObj, @o, FDirection) then
3107 begin
3108 SetState(MONSTATE_GO);
3110 goto _end;
3111 end;
3113 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
3114 if g_Obj_CollideWater(@o, 0, 0) then
3115 begin
3116 SetState(MONSTATE_GO);
3118 goto _end;
3119 end;
3121 // Æàðèì öåëü:
3122 tx := o.X+o.Rect.X+(o.Rect.Width div 2);
3123 ty := o.Y+o.Rect.Y+(o.Rect.Height div 2);
3124 g_Weapon_HitUID(FTargetUID, 2, FUID, HIT_SOME);
3125 end;
3126 end;
3127 end; // case FState of ...
3129 _end:
3131 // Ñîñòîÿíèå - Âîñêðåøåíèå:
3132 if FState = MONSTATE_REVIVE then
3133 if FAnim[FCurAnim, FDirection].Played then
3134 begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
3135 FAnim[FCurAnim, FDirection].Revert(False);
3136 SetState(MONSTATE_GO);
3137 end;
3139 // Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
3140 if vilefire <> nil then
3141 vilefire.Update();
3143 // Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
3144 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection] <> nil) then
3145 begin
3146 if FAnim[FCurAnim, FDirection].Played then
3147 begin // Óìåð:
3148 SetState(MONSTATE_DEAD);
3149 if g_Game_IsNet then MH_SEND_CoopStats();
3151 // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
3152 if FMonsterType in [MONSTER_PAIN, MONSTER_SOUL, MONSTER_BARREL] then
3153 FRemoved := True;
3154 end
3155 else if (FMonsterType = MONSTER_PAIN) and
3156 (FAnim[FCurAnim, FDirection].CurrentFrame =
3157 FAnim[FCurAnim, FDirection].TotalFrames div 2 + 1) and
3158 (FAnim[FCurAnim, FDirection].Counter = 0) then
3159 for i := 0 to 2 do // Pain_Elemental ïðè ñìåðòè âûïóñêàåò 3 Lost_Soul'à ïîñåðåäèíå àíèìàöèè:
3160 begin
3161 // FIXME: lostsouls may stuck in walls here
3162 mon := g_Monsters_Create(MONSTER_SOUL,
3163 FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)+RandomRange(-15,16),
3164 FObj.Y+FObj.Rect.Y+RandomRange(-7,8), FDirection);
3165 if mon <> nil then
3166 begin
3167 mon.SetState(MONSTATE_GO);
3168 mon.FNoRespawn := True;
3169 gTotalMonsters += 1;
3170 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3171 end;
3172 end;
3173 end;
3175 // Ñîâåðøåíèå àòàêè è ñòðåëüáû:
3176 if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
3177 if (FAnim[FCurAnim, FDirection] <> nil) then
3178 // Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
3179 if (FAnim[FCurAnim, FDirection].Played) then
3180 begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
3181 if FState = MONSTATE_ATTACK then
3182 begin // Ñîñòîÿíèå - Àòàêà
3183 // Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
3184 if FMonsterType <> MONSTER_SOUL then
3185 SetState(MONSTATE_GO);
3186 end
3187 else // Ñîñòîÿíèå - Ñòðåëüáà
3188 begin
3189 // Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
3190 if not FChainFire then
3191 SetState(MONSTATE_GO)
3192 else
3193 begin // Íàäî ñòðåëÿòü åùå
3194 FChainFire := False;
3195 // Ò.ê. ñîñòîÿíèå íå èçìåíèëîñü, è íóæåí
3196 // íîâûé öèêë îæèäàíèÿ çàâåðøåíèÿ àíèìàöèè:
3197 FAnim[FCurAnim, FDirection].Reset();
3198 end;
3199 end;
3201 FWaitAttackAnim := False;
3202 end
3204 else // Àíèìàöèÿ àòàêè åùå èäåò (èñêëþ÷åíèå - Lost_Soul):
3205 if (FMonsterType = MONSTER_SOUL) or
3206 ( (not FWaitAttackAnim) and
3207 (FAnim[FCurAnim, FDirection].CurrentFrame =
3208 (FAnim[FCurAnim, FDirection].TotalFrames div 2))
3209 ) then
3210 begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
3211 if FState = MONSTATE_ATTACK then
3212 begin // Ñîñòîÿíèå - Àòàêà
3213 // Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
3214 if FMonsterType = MONSTER_SOUL then
3215 FAnim[FCurAnim, FDirection].Reset();
3217 case FMonsterType of
3218 MONSTER_SOUL, MONSTER_IMP, MONSTER_DEMON:
3219 // Ãðûçåì ïåðâîãî ïîïàâøåãîñÿ:
3220 if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
3221 // Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
3222 if FMonsterType = MONSTER_SOUL then
3223 SetState(MONSTATE_GO);
3225 MONSTER_FISH:
3226 // Ðûáà êóñàåò ïåðâîãî ïîïàâøåãîñÿ ñî çâóêîì:
3227 if g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME) <> 0 then
3228 g_Sound_PlayExAt('SOUND_MONSTER_FISH_ATTACK', FObj.X, FObj.Y);
3230 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
3231 // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
3232 if FCurAnim = ANIM_ATTACK2 then
3233 begin
3234 o := FObj;
3235 o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
3236 if g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME) <> 0 then
3237 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_HIT', FObj.X, FObj.Y);
3238 end;
3240 MONSTER_VILE:
3241 // Êîëäóí ïûòàåòñÿ âîñêðåøàòü:
3242 if FCurAnim = ANIM_ATTACK2 then
3243 begin
3244 sx := isCorpse(@FObj, True);
3245 if sx <> -1 then
3246 begin // Íàøëè, êîãî âîñêðåñèòü
3247 gMonsters[sx].SetState(MONSTATE_REVIVE);
3248 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
3249 // Âîñêðåøàòü - ñåáå âðåäèòü:
3250 {g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
3251 end;
3252 end;
3253 end;
3254 end
3256 else // Ñîñòîÿíèå - Ñòðåëüáà
3257 begin
3258 // Âû÷èñëÿåì êîîðäèíàòû, îòêóäà âûëåòèò ïóëÿ:
3259 wx := MONSTER_ANIMTABLE[FMonsterType].wX;
3261 if FDirection = TDirection.D_LEFT then
3262 begin
3263 wx := MONSTER_ANIMTABLE[FMonsterType].wX-(MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2));
3264 wx := MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2)-wx;
3265 end; // Ýòî çíà÷èò: wx := hitX + (hitWidth / 2) - (wx - (hitX + (hitWidth / 2)))
3267 wx := FObj.X + wx;
3268 wy := FObj.Y + MONSTER_ANIMTABLE[FMonsterType].wY;
3270 // Ìîíñòð íå ìîæåò öåëèòüñÿ â îáúåêò çà ñïèíîé, ñòðåëÿÿ âëåâî:
3271 if (FDirection = TDirection.D_LEFT) and (tx > wx) then
3272 begin
3273 tx := wx - 32;
3274 ty := wy + Random(11) - 5;
3275 end;
3276 // È àíàëîãè÷íî, ñòðåëÿÿ âïðàâî:
3277 if (FDirection = TDirection.D_RIGHT) and (tx < wx) then
3278 begin
3279 tx := wx + 32;
3280 ty := wy + Random(11) - 5;
3281 end;
3283 // Äåëàåì âûñòðåë íóæíûì îðóæèåì:
3284 case FMonsterType of
3285 MONSTER_IMP:
3286 g_Weapon_ball1(wx, wy, tx, ty, FUID);
3287 MONSTER_ZOMBY:
3288 begin
3289 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3290 g_Weapon_gun(wx, wy, tx, ty, 1, 3, FUID, True);
3291 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3292 end;
3293 MONSTER_SERG:
3294 begin
3295 g_Weapon_shotgun(wx, wy, tx, ty, FUID);
3296 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3297 FShellTimer := 10;
3298 FShellType := SHELL_SHELL;
3299 end;
3300 MONSTER_MAN:
3301 begin
3302 g_Weapon_dshotgun(wx, wy, tx, ty, FUID);
3303 FShellTimer := 13;
3304 FShellType := SHELL_DBLSHELL;
3305 FAmmo := -36;
3306 end;
3307 MONSTER_CYBER:
3308 begin
3309 g_Weapon_rocket(wx, wy, tx, ty, FUID);
3310 // MH_SEND_MonsterAttack(FUID, wx, wy, tx, ty);
3311 end;
3312 MONSTER_SKEL:
3313 g_Weapon_revf(wx, wy, tx, ty, FUID, FTargetUID);
3314 MONSTER_CGUN:
3315 begin
3316 g_Weapon_mgun(wx, wy, tx, ty, FUID);
3317 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3318 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3319 end;
3320 MONSTER_SPIDER:
3321 begin
3322 g_Weapon_mgun(wx, wy, tx, ty, FUID);
3323 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3324 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
3325 end;
3326 MONSTER_BSP:
3327 g_Weapon_aplasma(wx, wy, tx, ty, FUID);
3328 MONSTER_ROBO:
3329 g_Weapon_plasma(wx, wy, tx, ty, FUID);
3330 MONSTER_MANCUB:
3331 g_Weapon_manfire(wx, wy, tx, ty, FUID);
3332 MONSTER_BARON, MONSTER_KNIGHT:
3333 g_Weapon_ball7(wx, wy, tx, ty, FUID);
3334 MONSTER_CACO:
3335 g_Weapon_ball2(wx, wy, tx, ty, FUID);
3336 MONSTER_PAIN:
3337 begin // Ñîçäàåì Lost_Soul:
3338 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+(FObj.Rect.Width div 2),
3339 FObj.Y+FObj.Rect.Y, FDirection);
3341 if mon <> nil then
3342 begin // Öåëü - öåëü Pain_Elemental'à. Ëåòèì ê íåé:
3343 mon.FTargetUID := FTargetUID;
3344 GetPos(FTargetUID, @o);
3345 mon.FTargetTime := 0;
3346 mon.FNoRespawn := True;
3347 mon.SetState(MONSTATE_GO);
3348 mon.shoot(@o, True);
3349 Inc(gTotalMonsters);
3351 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3352 end;
3353 end;
3354 end;
3356 if FMonsterType <> MONSTER_PAIN then
3357 if g_Game_IsNet then
3358 MH_SEND_MonsterShot(FUID, wx, wy, tx, ty);
3360 // Ñêîðîñòðåëüíûå ìîíñòðû:
3361 if (FMonsterType = MONSTER_CGUN) or
3362 (FMonsterType = MONSTER_SPIDER) or
3363 (FMonsterType = MONSTER_BSP) or
3364 (FMonsterType = MONSTER_MANCUB) or
3365 (FMonsterType = MONSTER_ROBO) then
3366 if not GetPos(FTargetUID, @o) then
3367 // Öåëü ìåðòâà - èùåì íîâóþ:
3368 findNewPrey()
3369 else // Öåëü æèâà - ïðîäîëæàåì ñòðåëÿòü:
3370 if shoot(@o, False) then
3371 FChainFire := True;
3372 end;
3374 // Àòàêà òîëüêî 1 ðàç çà àíèìàöèþ àòàêè:
3375 FWaitAttackAnim := True;
3376 end;
3378 // Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
3379 if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
3380 case FState of
3381 MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
3382 // Çâóêè ïðè ïåðåäâèæåíèè:
3383 case FMonsterType of
3384 MONSTER_CYBER:
3385 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3386 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3387 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_WALK', FObj.X, FObj.Y);
3388 MONSTER_SPIDER:
3389 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3390 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3391 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_WALK', FObj.X, FObj.Y);
3392 MONSTER_BSP:
3393 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3394 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3395 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3396 MONSTER_ROBO:
3397 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3398 (FAnim[FCurAnim, FDirection].CurrentFrame = 5) then
3399 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3400 end;
3401 end;
3403 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
3404 not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
3405 FObj.Vel.X := oldvelx;
3407 // Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
3408 if FAnim[FCurAnim, FDirection] <> nil then
3409 FAnim[FCurAnim, FDirection].Update();
3410 end;
3412 procedure TMonster.SetDeadAnim;
3413 begin
3414 if FAnim <> nil then
3415 FAnim[FCurAnim, FDirection].CurrentFrame := FAnim[FCurAnim, FDirection].TotalFrames - 1;
3416 end;
3418 procedure TMonster.RevertAnim(R: Boolean = True);
3419 begin
3420 if FAnim <> nil then
3421 if FAnim[FCurAnim, FDirection].IsReverse <> R then
3422 FAnim[FCurAnim, FDirection].Revert(R);
3423 end;
3425 function TMonster.AnimIsReverse: Boolean;
3426 begin
3427 if FAnim <> nil then
3428 Result := FAnim[FCurAnim, FDirection].IsReverse
3429 else
3430 Result := False;
3431 end;
3433 procedure TMonster.ClientUpdate();
3434 var
3435 a, b, sx, sy, oldvelx: Integer;
3436 st: Word;
3437 o, co: TObj;
3438 fall: Boolean;
3439 label
3440 _end;
3441 begin
3442 sx := 0; // SHUT UP COMPILER
3443 sy := 0;
3444 fall := True;
3446 // Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
3447 if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
3449 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
3450 if FMonsterType = MONSTER_FISH then
3451 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3452 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
3453 fall := False;
3455 // Ëåòàþùèå ìîíòñðû:
3456 if ((FMonsterType = MONSTER_SOUL) or
3457 (FMonsterType = MONSTER_PAIN) or
3458 (FMonsterType = MONSTER_CACO)) and
3459 (FState <> MONSTATE_DIE) and
3460 (FState <> MONSTATE_DEAD) then
3461 fall := False;
3463 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
3464 if gTime mod (GAME_TICK*2) <> 0 then
3465 begin
3466 g_Obj_Move(@FObj, fall, True, True);
3467 positionChanged(); // this updates spatial accelerators
3468 Exit;
3469 end;
3471 if FPainTicks > 0 then
3472 Dec(FPainTicks)
3473 else
3474 FPainSound := False;
3476 // Äâèãàåìñÿ:
3477 st := g_Obj_Move(@FObj, fall, True, True);
3478 positionChanged(); // this updates spatial accelerators
3480 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
3481 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
3482 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
3483 begin
3484 FRemoved := True;
3485 Exit;
3486 end;
3488 oldvelx := FObj.Vel.X;
3490 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
3491 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
3492 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3494 if FFireTime > 0 then
3495 begin
3496 if WordBool(st and MOVE_INWATER) then
3497 FFireTime := 0
3498 else
3499 begin
3500 OnFireFlame(1);
3501 FFireTime := FFireTime - 1;
3502 end;
3503 end;
3505 // Ìåðòâûé íè÷åãî íå äåëàåò:
3506 if (FState = MONSTATE_DEAD) then
3507 goto _end;
3509 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
3510 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
3511 case FMonsterType of
3512 MONSTER_FISH:
3513 if Random(4) = 0 then
3514 g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
3515 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
3516 MONSTER_ROBO, MONSTER_BARREL:
3517 g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
3518 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
3519 else
3520 g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
3521 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
3522 end;
3524 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
3525 if FMonsterType = MONSTER_BARREL then
3526 begin
3527 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
3528 (FAnim[FCurAnim, FDirection].Counter = 0) then
3529 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3530 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
3531 60, FUID);
3532 end;
3534 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
3535 if FMonsterType = MONSTER_SOUL then
3536 if WordBool(st and MOVE_HITAIR) then
3537 g_Obj_SetSpeed(@FObj, 16);
3539 if FAmmo < 0 then
3540 FAmmo := FAmmo + 1;
3542 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
3543 if FObj.Vel.Y < 0 then
3544 if WordBool(st and MOVE_INWATER) then
3545 FObj.Vel.Y := -4;
3547 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
3548 FTargetTime := FTargetTime + 1;
3550 if FShellTimer > -1 then
3551 if FShellTimer = 0 then
3552 begin
3553 if FShellType = SHELL_SHELL then
3554 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3555 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3556 GameVelX, GameVelY-2, SHELL_SHELL)
3557 else if FShellType = SHELL_DBLSHELL then
3558 begin
3559 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3560 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3561 GameVelX-1, GameVelY-2, SHELL_SHELL);
3562 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3563 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3564 GameVelX+1, GameVelY-2, SHELL_SHELL);
3565 end;
3566 FShellTimer := -1;
3567 end else Dec(FShellTimer);
3569 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
3570 if fall then
3571 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
3572 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
3573 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3574 FObj.Rect.Width, FObj.Rect.Height, 50) then
3575 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
3576 (FObj.Accel.Y = 0) then
3577 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
3579 case FState of
3580 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
3581 begin
3582 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
3583 if FPain >= MONSTERTABLE[FMonsterType].Pain then
3584 begin
3585 FPain := MONSTERTABLE[FMonsterType].Pain;
3586 if gSoundEffectsDF then PainSound();
3587 end;
3588 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
3589 PainSound();
3591 // Ñíèæàåì áîëü ñî âðåìåíåì:
3592 FPain := FPain - 5;
3594 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
3595 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
3596 begin
3597 SetState(MONSTATE_GO);
3598 FPain := 0;
3599 end;
3600 end;
3602 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
3603 begin
3604 // Ñïèì:
3605 FSleep := FSleep + 1;
3607 // Ïðîñïàëè äîñòàòî÷íî:
3608 if FSleep >= 18 then
3609 FSleep := 0
3610 else // åùå ñïèì
3611 goto _end;
3612 end;
3614 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
3615 begin
3616 // Æäåì:
3617 FSleep := FSleep - 1;
3618 end;
3620 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
3621 begin
3622 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
3623 if WordBool(st and MOVE_BLOCK) then
3624 begin
3625 Turn();
3626 FSleep := 40;
3627 SetState(MONSTATE_RUNOUT);
3629 goto _end;
3630 end;
3632 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
3633 if (FMonsterType = MONSTER_VILE) then
3634 if isCorpse(@FObj, False) <> -1 then
3635 begin
3636 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
3637 FObj.Vel.X := 0;
3639 goto _end;
3640 end;
3642 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
3643 if Abs(sx) < 40 then
3644 if FMonsterType <> MONSTER_FISH then
3645 begin
3646 SetState(MONSTATE_RUN);
3647 FSleep := 15;
3649 goto _end;
3650 end;
3652 // Óïåðëèñü â ñòåíó:
3653 if WordBool(st and MOVE_HITWALL) then
3654 begin
3655 case FMonsterType of
3656 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
3657 else // Íå ëåòàþò:
3658 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
3659 (FObj.Accel.Y = 0) then
3660 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
3661 // Ïðûæîê ÷åðåç ñòåíó:
3662 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
3663 SetState(MONSTATE_CLIMB);
3664 end;
3665 end;
3667 goto _end;
3668 end;
3670 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
3671 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
3672 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
3673 begin
3674 if FMonsterType = MONSTER_FISH then
3675 begin // Ðûáà
3676 if not WordBool(st and MOVE_INWATER) then
3677 begin // Ðûáà âíå âîäû:
3678 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
3679 begin // "Ñòîèò" òâåðäî
3680 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
3681 if FObj.Accel.Y = 0 then
3682 FObj.Vel.Y := -6;
3683 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
3684 end;
3686 // Ðûáå áîëüíî:
3687 SetState(MONSTATE_PAIN);
3688 FPain := FPain + 50;
3689 end
3690 else // Ðûáà â âîäå
3691 begin
3692 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
3693 if Abs(sy) > 8 then
3694 FObj.Vel.Y := g_basic.Sign(sy)*4
3695 else
3696 FObj.Vel.Y := 0;
3698 // Ðûáà ïëûâåò ââåðõ:
3699 if FObj.Vel.Y < 0 then
3700 if not g_Obj_CollideLiquid(@FObj, 0, -16) then
3701 begin
3702 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
3703 FObj.Vel.Y := 0;
3704 // Ïëàâàåì òóäà-ñþäà:
3705 SetState(MONSTATE_RUN);
3706 FSleep := 20;
3707 end;
3708 end;
3709 end
3710 else // Ëåòàþùèå ìîíñòðû
3711 begin
3712 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
3713 if Abs(sy) > 8 then
3714 FObj.Vel.Y := g_basic.Sign(sy)*4
3715 else
3716 FObj.Vel.Y := 0;
3717 end;
3718 end
3719 else // "Íàçåìíûå" ìîíñòðû
3720 begin
3721 // Âîçìîæíî, ïèíàåì êóñêè:
3722 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
3723 begin
3724 b := Abs(FObj.Vel.X);
3725 if b > 1 then b := b * (Random(8 div b) + 1);
3726 for a := 0 to High(gGibs) do
3727 begin
3728 if gGibs[a].alive and
3729 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
3730 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
3731 begin
3732 // Ïèíàåì êóñêè
3733 if FObj.Vel.X < 0 then
3734 begin
3735 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
3736 end
3737 else
3738 begin
3739 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
3740 end;
3741 positionChanged(); // this updates spatial accelerators
3742 end;
3743 end;
3744 end;
3745 // Áîññû ìîãóò ïèíàòü òðóïû:
3746 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
3747 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
3748 begin
3749 b := Abs(FObj.Vel.X);
3750 if b > 1 then b := b * (Random(8 div b) + 1);
3751 for a := 0 to High(gCorpses) do
3752 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
3753 begin
3754 co := gCorpses[a].Obj;
3755 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
3756 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
3757 // Ïèíàåì òðóïû
3758 if FObj.Vel.X < 0 then
3759 gCorpses[a].Damage(b*2, FUID, -b, Random(7)) // íàëåâî
3760 else
3761 gCorpses[a].Damage(b*2, FUID, b, Random(7)); // íàïðàâî
3762 end;
3763 end;
3764 end;
3766 FSleep := FSleep + 1;
3768 // Èíîãäà ðû÷èì:
3769 if FSleep >= 8 then
3770 begin
3771 FSleep := 0;
3772 if Random(8) = 0 then
3773 ActionSound();
3774 end;
3776 // Áåæèì â âûáðàííóþ ñòîðîíó:
3777 if FDirection = TDirection.D_RIGHT then
3778 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3779 else
3780 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3782 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3783 if WordBool(st and MOVE_INWATER) then
3784 FObj.Vel.X := FObj.Vel.X div 2
3785 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3786 if FMonsterType = MONSTER_FISH then
3787 FObj.Vel.X := 0;
3788 end;
3790 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
3791 begin
3792 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
3793 if WordBool(st and MOVE_BLOCK) then
3794 begin
3795 SetState(MONSTATE_RUNOUT);
3796 FSleep := 40;
3798 goto _end;
3799 end;
3801 FSleep := FSleep - 1;
3803 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
3804 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
3805 begin
3806 SetState(MONSTATE_GO);
3807 FSleep := 0;
3809 // Èíîãäà ðû÷èì:
3810 if Random(8) = 0 then
3811 ActionSound();
3812 end;
3814 // Áåæèì â âûáðàííóþ ñòîðîíó:
3815 if FDirection = TDirection.D_RIGHT then
3816 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3817 else
3818 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3820 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3821 if WordBool(st and MOVE_INWATER) then
3822 FObj.Vel.X := FObj.Vel.X div 2
3823 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3824 if FMonsterType = MONSTER_FISH then
3825 FObj.Vel.X := 0;
3826 end;
3828 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
3829 begin
3830 // Âûøëè èç ÁëîêÌîíà:
3831 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
3832 FSleep := 0;
3834 FSleep := FSleep - 1;
3836 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
3837 if FSleep <= -18 then
3838 begin
3839 SetState(MONSTATE_GO);
3840 FSleep := 0;
3842 // Èíîãäà ðû÷èì:
3843 if Random(8) = 0 then
3844 ActionSound();
3845 end;
3847 // Áåæèì â âûáðàííóþ ñòîðîíó:
3848 if FDirection = TDirection.D_RIGHT then
3849 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3850 else
3851 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3853 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3854 if WordBool(st and MOVE_INWATER) then
3855 FObj.Vel.X := FObj.Vel.X div 2
3856 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3857 if FMonsterType = MONSTER_FISH then
3858 FObj.Vel.X := 0;
3859 end;
3861 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
3862 begin
3863 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
3864 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
3865 (not WordBool(st and MOVE_HITWALL)) then
3866 begin
3867 SetState(MONSTATE_GO);
3868 FSleep := 0;
3870 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
3871 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3872 begin
3873 SetState(MONSTATE_RUN);
3874 FSleep := 15;
3875 end;
3876 end;
3878 // Áåæèì â âûáðàííóþ ñòîðîíó:
3879 if FDirection = TDirection.D_RIGHT then
3880 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3881 else
3882 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3884 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3885 if WordBool(st and MOVE_INWATER) then
3886 FObj.Vel.X := FObj.Vel.X div 2
3887 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3888 if FMonsterType = MONSTER_FISH then
3889 FObj.Vel.X := 0;
3890 end;
3892 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
3893 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
3894 begin
3895 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
3896 if FMonsterType = MONSTER_SOUL then
3897 begin
3898 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
3899 SetState(MONSTATE_GO);
3901 goto _end;
3902 end;
3904 // Çàìåäëÿåìñÿ ïðè àòàêå:
3905 if FMonsterType <> MONSTER_FISH then
3906 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3908 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
3909 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
3910 begin
3911 // Öåëü ïîãèáëà => èäåì äàëüøå:
3912 if not GetPos(FTargetUID, @o) then
3913 begin
3914 SetState(MONSTATE_GO);
3916 goto _end;
3917 end;
3919 // Öåëü íå âèäíî => èäåì äàëüøå:
3920 if not g_Look(@FObj, @o, FDirection) then
3921 begin
3922 SetState(MONSTATE_GO);
3924 goto _end;
3925 end;
3927 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
3928 if g_Obj_CollideWater(@o, 0, 0) then
3929 begin
3930 SetState(MONSTATE_GO);
3932 goto _end;
3933 end;
3934 end;
3935 end;
3936 end; // case FState of ...
3938 _end:
3940 // Ñîñòîÿíèå - Âîñêðåøåíèå:
3941 if FState = MONSTATE_REVIVE then
3942 if FAnim[FCurAnim, FDirection].Played then
3943 begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
3944 FAnim[FCurAnim, FDirection].Revert(False);
3945 SetState(MONSTATE_GO);
3946 end;
3948 // Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
3949 if vilefire <> nil then
3950 vilefire.Update();
3952 // Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
3953 if (FState = MONSTATE_DIE) and
3954 (FAnim[FCurAnim, FDirection] <> nil) and
3955 (FAnim[FCurAnim, FDirection].Played) then
3956 begin
3957 // Óìåð:
3958 SetState(MONSTATE_DEAD);
3960 // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
3961 if (FMonsterType = MONSTER_PAIN) or
3962 (FMonsterType = MONSTER_SOUL) or
3963 (FMonsterType = MONSTER_BARREL) then
3964 FRemoved := True
3965 else
3966 FAnim[FCurAnim, FDirection].CurrentFrame := FAnim[FCurAnim, FDirection].TotalFrames - 1;
3967 end;
3969 // Ñîâåðøåíèå àòàêè è ñòðåëüáû:
3970 if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
3971 if (FAnim[FCurAnim, FDirection] <> nil) then
3972 // Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
3973 if (FAnim[FCurAnim, FDirection].Played) then
3974 begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
3975 if FState = MONSTATE_ATTACK then
3976 begin // Ñîñòîÿíèå - Àòàêà
3977 // Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
3978 if FMonsterType <> MONSTER_SOUL then
3979 SetState(MONSTATE_GO);
3980 end
3981 else // Ñîñòîÿíèå - Ñòðåëüáà
3982 begin
3983 // Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
3984 if not FChainFire then
3985 SetState(MONSTATE_GO)
3986 else
3987 begin // Íàäî ñòðåëÿòü åùå
3988 FChainFire := False;
3989 // Ò.ê. ñîñòîÿíèå íå èçìåíèëîñü, è íóæåí
3990 // íîâûé öèêë îæèäàíèÿ çàâåðøåíèÿ àíèìàöèè:
3991 FAnim[FCurAnim, FDirection].Reset();
3992 end;
3993 end;
3995 FWaitAttackAnim := False;
3996 end
3998 else // Àíèìàöèÿ àòàêè åùå èäåò (èñêëþ÷åíèå - Lost_Soul):
3999 if (FMonsterType = MONSTER_SOUL) or
4000 ( (not FWaitAttackAnim) and
4001 (FAnim[FCurAnim, FDirection].CurrentFrame =
4002 (FAnim[FCurAnim, FDirection].TotalFrames div 2))
4003 ) then
4004 begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
4005 if FState = MONSTATE_ATTACK then
4006 begin // Ñîñòîÿíèå - Àòàêà
4007 // Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
4008 if FMonsterType = MONSTER_SOUL then
4009 FAnim[FCurAnim, FDirection].Reset();
4011 case FMonsterType of
4012 MONSTER_SOUL, MONSTER_IMP, MONSTER_DEMON:
4013 // Ãðûçåì ïåðâîãî ïîïàâøåãîñÿ:
4014 if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
4015 // Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
4016 if FMonsterType = MONSTER_SOUL then
4017 SetState(MONSTATE_GO);
4019 MONSTER_FISH:
4020 g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME);
4022 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
4023 // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
4024 if FCurAnim = ANIM_ATTACK2 then
4025 begin
4026 o := FObj;
4027 o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
4028 g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME);
4029 end;
4031 MONSTER_VILE:
4032 // Êîëäóí ïûòàåòñÿ âîñêðåøàòü:
4033 if FCurAnim = ANIM_ATTACK2 then
4034 begin
4035 sx := isCorpse(@FObj, True);
4036 if sx <> -1 then
4037 begin // Íàøëè, êîãî âîñêðåñèòü
4038 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
4039 // Âîñêðåøàòü - ñåáå âðåäèòü:
4040 {g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
4041 end;
4042 end;
4043 end;
4044 end
4046 else // Ñîñòîÿíèå - Ñòðåëüáà
4047 begin
4048 // Ñêîðîñòðåëüíûå ìîíñòðû:
4049 if (FMonsterType = MONSTER_CGUN) or
4050 (FMonsterType = MONSTER_SPIDER) or
4051 (FMonsterType = MONSTER_BSP) or
4052 (FMonsterType = MONSTER_MANCUB) or
4053 (FMonsterType = MONSTER_ROBO) then
4054 if not GetPos(FTargetUID, @o) then
4055 // Öåëü ìåðòâà - èùåì íîâóþ:
4056 findNewPrey()
4057 else // Öåëü æèâà - ïðîäîëæàåì ñòðåëÿòü:
4058 if shoot(@o, False) then
4059 FChainFire := True;
4060 end;
4062 // Àòàêà òîëüêî 1 ðàç çà àíèìàöèþ àòàêè:
4063 FWaitAttackAnim := True;
4064 end;
4066 // Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
4067 if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
4068 case FState of
4069 MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
4070 // Çâóêè ïðè ïåðåäâèæåíèè:
4071 case FMonsterType of
4072 MONSTER_CYBER:
4073 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4074 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4075 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_WALK', FObj.X, FObj.Y);
4076 MONSTER_SPIDER:
4077 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4078 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4079 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_WALK', FObj.X, FObj.Y);
4080 MONSTER_BSP:
4081 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4082 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4083 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
4084 MONSTER_ROBO:
4085 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4086 (FAnim[FCurAnim, FDirection].CurrentFrame = 5) then
4087 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
4088 end;
4089 end;
4091 // Êîñòûëü äëÿ ïîòîêîâ
4092 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
4093 not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
4094 FObj.Vel.X := oldvelx;
4096 // Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
4097 if FAnim[FCurAnim, FDirection] <> nil then
4098 FAnim[FCurAnim, FDirection].Update();
4099 end;
4101 procedure TMonster.ClientAttack(wx, wy, atx, aty: Integer);
4102 begin
4103 case FMonsterType of
4104 MONSTER_ZOMBY:
4105 begin
4106 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
4107 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
4108 end;
4109 MONSTER_SERG:
4110 begin
4111 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
4112 FShellTimer := 10;
4113 FShellType := SHELL_SHELL;
4114 end;
4115 MONSTER_MAN:
4116 begin
4117 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', wx, wy);
4118 FShellTimer := 13;
4119 FShellType := SHELL_DBLSHELL;
4120 end;
4121 MONSTER_CGUN, MONSTER_SPIDER:
4122 begin
4123 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
4124 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
4125 end;
4126 MONSTER_IMP:
4127 g_Weapon_ball1(wx, wy, atx, aty, FUID);
4128 MONSTER_CYBER:
4129 g_Weapon_rocket(wx, wy, atx, aty, FUID);
4130 MONSTER_SKEL:
4131 g_Weapon_revf(wx, wy, atx, aty, FUID, FTargetUID);
4132 MONSTER_BSP:
4133 g_Weapon_aplasma(wx, wy, atx, aty, FUID);
4134 MONSTER_ROBO:
4135 g_Weapon_plasma(wx, wy, atx, aty, FUID);
4136 MONSTER_MANCUB:
4137 g_Weapon_manfire(wx, wy, atx, aty, FUID);
4138 MONSTER_BARON, MONSTER_KNIGHT:
4139 g_Weapon_ball7(wx, wy, atx, aty, FUID);
4140 MONSTER_CACO:
4141 g_Weapon_ball2(wx, wy, atx, aty, FUID);
4142 end;
4143 end;
4145 procedure TMonster.Turn();
4146 begin
4147 // Ðàçâîðà÷èâàåìñÿ:
4148 if FDirection = TDirection.D_LEFT then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
4150 // Áåæèì â âûáðàííóþ ñòîðîíó:
4151 if FDirection = TDirection.D_RIGHT then
4152 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
4153 else
4154 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
4155 end;
4157 function TMonster.findNewPrey(): Boolean;
4158 var
4159 a: DWORD;
4160 l, l2: Integer;
4161 PlayersSee, MonstersSee: Array of DWORD;
4162 PlayerNear, MonsterNear: Integer;
4163 begin
4164 Result := False;
4165 SetLength(MonstersSee, 0);
4166 SetLength(PlayersSee, 0);
4168 FTargetUID := 0;
4169 l := 32000;
4170 PlayerNear := -1;
4171 MonsterNear := -1;
4173 // Ïîåõàâøèå, êàííèáàëû, è äîáðûå èãðîêîâ íå òðîãàþò
4174 if (gPlayers <> nil) and (FBehaviour <> BH_INSANE) and
4175 (FBehaviour <> BH_CANNIBAL) and (FBehaviour <> BH_GOOD) then
4176 for a := 0 to High(gPlayers) do
4177 if (gPlayers[a] <> nil) and (gPlayers[a].alive)
4178 and (not gPlayers[a].NoTarget) and (gPlayers[a].FPowerups[MR_INVIS] < gTime) then
4179 begin
4180 if g_Look(@FObj, @gPlayers[a].Obj, FDirection) then
4181 begin
4182 SetLength(PlayersSee, Length(PlayersSee) + 1);
4183 PlayersSee[High(PlayersSee)] := a;
4184 end;
4185 l2 := Abs(gPlayers[a].GameX-FObj.X)+
4186 Abs(gPlayers[a].GameY-FObj.Y);
4187 if l2 < l then
4188 begin
4189 l := l2;
4190 PlayerNear := Integer(a);
4191 end;
4192 end;
4194 // Êèëëåðû è äîáðûå íå òðîãàþò ìîíñòðîâ
4195 if (gMonsters <> nil) and (FBehaviour <> BH_KILLER) and (FBehaviour <> BH_GOOD) then
4196 for a := 0 to High(gMonsters) do
4197 if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
4198 (gMonsters[a].FUID <> FUID) then
4199 begin
4200 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
4201 Continue; // Êàííèáàëû àòàêóþò òîëüêî ñîðîäè÷åé
4202 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL)
4203 and (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
4204 Continue; // Ïîåõàâøèå íå òðîãàþò äðóçåé, íî èì íå íðàâÿòñÿ áî÷êè
4205 if ((FBehaviour = BH_NORMAL) or (FBehaviour = BH_MANIAC))
4206 and (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
4207 Continue; // Îñòàâøèåñÿ òèïû, êðîìå êàííèáàëîâ, íå òðîãàþò ñâîèõ äðóçåé
4209 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
4210 begin
4211 SetLength(MonstersSee, Length(MonstersSee) + 1);
4212 MonstersSee[High(MonstersSee)] := a;
4213 end;
4214 l2 := Abs(gMonsters[a].FObj.X-FObj.X)+
4215 Abs(gMonsters[a].FObj.Y-FObj.Y);
4216 if l2 < l then
4217 begin
4218 l := l2;
4219 MonsterNear := Integer(a);
4220 end;
4221 end;
4223 case FBehaviour of
4224 BH_NORMAL, BH_KILLER:
4225 begin
4226 // Îáû÷íûé è êèëëåð ñíà÷àëà èùóò èãðîêîâ â ïîëå çðåíèÿ
4227 if (FTargetUID = 0) and (Length(PlayersSee) > 0) then
4228 begin
4229 a := PlayersSee[Random(Length(PlayersSee))];
4230 FTargetUID := gPlayers[a].UID;
4231 end;
4232 // Çàòåì ïîáëèçîñòè
4233 if (FTargetUID = 0) and (PlayerNear > -1) then
4234 begin
4235 a := PlayerNear;
4236 FTargetUID := gPlayers[a].UID;
4237 end;
4238 // Ïîòîì îáû÷íûå èùóò ìîíñòðîâ â ïîëå çðåíèÿ
4239 if (FTargetUID = 0) and (Length(MonstersSee) > 0) then
4240 begin
4241 a := MonstersSee[Random(Length(MonstersSee))];
4242 FTargetUID := gMonsters[a].UID;
4243 end;
4244 // Çàòåì ïîáëèçîñòè
4245 if (FTargetUID = 0) and (MonsterNear > -1) then
4246 begin
4247 a := MonsterNear;
4248 FTargetUID := gMonsters[a].UID;
4249 end;
4250 end;
4251 BH_MANIAC, BH_INSANE, BH_CANNIBAL:
4252 begin
4253 // Ìàíüÿêè, ïîåõàâøèå è êàííèáàëû ñíà÷àëà èñòðåáëÿþò âñ¸ â ïîëå çðåíèÿ
4254 if (FTargetUID = 0) and (Length(PlayersSee) > 0) then
4255 begin
4256 a := PlayersSee[Random(Length(PlayersSee))];
4257 FTargetUID := gPlayers[a].UID;
4258 end;
4259 if (FTargetUID = 0) and (Length(MonstersSee) > 0) then
4260 begin
4261 a := MonstersSee[Random(Length(MonstersSee))];
4262 FTargetUID := gMonsters[a].UID;
4263 end;
4264 // Çàòåì èùóò êîãî-òî ïîáëèçîñòè
4265 if (FTargetUID = 0) and (PlayerNear > -1) then
4266 begin
4267 a := PlayerNear;
4268 FTargetUID := gPlayers[a].UID;
4269 end;
4270 if (FTargetUID = 0) and (MonsterNear > -1) then
4271 begin
4272 a := MonsterNear;
4273 FTargetUID := gMonsters[a].UID;
4274 end;
4275 end;
4276 end;
4278 // Åñëè è ìîíñòðîâ íåò - íà÷èíàåì æäàòü öåëü:
4279 if FTargetUID = 0 then
4280 begin
4281 // Ïîåõàâøèé ïûòàåòñÿ ñàìîóáèòüñÿ
4282 if FBehaviour = BH_INSANE then
4283 FTargetUID := FUID
4284 else
4285 FTargetTime := MAX_ATM;
4286 end
4287 else
4288 begin // Öåëü íàøëè
4289 FTargetTime := 0;
4290 Result := True;
4291 end;
4292 end;
4294 function TMonster.kick(o: PObj): Boolean;
4295 begin
4296 Result := False;
4298 case FMonsterType of
4299 MONSTER_FISH:
4300 begin
4301 SetState(MONSTATE_ATTACK);
4302 Result := True;
4303 end;
4304 MONSTER_DEMON:
4305 begin
4306 SetState(MONSTATE_ATTACK);
4307 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ATTACK', FObj.X, FObj.Y);
4308 Result := True;
4309 end;
4310 MONSTER_IMP:
4311 begin
4312 SetState(MONSTATE_ATTACK);
4313 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ATTACK', FObj.X, FObj.Y);
4314 Result := True;
4315 end;
4316 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
4317 begin
4318 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
4319 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ATTACK', FObj.X, FObj.Y);
4320 Result := True;
4321 end;
4322 MONSTER_BARON, MONSTER_KNIGHT,
4323 MONSTER_CACO, MONSTER_MANCUB:
4324 // Ýòè ìîíñòðû íå ïèíàþò - îíè ñòðåëÿþò â óïîð:
4325 if not g_Game_IsClient then Result := shoot(o, True);
4326 end;
4327 end;
4329 function TMonster.shoot(o: PObj; immediately: Boolean): Boolean;
4330 var
4331 xd, yd, m: Integer;
4332 begin
4333 Result := False;
4335 // Ñòðåëÿòü ðàíî:
4336 if FAmmo < 0 then
4337 Exit;
4339 // Æäàòü âðåìåíè ãîòîâíîñòè ê âûñòðåëó:
4340 if not immediately then
4341 case FMonsterType of
4342 MONSTER_FISH, MONSTER_BARREL, MONSTER_DEMON:
4343 Exit; // íå ñòðåëÿþò
4344 MONSTER_CGUN, MONSTER_BSP, MONSTER_ROBO:
4345 begin
4346 FAmmo := FAmmo + 1;
4347 // Âðåìÿ âûñòðåëà óïóùåíî:
4348 if FAmmo >= 50 then
4349 FAmmo := IfThen(FMonsterType = MONSTER_ROBO, -200, -50);
4350 end;
4351 MONSTER_MAN: ;
4352 MONSTER_MANCUB:
4353 begin
4354 FAmmo := FAmmo + 1;
4355 // Âðåìÿ âûñòðåëà óïóùåíî:
4356 if FAmmo >= 5 then
4357 FAmmo := -50;
4358 end;
4359 MONSTER_SPIDER:
4360 begin
4361 FAmmo := FAmmo + 1;
4362 // Âðåìÿ âûñòðåëà óïóùåíî:
4363 if FAmmo >= 100 then
4364 FAmmo := -50;
4365 end;
4366 MONSTER_CYBER:
4367 begin
4368 // Ñòðåëÿåò íå âñåãäà:
4369 if Random(2) = 0 then
4370 Exit;
4371 FAmmo := FAmmo + 1;
4372 // Âðåìÿ âûñòðåëà óïóùåíî:
4373 if FAmmo >= 10 then
4374 FAmmo := -50;
4375 end;
4376 MONSTER_BARON, MONSTER_KNIGHT: if Random(8) <> 0 then Exit;
4377 MONSTER_SKEL: if Random(32) <> 0 then Exit;
4378 MONSTER_VILE: if Random(8) <> 0 then Exit;
4379 MONSTER_PAIN: if Random(8) <> 0 then Exit;
4380 else if Random(16) <> 0 then Exit;
4381 end;
4383 // Öåëè íå âèäíî:
4384 if not g_Look(@FObj, o, FDirection) then
4385 Exit;
4387 FTargetTime := 0;
4389 tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2)+((o^.Vel.X{+o^.Accel.X})*12);
4390 ty := o^.Y+o^.Rect.Y+(o^.Rect.Height div 2)+((o^.Vel.Y{+o^.Accel.Y})*12);
4392 // Ðàçíèöà ïî âûñîòå áîëüøå ðàçíèöû ïî ãîðèçîíòàëè
4393 // (íå ìîæåò ñòðåëÿòü ïîä òàêèì áîëüøèì óãëîì):
4394 if Abs(tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2))) <
4395 Abs(ty-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2))) then
4396 Exit;
4398 case FMonsterType of
4399 MONSTER_IMP, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO:
4400 begin
4401 SetState(MONSTATE_SHOOT);
4402 {nn}
4403 end;
4404 MONSTER_SKEL:
4405 begin
4406 SetState(MONSTATE_SHOOT);
4407 {nn}
4408 end;
4409 MONSTER_VILE:
4410 begin // Çàæèãàåì îãîíü
4411 tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2);
4412 ty := o^.Y+o^.Rect.Y;
4413 SetState(MONSTATE_SHOOT);
4415 vilefire.Reset();
4417 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ATTACK', FObj.X, FObj.Y);
4418 g_Sound_PlayExAt('SOUND_FIRE', o^.X, o^.Y);
4419 end;
4420 MONSTER_SOUL:
4421 begin // Ëåòèò â ñòîðîíó öåëè:
4422 SetState(MONSTATE_ATTACK);
4423 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_ATTACK', FObj.X, FObj.Y);
4425 xd := tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
4426 yd := ty-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
4427 m := Max(Abs(xd), Abs(yd));
4428 if m = 0 then
4429 m := 1;
4431 FObj.Vel.X := (xd*16) div m;
4432 FObj.Vel.Y := (yd*16) div m;
4433 end;
4434 MONSTER_MANCUB, MONSTER_ZOMBY, MONSTER_SERG, MONSTER_BSP, MONSTER_ROBO,
4435 MONSTER_CYBER, MONSTER_CGUN, MONSTER_SPIDER, MONSTER_PAIN, MONSTER_MAN:
4436 begin
4437 // Ìàíêóáóñ ðÿâêàåò ïåðåä ïåðâîé àòàêîé:
4438 if FMonsterType = MONSTER_MANCUB then
4439 if FAmmo = 1 then
4440 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ATTACK', FObj.X, FObj.Y);
4442 SetState(MONSTATE_SHOOT);
4443 end;
4444 else Exit;
4445 end;
4447 Result := True;
4448 end;
4450 function TMonster.alive(): Boolean;
4451 begin
4452 Result := (FHealth > 0) and not (FState in [MONSTATE_DIE, MONSTATE_DEAD]);
4453 end;
4455 procedure TMonster.SetHealth(aH: Integer);
4456 begin
4457 if (aH > 0) and (aH < 1000000) then
4458 begin
4459 FHealth := aH;
4460 if FHealth > FMaxHealth then
4461 FMaxHealth := FHealth;
4462 end;
4463 end;
4465 procedure TMonster.WakeUp();
4466 begin
4467 if g_Game_IsClient then Exit;
4468 SetState(MONSTATE_GO);
4469 FTargetTime := MAX_ATM;
4470 WakeUpSound();
4471 end;
4473 procedure TMonster.SaveState (st: TStream);
4474 var
4475 i: Integer;
4476 b: Byte;
4477 anim: Boolean;
4478 begin
4479 assert(st <> nil);
4481 // Ñèãíàòóðà ìîíñòðà:
4482 utils.writeSign(st, 'MONS');
4483 utils.writeInt(st, Byte(0)); // version
4484 // UID ìîíñòðà:
4485 utils.writeInt(st, Word(FUID));
4486 // Íàïðàâëåíèå
4487 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
4488 utils.writeInt(st, Byte(b));
4489 // Íàäî ëè óäàëèòü åãî
4490 utils.writeBool(st, FRemoved);
4491 // Îñòàëîñü çäîðîâüÿ
4492 utils.writeInt(st, LongInt(FHealth));
4493 // Ñîñòîÿíèå
4494 utils.writeInt(st, Byte(FState));
4495 // Òåêóùàÿ àíèìàöèÿ
4496 utils.writeInt(st, Byte(FCurAnim));
4497 // UID öåëè
4498 utils.writeInt(st, Word(FTargetUID));
4499 // Âðåìÿ ïîñëå ïîòåðè öåëè
4500 utils.writeInt(st, LongInt(FTargetTime));
4501 // Ïîâåäåíèå ìîíñòðà
4502 utils.writeInt(st, Byte(FBehaviour));
4503 // Ãîòîâíîñòü ê âûñòðåëó
4504 utils.writeInt(st, LongInt(FAmmo));
4505 // Áîëü
4506 utils.writeInt(st, LongInt(FPain));
4507 // Âðåìÿ îæèäàíèÿ
4508 utils.writeInt(st, LongInt(FSleep));
4509 // Îçâó÷èâàòü ëè áîëü
4510 utils.writeBool(st, FPainSound);
4511 // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè
4512 utils.writeBool(st, FWaitAttackAnim);
4513 // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå
4514 utils.writeBool(st, FChainFire);
4515 // Ïîäëåæèò ëè ðåñïàâíó
4516 utils.writeBool(st, FNoRespawn);
4517 // Êîîðäèíàòû öåëè
4518 utils.writeInt(st, LongInt(tx));
4519 utils.writeInt(st, LongInt(ty));
4520 // ID ìîíñòðà ïðè ñòàðòå êàðòû
4521 utils.writeInt(st, LongInt(FStartID));
4522 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà
4523 utils.writeInt(st, LongInt(FSpawnTrigger));
4524 // Îáúåêò ìîíñòðà
4525 Obj_SaveState(st, @FObj);
4526 // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà
4527 anim := (vilefire <> nil);
4528 utils.writeBool(st, anim);
4529 // Åñëè åñòü - ñîõðàíÿåì:
4530 if anim then vilefire.SaveState(st);
4531 // Àíèìàöèè
4532 for i := ANIM_SLEEP to ANIM_PAIN do
4533 begin
4534 // Åñòü ëè ëåâàÿ àíèìàöèÿ
4535 anim := (FAnim[i, TDirection.D_LEFT] <> nil);
4536 utils.writeBool(st, anim);
4537 // Åñëè åñòü - ñîõðàíÿåì
4538 if anim then FAnim[i, TDirection.D_LEFT].SaveState(st);
4539 // Åñòü ëè ïðàâàÿ àíèìàöèÿ
4540 anim := (FAnim[i, TDirection.D_RIGHT] <> nil);
4541 utils.writeBool(st, anim);
4542 // Åñëè åñòü - ñîõðàíÿåì
4543 if anim then FAnim[i, TDirection.D_RIGHT].SaveState(st);
4544 end;
4545 end;
4548 procedure TMonster.LoadState (st: TStream);
4549 var
4550 i: Integer;
4551 b: Byte;
4552 anim: Boolean;
4553 begin
4554 assert(st <> nil);
4556 // Ñèãíàòóðà ìîíñòðà:
4557 if not utils.checkSign(st, 'MONS') then raise XStreamError.Create('invalid monster signature');
4558 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid monster version');
4559 if (uidMap[FUID] <> nil) and (uidMap[FUID] <> self) then raise Exception.Create('internal error in monster loader (0)');
4560 uidMap[FUID] := nil;
4561 // UID ìîíñòðà:
4562 FUID := utils.readWord(st);
4563 //if (arrIdx = -1) then raise Exception.Create('internal error in monster loader');
4564 if (uidMap[FUID] <> nil) then raise Exception.Create('internal error in monster loader (1)');
4565 uidMap[FUID] := self;
4566 // Íàïðàâëåíèå
4567 b := utils.readByte(st);
4568 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
4569 // Íàäî ëè óäàëèòü åãî
4570 FRemoved := utils.readBool(st);
4571 // Îñòàëîñü çäîðîâüÿ
4572 FHealth := utils.readLongInt(st);
4573 // Ñîñòîÿíèå
4574 FState := utils.readByte(st);
4575 // Òåêóùàÿ àíèìàöèÿ
4576 FCurAnim := utils.readByte(st);
4577 // UID öåëè
4578 FTargetUID := utils.readWord(st);
4579 // Âðåìÿ ïîñëå ïîòåðè öåëè
4580 FTargetTime := utils.readLongInt(st);
4581 // Ïîâåäåíèå ìîíñòðà
4582 FBehaviour := utils.readByte(st);
4583 // Ãîòîâíîñòü ê âûñòðåëó
4584 FAmmo := utils.readLongInt(st);
4585 // Áîëü
4586 FPain := utils.readLongInt(st);
4587 // Âðåìÿ îæèäàíèÿ
4588 FSleep := utils.readLongInt(st);
4589 // Îçâó÷èâàòü ëè áîëü
4590 FPainSound := utils.readBool(st);
4591 // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè
4592 FWaitAttackAnim := utils.readBool(st);
4593 // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå
4594 FChainFire := utils.readBool(st);
4595 // Ïîäëåæèò ëè ðåñïàâíó
4596 FNoRespawn := utils.readBool(st);
4597 // Êîîðäèíàòû öåëè
4598 tx := utils.readLongInt(st);
4599 ty := utils.readLongInt(st);
4600 // ID ìîíñòðà ïðè ñòàðòå êàðòû
4601 FStartID := utils.readLongInt(st);
4602 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà
4603 FSpawnTrigger := utils.readLongInt(st);
4604 // Îáúåêò ìîíñòðà
4605 Obj_LoadState(@FObj, st);
4606 // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà
4607 anim := utils.readBool(st);
4608 // Åñëè åñòü - çàãðóæàåì:
4609 if anim then
4610 begin
4611 Assert(vilefire <> nil, 'TMonster.LoadState: no vilefire anim');
4612 vilefire.LoadState(st);
4613 end;
4614 // Àíèìàöèè
4615 for i := ANIM_SLEEP to ANIM_PAIN do
4616 begin
4617 // Åñòü ëè ëåâàÿ àíèìàöèÿ
4618 anim := utils.readBool(st);
4619 // Åñëè åñòü - çàãðóæàåì
4620 if anim then
4621 begin
4622 Assert(FAnim[i, TDirection.D_LEFT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_left anim');
4623 FAnim[i, TDirection.D_LEFT].LoadState(st);
4624 end;
4625 // Åñòü ëè ïðàâàÿ àíèìàöèÿ
4626 anim := utils.readBool(st);
4627 // Åñëè åñòü - çàãðóæàåì
4628 if anim then
4629 begin
4630 Assert(FAnim[i, TDirection.D_RIGHT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_right anim');
4631 FAnim[i, TDirection.D_RIGHT].LoadState(st);
4632 end;
4633 end;
4634 // update cache
4635 self.positionChanged
4636 end;
4639 procedure TMonster.ActivateTriggers();
4640 var
4641 a: Integer;
4642 begin
4643 if FDieTriggers <> nil then
4644 for a := 0 to High(FDieTriggers) do
4645 g_Triggers_Press(FDieTriggers[a], ACTIVATE_MONSTERPRESS);
4646 if FSpawnTrigger > -1 then
4647 begin
4648 g_Triggers_DecreaseSpawner(FSpawnTrigger);
4649 FSpawnTrigger := -1;
4650 end;
4651 end;
4653 procedure TMonster.AddTrigger(t: Integer);
4654 begin
4655 SetLength(FDieTriggers, Length(FDieTriggers)+1);
4656 FDieTriggers[High(FDieTriggers)] := t;
4657 end;
4659 procedure TMonster.ClearTriggers();
4660 begin
4661 SetLength(FDieTriggers, 0);
4662 end;
4664 procedure TMonster.CatchFire(Attacker: Word; Timeout: Integer = MON_BURN_TIME);
4665 begin
4666 if FMonsterType in [MONSTER_SOUL, MONSTER_VILE] then
4667 exit; // àð÷è íå ãîðÿò, ÷åðåïà óæå ãîðÿò
4668 if Timeout <= 0 then exit;
4669 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
4670 exit; // íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
4671 if FFireTime <= 0 then
4672 g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
4673 FFireTime := Timeout;
4674 FFireAttacker := Attacker;
4675 if g_Game_IsNet and g_Game_IsServer then MH_SEND_MonsterState(FUID);
4676 end;
4678 procedure TMonster.OnFireFlame(Times: DWORD = 1);
4679 var
4680 id, i: DWORD;
4681 Anim: TAnimation;
4682 begin
4683 if (Random(10) = 1) and (Times = 1) then
4684 Exit;
4686 if g_Frames_Get(id, 'FRAMES_FLAME') then
4687 begin
4688 for i := 1 to Times do
4689 begin
4690 Anim := TAnimation.Create(id, False, 3);
4691 Anim.Alpha := 0;
4692 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
4693 Obj.Y+8+Random(8+Times*2)+IfThen(FState = MONSTATE_DEAD, 16, 0), Anim, ONCEANIM_SMOKE);
4694 Anim.Free();
4695 end;
4696 end;
4697 end;
4700 // ////////////////////////////////////////////////////////////////////////// //
4701 // throws on invalid uid
4702 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
4703 begin
4704 result := g_Mons_ByIdx_NC(uid);
4705 if (result = nil) then raise Exception.Create('g_Mons_ByIdx: invalid monster id');
4706 end;
4708 // can return null
4709 function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
4710 begin
4711 if (uid < 0) or (uid > High(gMonsters)) then begin result := nil; exit; end;
4712 result := gMonsters[uid];
4713 end;
4715 function g_Mons_TotalCount (): Integer; inline;
4716 begin
4717 result := Length(gMonsters);
4718 end;
4721 function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
4722 var
4723 idx: Integer;
4724 mon: TMonster;
4725 begin
4726 result := false;
4727 if (gMonsters = nil) or not assigned(cb) then exit;
4728 for idx := 0 to High(gMonsters) do
4729 begin
4730 mon := gMonsters[idx];
4731 if (mon <> nil) then
4732 begin
4733 result := cb(mon);
4734 if result then exit;
4735 end;
4736 end;
4737 end;
4740 function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
4741 var
4742 idx: Integer;
4743 mon: TMonster;
4744 begin
4745 result := false;
4746 if (gMonsters = nil) or not assigned(cb) then exit;
4747 for idx := 0 to High(gMonsters) do
4748 begin
4749 mon := gMonsters[idx];
4750 if (mon <> nil) and mon.alive then
4751 begin
4752 result := cb(mon);
4753 if result then exit;
4754 end;
4755 end;
4756 end;
4759 function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
4760 (*
4761 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4762 begin
4763 result := mon.alive;// and g_Obj_Collide(x, y, width, height, @mon.Obj));
4764 end;
4765 *)
4766 var
4767 idx: Integer;
4768 mon: TMonster;
4769 mit: PMonster;
4770 it: TMonsterGrid.Iter;
4771 begin
4772 result := false;
4773 if (width < 1) or (height < 1) then exit;
4774 if gmon_debug_use_sqaccel then
4775 begin
4776 //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4777 it := monsGrid.forEachInAABB(x, y, width, height);
4778 for mit in it do if (mit.alive) then begin result := true; break; end;
4779 it.release();
4780 end
4781 else
4782 begin
4783 for idx := 0 to High(gMonsters) do
4784 begin
4785 mon := gMonsters[idx];
4786 if (mon <> nil) and mon.alive then
4787 begin
4788 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4789 begin
4790 result := true;
4791 exit;
4792 end;
4793 end;
4794 end;
4795 end;
4796 end;
4799 function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
4800 (*
4801 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4802 begin
4803 result := cb(mon);
4804 end;
4805 *)
4806 var
4807 idx: Integer;
4808 mon: TMonster;
4809 mit: PMonster;
4810 it: TMonsterGrid.Iter;
4811 begin
4812 result := false;
4813 if (width < 1) or (height < 1) then exit;
4814 if gmon_debug_use_sqaccel then
4815 begin
4816 //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4817 it := monsGrid.forEachInAABB(x, y, width, height);
4818 for mit in it do if (cb(mit^)) then begin result := true; break; end;
4819 it.release();
4820 end
4821 else
4822 begin
4823 for idx := 0 to High(gMonsters) do
4824 begin
4825 mon := gMonsters[idx];
4826 if (mon <> nil) and mon.alive then
4827 begin
4828 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4829 begin
4830 result := cb(mon);
4831 if result then exit;
4832 end;
4833 end;
4834 end;
4835 end;
4836 end;
4839 function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
4840 (*
4841 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4842 begin
4843 //result := false;
4844 //if mon.alive and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
4845 if mon.alive then result := cb(mon) else result := false;
4846 end;
4847 *)
4848 var
4849 idx: Integer;
4850 mon: TMonster;
4851 mit: PMonster;
4852 it: TMonsterGrid.Iter;
4853 begin
4854 result := false;
4855 if (width < 1) or (height < 1) then exit;
4856 if gmon_debug_use_sqaccel then
4857 begin
4859 if (width = 1) and (height = 1) then
4860 begin
4861 result := (monsGrid.forEachAtPoint(x, y, monsCollCheck) <> nil);
4862 end
4863 else
4864 begin
4865 result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4866 end;
4868 it := monsGrid.forEachInAABB(x, y, width, height);
4869 for mit in it do
4870 begin
4871 if (mit^.alive) then
4872 begin
4873 if (cb(mit^)) then begin result := true; break; end;
4874 end;
4875 end;
4876 it.release();
4877 end
4878 else
4879 begin
4880 for idx := 0 to High(gMonsters) do
4881 begin
4882 mon := gMonsters[idx];
4883 if (mon <> nil) and mon.alive then
4884 begin
4885 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4886 begin
4887 result := cb(mon);
4888 if result then exit;
4889 end;
4890 end;
4891 end;
4892 end;
4893 end;
4896 end.