DEADSOFTWARE

Refactor: Define constants for LiftType
[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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 {$M+}
18 {.$DEFINE D2F_DEBUG_MONS_MOVE}
19 unit g_monsters;
21 interface
23 uses
24 SysUtils, Classes,
25 mempool,
26 g_basic, e_graphics, g_phys, g_textures, g_grid,
27 g_saveload, g_panel, xprofiler;
29 const
30 MONSTATE_SLEEP = 0;
31 MONSTATE_GO = 1;
32 MONSTATE_RUN = 2;
33 MONSTATE_CLIMB = 3;
34 MONSTATE_DIE = 4;
35 MONSTATE_DEAD = 5;
36 MONSTATE_ATTACK = 6;
37 MONSTATE_SHOOT = 7;
38 MONSTATE_PAIN = 8;
39 MONSTATE_WAIT = 9;
40 MONSTATE_REVIVE = 10;
41 MONSTATE_RUNOUT = 11;
43 { in mapdef now
44 BH_NORMAL = 0;
45 BH_KILLER = 1;
46 BH_MANIAC = 2;
47 BH_INSANE = 3;
48 BH_CANNIBAL = 4;
49 BH_GOOD = 5;
50 }
52 type
53 PMonster = ^TMonster;
54 TMonster = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
55 private
56 FMonsterType: Byte;
57 FUID: Word;
58 FDirection: TDirection;
59 FStartDirection: TDirection;
60 FStartX, FStartY: Integer;
61 FRemoved: Boolean;
62 FHealth: Integer;
63 FMaxHealth: Integer;
64 FState: Byte;
65 FCurAnim: Byte;
66 FAnim: Array of Array [TDirection.D_LEFT..TDirection.D_RIGHT] of TAnimation;
67 FTargetUID: Word;
68 FTargetTime: Integer;
69 FBehaviour: Byte;
70 FAmmo: Integer;
71 FPain: Integer;
72 FSleep: Integer;
73 FPainSound: Boolean;
74 FPainTicks: Integer;
75 FWaitAttackAnim: Boolean;
76 FChainFire: Boolean;
77 tx, ty: Integer;
78 FStartID: Integer;
79 FObj: TObj;
80 FBloodRed: Byte;
81 FBloodGreen: Byte;
82 FBloodBlue: Byte;
83 FBloodKind: Byte;
84 FShellTimer: Integer;
85 FShellType: Byte;
86 FFirePainTime: Integer;
87 FFireAttacker: Word;
88 vilefire: TAnimation;
89 mProxyId: Integer; // node in dyntree or -1
90 mArrIdx: Integer; // in gMonsters
92 FDieTriggers: Array of Integer;
93 FSpawnTrigger: Integer;
95 mNeedSend: Boolean; // for network
97 mEDamageType: Integer;
99 procedure Turn();
100 function findNewPrey(): Boolean;
101 procedure ActivateTriggers();
103 procedure setGameX (v: Integer); inline;
104 procedure setGameY (v: Integer); inline;
106 procedure doDamage (v: Integer);
108 public
109 FNoRespawn: Boolean;
110 FFireTime: Integer;
111 trapCheckFrameId: DWord; // for `g_weapons.CheckTrap()`
112 mplatCheckFrameId: LongWord;
114 constructor Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
115 destructor Destroy(); override;
116 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
117 function Collide(Panel: TPanel): Boolean; overload;
118 function Collide(X, Y: Integer): Boolean; overload;
119 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
120 function alive(): Boolean;
121 procedure SetHealth(aH: Integer);
122 procedure Push(vx, vy: Integer);
123 function Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
124 function Heal(Value: Word): Boolean;
125 procedure BFGHit();
126 procedure Update();
127 procedure ClientUpdate();
128 procedure ClientAttack(wx, wy, atx, aty: Integer);
129 procedure SetDeadAnim;
130 procedure Draw();
131 procedure WakeUp();
132 procedure WakeUpSound();
133 procedure DieSound();
134 procedure PainSound();
135 procedure ActionSound();
136 procedure AddTrigger(t: Integer);
137 procedure ClearTriggers();
138 procedure Respawn();
139 procedure SaveState (st: TStream);
140 procedure LoadState (st: TStream);
141 procedure SetState(State: Byte; ForceAnim: Byte = 255);
142 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
143 procedure MakeBloodSimple(Count: Word);
144 procedure RevertAnim(R: Boolean = True);
145 function AnimIsReverse: Boolean;
146 function shoot(o: PObj; immediately: Boolean): Boolean;
147 function kick(o: PObj): Boolean;
148 procedure CatchFire(Attacker: Word);
149 procedure OnFireFlame(Times: DWORD = 1);
151 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
153 procedure setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline;
154 procedure moveBy (dx, dy: Integer); inline;
156 procedure getMapBox (out x, y, w, h: Integer); inline;
158 // get-and-clear
159 function gncNeedSend (): Boolean; inline;
160 procedure setDirty (); inline; // why `dirty`? 'cause i may introduce property `needSend` later
162 public
163 property Obj: TObj read FObj;
165 property proxyId: Integer read mProxyId;
166 property arrIdx: Integer read mArrIdx;
168 property MonsterType: Byte read FMonsterType;
169 property MonsterHealth: Integer read FHealth write FHealth;
170 property MonsterAmmo: Integer read FAmmo write FAmmo;
171 property MonsterTargetUID: Word read FTargetUID write FTargetUID;
172 property MonsterTargetTime: Integer read FTargetTime write FTargetTime;
173 property MonsterBehaviour: Byte read FBehaviour write FBehaviour;
174 property MonsterSleep: Integer read FSleep write FSleep;
175 property MonsterState: Byte read FState write FState;
176 property MonsterRemoved: Boolean read FRemoved write FRemoved;
177 property MonsterPain: Integer read FPain write FPain;
178 property MonsterAnim: Byte read FCurAnim write FCurAnim;
180 property UID: Word read FUID write FUID;
181 property SpawnTrigger: Integer read FSpawnTrigger write FSpawnTrigger;
183 property GameX: Integer read FObj.X write setGameX;
184 property GameY: Integer read FObj.Y write setGameY;
185 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
186 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
187 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
188 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
189 property GameDirection: TDirection read FDirection write FDirection;
191 property StartID: Integer read FStartID;
193 published
194 property eMonsterType: Byte read FMonsterType;
195 property eMonsterHealth: Integer read FHealth write FHealth;
196 property eMonsterAmmo: Integer read FAmmo write FAmmo;
197 property eMonsterTargetUID: Word read FTargetUID write FTargetUID;
198 property eMonsterTargetTime: Integer read FTargetTime write FTargetTime;
199 property eMonsterBehaviour: Byte read FBehaviour write FBehaviour;
200 property eMonsterSleep: Integer read FSleep write FSleep;
201 property eMonsterState: Byte read FState write FState;
202 property eMonsterRemoved: Boolean read FRemoved;
203 property eMonsterPain: Integer read FPain write FPain;
204 property eMonsterAnim: Byte read FCurAnim;
206 property eUID: Word read FUID;
207 property eSpawnTrigger: Integer read FSpawnTrigger;
209 property eGameX: Integer read FObj.X write setGameX;
210 property eGameY: Integer read FObj.Y write setGameY;
211 property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
212 property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
213 property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
214 property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
215 property eGameDirection: TDirection read FDirection write FDirection;
217 property eStartID: Integer read FStartID;
219 // set this before assigning something to `eDamage`
220 property eDamageType: Integer read mEDamageType write mEDamageType;
221 property eDamage: Integer write doDamage;
222 end;
225 // will be called from map loader
226 procedure g_Mons_InitTree (x, y, w, h: Integer);
228 procedure g_Monsters_LoadData ();
229 procedure g_Monsters_FreeData ();
230 procedure g_Monsters_Init ();
231 procedure g_Monsters_Free (clearGrid: Boolean=true);
232 function g_Monsters_Create (MonsterType: Byte; X, Y: Integer; Direction: TDirection;
233 AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
234 procedure g_Monsters_Update ();
235 procedure g_Monsters_Draw ();
236 procedure g_Monsters_DrawHealth ();
237 function g_Monsters_ByUID (UID: Word): TMonster;
238 procedure g_Monsters_killedp ();
239 procedure g_Monsters_SaveState (st: TStream);
240 procedure g_Monsters_LoadState (st: TStream);
242 function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
243 function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
245 function g_Mons_TypeLo (): Integer; inline;
246 function g_Mons_TypeHi (): Integer; inline;
248 function g_Mons_TypeIdByName (const name: AnsiString): Integer;
249 function g_Mons_NameByTypeId (monType: Integer): AnsiString;
250 function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
253 type
254 TEachMonsterCB = function (mon: TMonster): Boolean is nested; // return `true` to stop
256 // throws on invalid uid
257 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
259 // can return null
260 function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
262 function g_Mons_TotalCount (): Integer; inline;
264 function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
266 function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
267 function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
269 function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
270 function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
272 function g_Mons_getNewTrapFrameId (): DWord; inline;
273 function g_Mons_getNewMPlatFrameId (): LongWord; inline;
277 type
278 TMonsAlongLineCB = function (mon: TMonster; tag: Integer): Boolean is nested;
280 function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
284 var
285 gmon_debug_use_sqaccel: Boolean = true;
288 //HACK!
289 procedure g_Mons_ProfilersBegin ();
290 procedure g_Mons_ProfilersEnd ();
292 procedure g_Mons_LOS_Start (); inline;
293 procedure g_Mons_LOS_End (); inline;
295 var
296 profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
299 type
300 TMonsterGrid = specialize TBodyGridBase<TMonster>;
302 var
303 monsGrid: TMonsterGrid = nil; // DO NOT USE! public for debugging only!
306 var
307 gmon_debug_think: Boolean = true;
308 gmon_debug_one_think_step: Boolean = false;
311 implementation
313 uses
314 e_log, e_texture, g_main, g_sound, g_gfx, g_player, g_game,
315 g_weapons, g_triggers, MAPDEF, g_items, g_options,
316 g_console, g_map, Math, g_menu, wadreader,
317 g_language, g_netmsg, idpool, utils, xstreams;
321 // ////////////////////////////////////////////////////////////////////////// //
322 procedure g_Mons_ProfilersBegin ();
323 begin
324 if (profMonsLOS = nil) then profMonsLOS := TProfiler.Create('LOS CALC', g_profile_history_size);
325 if (profMonsLOS <> nil) then profMonsLOS.mainBegin(g_profile_los);
326 if g_profile_los and (profMonsLOS <> nil) then
327 begin
328 profMonsLOS.sectionBegin('loscalc');
329 profMonsLOS.sectionEnd();
330 end;
331 end;
333 procedure g_Mons_ProfilersEnd ();
334 begin
335 if (profMonsLOS <> nil) and (g_profile_los) then profMonsLOS.mainEnd();
336 end;
338 procedure g_Mons_LOS_Start (); inline;
339 begin
340 if (profMonsLOS <> nil) then profMonsLOS.sectionBeginAccum('loscalc');
341 end;
343 procedure g_Mons_LOS_End (); inline;
344 begin
345 if (profMonsLOS <> nil) then profMonsLOS.sectionEnd();
346 end;
349 // ////////////////////////////////////////////////////////////////////////// //
350 var
351 monCheckTrapLastFrameId: DWord = 0;
352 monCheckMPlatLastFrameId: LongWord = 0;
355 procedure TMonster.getMapBox (out x, y, w, h: Integer); inline;
356 begin
357 x := FObj.X+FObj.Rect.X;
358 y := FObj.Y+FObj.Rect.Y;
359 w := FObj.Rect.Width;
360 h := FObj.Rect.Height;
361 end;
363 function TMonster.gncNeedSend (): Boolean; inline; begin result := mNeedSend; mNeedSend := false; end;
365 procedure TMonster.setDirty (); inline; begin mNeedSend := true; end;
368 // ////////////////////////////////////////////////////////////////////////// //
370 function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
371 begin
372 if not assigned(cb) then begin result := nil; exit; end;
373 result := monsGrid.forEachAlongLine(x0, y0, x1, y1, cb, -1, log);
374 end;
378 //WARNING! call this after monster position was changed, or coldet will not work right!
379 procedure TMonster.positionChanged ();
380 var
381 x, y, w, h: Integer;
382 nx, ny, nw, nh: Integer;
383 begin
384 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
385 //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);
386 {$ENDIF}
387 if (mProxyId = -1) then
388 begin
389 //mNeedSend := true;
390 mProxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
391 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
392 monsGrid.getBodyXY(mProxyId, x, y);
393 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);
394 {$ENDIF}
395 end
396 else
397 begin
398 monsGrid.getBodyDims(mProxyId, x, y, w, h);
399 getMapBox(nx, ny, nw, nh);
401 if (w <> nw) or (h <> nh) then
402 begin
403 //mNeedSend := true;
404 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
405 e_WriteLog(Format('monster #%d:(%u): resized; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
406 {$ENDIF}
407 monsGrid.moveResizeBody(mProxyId, nx, ny, nw, nh);
408 end
409 else if (x <> nx) or (y <> ny) then
410 begin
411 //mNeedSend := true;
412 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
413 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);
414 {$ENDIF}
415 monsGrid.moveBody(mProxyId, nx, ny);
416 end
417 else
418 begin
419 exit; // nothing to do
420 end;
421 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
422 monsGrid.getBodyXY(mProxyId, x, y);
423 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);
424 {$ENDIF}
425 end;
426 end;
429 // ////////////////////////////////////////////////////////////////////////// //
430 const
431 ANIM_SLEEP = 0;
432 ANIM_GO = 1;
433 ANIM_DIE = 2;
434 ANIM_MESS = 3;
435 ANIM_ATTACK = 4;
436 ANIM_ATTACK2 = 5;
437 ANIM_PAIN = 6;
439 MONSTER_SIGNATURE = $534E4F4D; // 'MONS'
441 // Òàáëèöà òèïîâ àíèìàöèè ìîíñòðîâ:
442 ANIMTABLE: Array [ANIM_SLEEP..ANIM_PAIN] of
443 record
444 name: String;
445 loop: Boolean;
446 end = ((name: 'SLEEP'; loop: True),
447 (name: 'GO'; loop: True),
448 (name: 'DIE'; loop: False),
449 (name: 'MESS'; loop: False),
450 (name: 'ATTACK'; loop: False),
451 (name: 'ATTACK2'; loop: False),
452 (name: 'PAIN'; loop: False));
454 // Òàáëèöà õàðàêòåðèñòèê ìîíñòðîâ:
455 MONSTERTABLE: Array [MONSTER_DEMON..MONSTER_MAN] of
456 record
457 Name: String;
458 Rect: TRectWH;
459 Health: Word;
460 RunVel: Byte;
461 MinPain: Byte;
462 Pain: Byte;
463 Jump: Byte;
464 end =
465 ((Name:'DEMON'; Rect:(X:7; Y:8; Width:50; Height:52); Health:60;
466 RunVel: 7; MinPain: 10; Pain: 20; Jump: 10),
468 (Name:'IMP'; Rect:(X:15; Y:10; Width:34; Height:50); Health:25;
469 RunVel: 3; MinPain: 0; Pain: 15; Jump: 10),
471 (Name:'ZOMBY'; Rect:(X:15; Y:8; Width:34; Height:52); Health:15;
472 RunVel: 3; MinPain: 0; Pain: 10; Jump: 10),
474 (Name:'SERG'; Rect:(X:15; Y:8; Width:34; Height:52); Health:20;
475 RunVel: 3; MinPain: 0; Pain: 10; Jump: 10),
477 (Name:'CYBER'; Rect:(X:24; Y:9; Width:80; Height:110); Health:500;
478 RunVel: 5; MinPain: 50; Pain: 70; Jump: 10),
480 (Name:'CGUN'; Rect:(X:15; Y:4; Width:34; Height:56); Health:60;
481 RunVel: 3; MinPain: 10; Pain: 20; Jump: 10),
483 (Name:'BARON'; Rect:(X:39; Y:32; Width:50; Height:64); Health:150;
484 RunVel: 3; MinPain: 30; Pain: 40; Jump: 10),
486 (Name:'KNIGHT'; Rect:(X:39; Y:32; Width:50; Height:64); Health:75;
487 RunVel: 3; MinPain: 30; Pain: 40; Jump: 10),
489 (Name:'CACO'; Rect:(X:34; Y:36; Width:60; Height:56); Health:100;
490 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
492 (Name:'SOUL'; Rect:(X:16; Y:14; Width:32; Height:36); Health:60;
493 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
495 (Name:'PAIN'; Rect:(X:34; Y:36; Width:60; Height:56); Health:100;
496 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
498 (Name:'SPIDER'; Rect:(X:23; Y:14; Width:210; Height:100); Health:500;
499 RunVel: 4; MinPain: 50; Pain: 70; Jump: 10),
501 (Name:'BSP'; Rect:(X:14; Y:17; Width:100; Height:42); Health:150;
502 RunVel: 4; MinPain: 0; Pain: 20; Jump: 10),
504 (Name:'MANCUB'; Rect:(X:28; Y:34; Width:72; Height:60); Health:200;
505 RunVel: 3; MinPain: 20; Pain: 40; Jump: 7),
507 (Name:'SKEL'; Rect:(X:30; Y:28; Width:68; Height:72); Health:200;
508 RunVel: 6; MinPain: 20; Pain: 40; Jump: 11),
510 (Name:'VILE'; Rect:(X:30; Y:28; Width:68; Height:72); Health:150;
511 RunVel: 7; MinPain: 10; Pain: 30; Jump: 12),
513 (Name:'FISH'; Rect:(X:6; Y:11; Width:20; Height:10); Health:35;
514 RunVel: 14; MinPain: 10; Pain: 20; Jump: 6),
516 (Name:'BARREL'; Rect:(X:20; Y:13; Width:24; Height:36); Health:20;
517 RunVel: 0; MinPain: 0; Pain: 0; Jump: 0),
519 (Name:'ROBO'; Rect:(X:30; Y:26; Width:68; Height:76); Health:20;
520 RunVel: 3; MinPain: 20; Pain: 40; Jump: 6),
522 (Name:'MAN'; Rect:(X:15; Y:6; Width:34; Height:52); Health:400;
523 RunVel: 8; MinPain: 50; Pain: 70; Jump: 10));
525 // Òàáëèöà ïàðàìåòðîâ àíèìàöèè ìîíñòðîâ:
526 MONSTER_ANIMTABLE: Array [MONSTER_DEMON..MONSTER_MAN] of
527 record
528 LeftAnim: Boolean;
529 wX, wY: Integer; // Îòêóäà âûëåòèò ïóëÿ
530 AnimSpeed: Array [ANIM_SLEEP..ANIM_PAIN] of Byte;
531 AnimDeltaRight: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
532 AnimDeltaLeft: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
533 end = // SLEEP GO DIE MESS ATTACK ATTACK2 PAIN
534 ((LeftAnim: False; wX: 54; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //DEMON
535 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));
536 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))),
538 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //IMP
539 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));
540 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))),
542 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //ZOMBY
543 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));
544 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))),
546 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //SERG
547 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));
548 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))),
550 (LeftAnim: True; wX: 70; wY: 73; AnimSpeed:(3, 3, 3, 3, 3, 4, 3); //CYBER
551 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));
552 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))),
554 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 1, 0, 4); //CGUN
555 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));
556 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))),
558 (LeftAnim: True; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //BARON
559 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));
560 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))),
562 (LeftAnim: True; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //KNIGHT
563 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));
564 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))),
566 (LeftAnim: False; wX: 88; wY: 69; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //CACO
567 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));
568 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))),
570 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 4, 1, 0, 4); //SOUL
571 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));
572 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))),
574 (LeftAnim: False; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //PAIN
575 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));
576 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))),
578 (LeftAnim: True; wX: 128; wY: 64; AnimSpeed:(3, 2, 4, 4, 1, 0, 4); //SPIDER
579 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));
580 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))),
582 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 2, 3, 4, 1, 0, 4); //BSP
583 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));
584 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))),
586 (LeftAnim: False; wX: 64; wY: 64; AnimSpeed:(3, 2, 2, 4, 2, 0, 4); //MANCUB
587 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));
588 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))),
590 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 3, 3, 3, 3, 3, 3); //SKEL
591 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));
592 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))),
594 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 3, 3, 3, 3, 3, 3); //VILE
595 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));
596 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))),
598 (LeftAnim: False; wX: 8; wY: 8; AnimSpeed:(2, 2, 2, 2, 3, 0, 1); //FISH
599 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));
600 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 ))),
602 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 0, 3, 0, 0, 0, 5); //BARREL
603 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));
604 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))),
606 (LeftAnim: False; wX: 95; wY: 57; AnimSpeed:(1, 2, 1, 0, 1, 1, 0); //ROBO
607 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));
608 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))),
610 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 2, 0, 5); //MAN
611 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));
612 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))) );
614 MAX_ATM = 89; // Âðåìÿ îæèäàíèÿ ïîñëå ïîòåðè öåëè
615 MAX_SOUL = 512; // Îãðàíè÷åíèå Lost_Soul'îâ
618 // ////////////////////////////////////////////////////////////////////////// //
619 var
620 gMonsters: array of TMonster;
621 uidMap: array [0..65535] of TMonster; // monster knows it's index
622 freeInds: TIdPool = nil;
625 procedure clearUidMap ();
626 var
627 idx: Integer;
628 begin
629 for idx := 0 to High(uidMap) do uidMap[idx] := nil;
630 freeInds.clear();
631 end;
634 function g_Mons_getNewTrapFrameId (): DWord; inline;
635 var
636 f: Integer;
637 begin
638 Inc(monCheckTrapLastFrameId);
639 if (monCheckTrapLastFrameId = 0) then
640 begin
641 // wraparound
642 monCheckTrapLastFrameId := 1;
643 for f := 0 to High(gMonsters) do
644 begin
645 if (gMonsters[f] <> nil) then gMonsters[f].trapCheckFrameId := 0;
646 end;
647 end;
648 result := monCheckTrapLastFrameId;
649 end;
652 function g_Mons_getNewMPlatFrameId (): LongWord; inline;
653 var
654 f: Integer;
655 begin
656 Inc(monCheckMPlatLastFrameId);
657 if (monCheckMPlatLastFrameId = 0) then
658 begin
659 // wraparound
660 monCheckMPlatLastFrameId := 1;
661 for f := 0 to High(gMonsters) do
662 begin
663 if (gMonsters[f] <> nil) then gMonsters[f].mplatCheckFrameId := 0;
664 end;
665 end;
666 result := monCheckMPlatLastFrameId;
667 end;
670 var
671 pt_x: Integer = 0;
672 pt_xs: Integer = 1;
673 pt_y: Integer = 0;
674 pt_ys: Integer = 1;
675 soulcount: Integer = 0;
678 function allocMonster (): DWORD;
679 var
680 f, olen: Integer;
681 begin
682 result := freeInds.alloc();
683 if (result > High(gMonsters)) then
684 begin
685 olen := Length(gMonsters);
686 SetLength(gMonsters, result+64);
687 for f := olen to High(gMonsters) do gMonsters[f] := nil;
688 end;
689 end;
692 function IsFriend(a, b: Byte): Boolean;
693 begin
694 Result := True;
696 // Áî÷êà - âñåì äðóã:
697 if (a = MONSTER_BARREL) or (b = MONSTER_BARREL) then
698 Exit;
700 // Ìîíñòðû îäíîãî âèäà:
701 if a = b then
702 case a of
703 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
704 MONSTER_SOUL, MONSTER_PAIN, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
705 Exit; // Ýòè íå áüþò ñâîèõ
706 end;
708 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
709 if (a = MONSTER_SOUL) and (b = MONSTER_PAIN) then
710 Exit;
711 // Pain_Elemental íå ìîæåò ðàíèòü Lost_Soul'à:
712 if (b = MONSTER_SOUL) and (a = MONSTER_PAIN) 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 := 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 end;
1381 mon.positionChanged();
1383 result := mon;
1384 end;
1386 procedure g_Monsters_killedp();
1387 var
1388 a, h: Integer;
1389 begin
1390 if gMonsters = nil then
1391 Exit;
1393 // Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
1394 h := High(gMonsters);
1395 for a := 0 to h do
1396 begin
1397 if (gMonsters[a] <> nil) then
1398 begin
1399 with gMonsters[a] do
1400 begin
1401 if (FMonsterType = MONSTER_MAN) and
1402 (FState <> MONSTATE_DEAD) and
1403 (FState <> MONSTATE_SLEEP) and
1404 (FState <> MONSTATE_DIE) then
1405 begin
1406 g_Sound_PlayExAt('SOUND_MONSTER_TRUP', FObj.X, FObj.Y);
1407 Exit;
1408 end;
1409 end;
1410 end;
1411 end;
1412 end;
1414 procedure g_Monsters_Update();
1415 var
1416 a: Integer;
1417 begin
1418 // Öåëåóêàçàòåëü
1419 if gTime mod (GAME_TICK*2) = 0 then
1420 begin
1421 pt_x := pt_x+pt_xs;
1422 pt_y := pt_y+pt_ys;
1423 if abs(pt_x) > 246 then pt_xs := -pt_xs;
1424 if abs(pt_y) > 100 then pt_ys := -pt_ys;
1425 end;
1427 gMon := True; // Äëÿ ðàáîòû BlockMon'à
1429 if gmon_debug_think or gmon_debug_one_think_step then
1430 begin
1431 gmon_debug_one_think_step := false;
1432 for a := 0 to High(gMonsters) do
1433 begin
1434 if (gMonsters[a] = nil) then continue;
1435 if not gMonsters[a].FRemoved then
1436 begin
1437 if g_Game_IsClient then
1438 gMonsters[a].ClientUpdate()
1439 else
1440 gMonsters[a].Update();
1441 end
1442 else
1443 begin
1444 gMonsters[a].Free();
1445 gMonsters[a] := nil;
1446 end;
1447 end;
1448 end;
1450 gMon := False;
1451 end;
1453 procedure g_Monsters_Draw();
1454 var
1455 a: Integer;
1456 begin
1457 if gMonsters <> nil then
1458 begin
1459 for a := 0 to High(gMonsters) do
1460 begin
1461 if (gMonsters[a] <> nil) then gMonsters[a].Draw();
1462 end;
1463 end;
1464 end;
1466 procedure g_Monsters_DrawHealth();
1467 var
1468 a: Integer;
1469 fW, fH: Byte;
1470 begin
1471 if gMonsters = nil then Exit;
1472 e_TextureFontGetSize(gStdFont, fW, fH);
1474 for a := 0 to High(gMonsters) do
1475 begin
1476 if gMonsters[a] <> nil then
1477 begin
1478 e_TextureFontPrint(gMonsters[a].FObj.X + gMonsters[a].FObj.Rect.X,
1479 gMonsters[a].FObj.Y + gMonsters[a].FObj.Rect.Y + gMonsters[a].FObj.Rect.Height - fH,
1480 IntToStr(gMonsters[a].FHealth), gStdFont);
1481 end;
1482 end;
1483 end;
1485 function g_Monsters_ByUID (UID: Word): TMonster;
1486 begin
1487 result := uidMap[UID];
1488 end;
1490 procedure g_Monsters_SaveState (st: TStream);
1491 var
1492 count, i: Integer;
1493 begin
1494 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ
1495 count := 0;
1496 for i := 0 to High(gMonsters) do
1497 begin
1498 if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then count += 1;
1499 end;
1501 // Ñîõðàíÿåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1502 utils.writeInt(st, LongInt(pt_x));
1503 utils.writeInt(st, LongInt(pt_xs));
1504 utils.writeInt(st, LongInt(pt_y));
1505 utils.writeInt(st, LongInt(pt_ys));
1507 // Êîëè÷åñòâî ìîíñòðîâ
1508 utils.writeInt(st, LongInt(count));
1510 if (count = 0) then exit;
1512 // Ñîõðàíÿåì ìîíñòðîâ
1513 for i := 0 to High(gMonsters) do
1514 begin
1515 if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then
1516 begin
1517 // Òèï ìîíñòðà
1518 utils.writeInt(st, Byte(gMonsters[i].MonsterType));
1519 // Ñîõðàíÿåì äàííûå ìîíñòðà:
1520 gMonsters[i].SaveState(st);
1521 end;
1522 end;
1523 end;
1526 procedure g_Monsters_LoadState (st: TStream);
1527 var
1528 count, a: Integer;
1529 b: Byte;
1530 mon: TMonster;
1531 begin
1532 assert(st <> nil);
1534 g_Monsters_Free(false);
1536 // Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1537 pt_x := utils.readLongInt(st);
1538 pt_xs := utils.readLongInt(st);
1539 pt_y := utils.readLongInt(st);
1540 pt_ys := utils.readLongInt(st);
1542 // Êîëè÷åñòâî ìîíñòðîâ
1543 count := utils.readLongInt(st);
1545 if (count = 0) then exit;
1546 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid monster count');
1548 // Çàãðóæàåì ìîíñòðîâ
1549 for a := 0 to count-1 do
1550 begin
1551 // Òèï ìîíñòðà
1552 b := utils.readByte(st);
1553 // Ñîçäàåì ìîíñòðà
1554 mon := g_Monsters_Create(b, 0, 0, TDirection.D_LEFT);
1555 if (mon = nil) then raise XStreamError.Create('g_Monsters_LoadState: ID = -1 (can''t create)');
1556 // Çàãðóæàåì äàííûå ìîíñòðà
1557 mon.LoadState(st);
1558 end;
1559 end;
1562 // ////////////////////////////////////////////////////////////////////////// //
1563 function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
1564 begin
1565 result := nil;
1566 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1567 begin
1568 result := g_Monsters_Create(monType, x, y, dir);
1569 end;
1570 end;
1573 function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
1574 begin
1575 result := g_Mons_SpawnAt(g_Mons_TypeIdByName(typeName), x, y, dir);
1576 end;
1580 // ////////////////////////////////////////////////////////////////////////// //
1581 function g_Mons_TypeLo (): Integer; inline; begin result := Low(MONSTERTABLE); end;
1582 function g_Mons_TypeHi (): Integer; inline; begin result := High(MONSTERTABLE); end;
1585 function g_Mons_TypeIdByName (const name: String): Integer;
1586 var
1587 i: Integer;
1588 begin
1589 i := MONSTER_DEMON;
1590 while (i <= MONSTER_MAN) do
1591 begin
1592 if (CompareText(name, MONSTERTABLE[i].Name) = 0) then
1593 begin
1594 result := i;
1595 exit;
1596 end;
1597 Inc(i);
1598 end;
1599 result := -1;
1600 // HACK!
1601 if (CompareText(name, 'zombie') = 0) then result := MONSTER_ZOMBY;
1602 end;
1605 function g_Mons_NameByTypeId (monType: Integer): AnsiString;
1606 begin
1607 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1608 result := MONSTERTABLE[monType].Name
1609 else
1610 result := '?';
1611 end;
1614 function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
1615 begin
1616 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1617 Result := KilledByMonster[monType]
1618 else
1619 Result := '?';
1620 end;
1623 // ////////////////////////////////////////////////////////////////////////// //
1624 { T M o n s t e r : }
1626 procedure TMonster.setGameX (v: Integer); inline; begin FObj.X := v; positionChanged(); end;
1627 procedure TMonster.setGameY (v: Integer); inline; begin FObj.Y := v; positionChanged(); end;
1629 procedure TMonster.setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline; begin FObj.X := ax; FObj.Y := ay; if callPosChanged then positionChanged(); end;
1631 procedure TMonster.moveBy (dx, dy: Integer); inline;
1632 begin
1633 if (dx <> 0) or (dy <> 0) then
1634 begin
1635 FObj.X += dx;
1636 FObj.Y += dy;
1637 positionChanged();
1638 end;
1639 end;
1641 procedure TMonster.doDamage (v: Integer);
1642 begin
1643 if (v <= 0) then exit;
1644 if (v > 32767) then v := 32767;
1645 Damage(v, 0, 0, 0, mEDamageType);
1646 end;
1648 procedure TMonster.ActionSound();
1649 begin
1650 case FMonsterType of
1651 MONSTER_IMP:
1652 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ACTION', FObj.X, FObj.Y);
1653 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN,
1654 MONSTER_MANCUB:
1655 g_Sound_PlayExAt('SOUND_MONSTER_ACTION', FObj.X, FObj.Y);
1656 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1657 MONSTER_KNIGHT, MONSTER_PAIN, MONSTER_DEMON,
1658 MONSTER_SPIDER:
1659 g_Sound_PlayExAt('SOUND_MONSTER_ACTION2', FObj.X, FObj.Y);
1660 MONSTER_BSP:
1661 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ACTION', FObj.X, FObj.Y);
1662 MONSTER_VILE:
1663 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ACTION', FObj.X, FObj.Y);
1664 MONSTER_SKEL:
1665 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ACTION', FObj.X, FObj.Y);
1666 MONSTER_CYBER:
1668 MONSTER_MAN:
1669 g_Sound_PlayExAt('SOUND_MONSTER_HAHA', FObj.X, FObj.Y);
1670 end;
1671 end;
1673 procedure TMonster.PainSound();
1674 begin
1675 if FPainSound then
1676 Exit;
1678 FPainSound := True;
1679 FPainTicks := 20;
1681 case FMonsterType of
1682 MONSTER_IMP, MONSTER_ZOMBY, MONSTER_SERG,
1683 MONSTER_SKEL, MONSTER_CGUN:
1684 g_Sound_PlayExAt('SOUND_MONSTER_PAIN', FObj.X, FObj.Y);
1685 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1686 MONSTER_KNIGHT, MONSTER_DEMON, MONSTER_SPIDER,
1687 MONSTER_BSP, MONSTER_CYBER:
1688 g_Sound_PlayExAt('SOUND_MONSTER_PAIN2', FObj.X, FObj.Y);
1689 MONSTER_VILE:
1690 g_Sound_PlayExAt('SOUND_MONSTER_VILE_PAIN', FObj.X, FObj.Y);
1691 MONSTER_MANCUB:
1692 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_PAIN', FObj.X, FObj.Y);
1693 MONSTER_PAIN:
1694 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_PAIN', FObj.X, FObj.Y);
1695 MONSTER_MAN:
1696 g_Sound_PlayExAt('SOUND_MONSTER_MAN_PAIN', FObj.X, FObj.Y);
1697 end;
1698 end;
1700 procedure TMonster.DieSound();
1701 begin
1702 case FMonsterType of
1703 MONSTER_IMP:
1704 case Random(2) of
1705 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_1', FObj.X, FObj.Y);
1706 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_2', FObj.X, FObj.Y);
1707 end;
1708 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1709 case Random(3) of
1710 0: g_Sound_PlayExAt('SOUND_MONSTER_DIE_1', FObj.X, FObj.Y);
1711 1: g_Sound_PlayExAt('SOUND_MONSTER_DIE_2', FObj.X, FObj.Y);
1712 2: g_Sound_PlayExAt('SOUND_MONSTER_DIE_3', FObj.X, FObj.Y);
1713 end;
1714 MONSTER_DEMON:
1715 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_DIE', FObj.X, FObj.Y);
1716 MONSTER_BARREL:
1717 g_Sound_PlayExAt('SOUND_MONSTER_BARREL_DIE', FObj.X, FObj.Y);
1718 MONSTER_SOUL:
1719 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_DIE', FObj.X, FObj.Y);
1720 MONSTER_BSP:
1721 g_Sound_PlayExAt('SOUND_MONSTER_BSP_DIE', FObj.X, FObj.Y);
1722 MONSTER_VILE:
1723 g_Sound_PlayExAt('SOUND_MONSTER_VILE_DIE', FObj.X, FObj.Y);
1724 MONSTER_BARON:
1725 g_Sound_PlayExAt('SOUND_MONSTER_BARON_DIE', FObj.X, FObj.Y);
1726 MONSTER_CACO:
1727 g_Sound_PlayExAt('SOUND_MONSTER_CACO_DIE', FObj.X, FObj.Y);
1728 MONSTER_CYBER:
1729 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_DIE', FObj.X, FObj.Y);
1730 MONSTER_KNIGHT:
1731 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_DIE', FObj.X, FObj.Y);
1732 MONSTER_MANCUB:
1733 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_DIE', FObj.X, FObj.Y);
1734 MONSTER_PAIN:
1735 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_DIE', FObj.X, FObj.Y);
1736 MONSTER_SKEL:
1737 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_DIE', FObj.X, FObj.Y);
1738 MONSTER_SPIDER:
1739 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_DIE', FObj.X, FObj.Y);
1740 MONSTER_MAN:
1741 g_Sound_PlayExAt('SOUND_MONSTER_MAN_DIE', FObj.X, FObj.Y);
1742 end;
1743 end;
1745 procedure TMonster.WakeUpSound();
1746 begin
1747 case FMonsterType of
1748 MONSTER_IMP:
1749 case Random(2) of
1750 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_1', FObj.X, FObj.Y);
1751 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_2', FObj.X, FObj.Y);
1752 end;
1753 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1754 case Random(3) of
1755 0: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_1', FObj.X, FObj.Y);
1756 1: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_2', FObj.X, FObj.Y);
1757 2: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_3', FObj.X, FObj.Y);
1758 end;
1759 MONSTER_MAN:
1760 g_Sound_PlayExAt('SOUND_MONSTER_MAN_ALERT', FObj.X, FObj.Y);
1761 MONSTER_BSP:
1762 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ALERT', FObj.X, FObj.Y);
1763 MONSTER_VILE:
1764 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ALERT', FObj.X, FObj.Y);
1765 MONSTER_BARON:
1766 g_Sound_PlayExAt('SOUND_MONSTER_BARON_ALERT', FObj.X, FObj.Y);
1767 MONSTER_CACO:
1768 g_Sound_PlayExAt('SOUND_MONSTER_CACO_ALERT', FObj.X, FObj.Y);
1769 MONSTER_CYBER:
1770 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_ALERT', FObj.X, FObj.Y);
1771 MONSTER_KNIGHT:
1772 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_ALERT', FObj.X, FObj.Y);
1773 MONSTER_MANCUB:
1774 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ALERT', FObj.X, FObj.Y);
1775 MONSTER_PAIN:
1776 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_ALERT', FObj.X, FObj.Y);
1777 MONSTER_DEMON:
1778 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ALERT', FObj.X, FObj.Y);
1779 MONSTER_SKEL:
1780 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ALERT', FObj.X, FObj.Y);
1781 MONSTER_SPIDER:
1782 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_ALERT', FObj.X, FObj.Y);
1783 MONSTER_SOUL:
1785 end;
1786 end;
1788 procedure TMonster.BFGHit();
1789 begin
1790 if FMonsterType = MONSTER_FISH then
1791 Exit;
1793 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1794 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1795 {if g_Game_IsServer and g_Game_IsNet then
1796 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1797 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1798 0, NET_GFX_BFG);}
1799 end;
1801 function TMonster.Collide(X, Y: Integer; Width, Height: Word): Boolean;
1802 begin
1803 Result := g_Collide(FObj.X+FObj.Rect.X,
1804 FObj.Y+FObj.Rect.Y,
1805 FObj.Rect.Width,
1806 FObj.Rect.Height,
1807 X, Y,
1808 Width, Height);
1809 end;
1811 function TMonster.Collide(Panel: TPanel): Boolean;
1812 begin
1813 Result := g_Collide(FObj.X+FObj.Rect.X,
1814 FObj.Y+FObj.Rect.Y,
1815 FObj.Rect.Width,
1816 FObj.Rect.Height,
1817 Panel.X, Panel.Y,
1818 Panel.Width, Panel.Height);
1819 end;
1821 function TMonster.Collide(X, Y: Integer): Boolean;
1822 begin
1823 X := X - FObj.X - FObj.Rect.X;
1824 Y := Y - FObj.Y - FObj.Rect.Y;
1825 Result := (x >= 0) and (x <= FObj.Rect.Width) and
1826 (y >= 0) and (y <= FObj.Rect.Height);
1827 end;
1829 procedure TMonster.Respawn;
1830 begin
1831 FObj.Vel.X := 0;
1832 FObj.Vel.Y := 0;
1833 FObj.Accel.X := 0;
1834 FObj.Accel.Y := 0;
1835 FDirection := FStartDirection;
1836 {GameX}FObj.X := FStartX;
1837 {GameY}FObj.Y := FStartY;
1838 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
1839 FHealth := MONSTERTABLE[FMonsterType].Health;
1840 FAmmo := 0;
1841 FPain := 0;
1842 FTargetUID := 0;
1843 FTargetTime := 0;
1844 FDieTriggers := nil;
1845 FWaitAttackAnim := False;
1846 FChainFire := False;
1847 FShellTimer := -1;
1849 FState := MONSTATE_SLEEP;
1850 FCurAnim := ANIM_SLEEP;
1852 positionChanged(); // this updates spatial accelerators
1854 if g_Game_IsNet and g_Game_IsServer then
1855 begin
1856 MH_SEND_MonsterPos(FUID);
1857 MH_SEND_MonsterState(FUID);
1858 end;
1859 end;
1861 constructor TMonster.Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
1862 var
1863 a: Integer;
1864 FramesID: DWORD = 0;
1865 s: String;
1866 res: Boolean;
1867 begin
1868 if ForcedUID < 0 then
1869 FUID := g_CreateUID(UID_MONSTER)
1870 else
1871 FUID := ForcedUID;
1873 FMonsterType := MonsterType;
1875 g_Obj_Init(@FObj);
1877 FState := MONSTATE_SLEEP;
1878 FCurAnim := ANIM_SLEEP;
1879 FHealth := MONSTERTABLE[MonsterType].Health;
1880 FMaxHealth := FHealth;
1881 FObj.Rect := MONSTERTABLE[MonsterType].Rect;
1882 FDieTriggers := nil;
1883 FSpawnTrigger := -1;
1884 FWaitAttackAnim := False;
1885 FChainFire := False;
1886 FStartID := aID;
1887 FNoRespawn := False;
1888 FShellTimer := -1;
1889 FBehaviour := BH_NORMAL;
1890 FFireTime := 0;
1891 FFirePainTime := 0;
1892 FFireAttacker := 0;
1893 mEDamageType := HIT_SOME;
1895 mProxyId := -1;
1896 mArrIdx := -1;
1897 trapCheckFrameId := 0;
1898 mplatCheckFrameId := 0;
1899 mNeedSend := false;
1901 if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
1902 FBloodKind := BLOOD_SPARKS
1903 else
1904 FBloodKind := BLOOD_NORMAL;
1905 if FMonsterType = MONSTER_CACO then
1906 begin
1907 FBloodRed := 0;
1908 FBloodGreen := 0;
1909 FBloodBlue := 150;
1910 end
1911 else if FMonsterType in [MONSTER_BARON, MONSTER_KNIGHT] then
1912 begin
1913 FBloodRed := 0;
1914 FBloodGreen := 150;
1915 FBloodBlue := 0;
1916 end
1917 else
1918 begin
1919 FBloodRed := 150;
1920 FBloodGreen := 0;
1921 FBloodBlue := 0;
1922 end;
1924 SetLength(FAnim, Length(ANIMTABLE));
1926 for a := 0 to High(FAnim) do
1927 begin
1928 FAnim[a, TDirection.D_LEFT] := nil;
1929 FAnim[a, TDirection.D_RIGHT] := nil;
1930 end;
1932 for a := ANIM_SLEEP to ANIM_PAIN do
1933 if (ANIMTABLE[a].name <> '') and
1934 (MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a] <> 0) then
1935 begin
1936 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1937 '_'+ANIMTABLE[a].name;
1939 res := g_Frames_Exists(s);
1941 if res then
1942 res := g_Frames_Get(FramesID, s);
1944 // Åñëè íåò òàêîé àíèìàöèè, òî ïðîáóåì çàìåíèòü åå íà àíèìàöèþ ñìåðòè:
1945 if (not res) then
1946 begin
1947 // Çàìåíÿåì òîëüêî ANIM_MESS íà ANIM_DIE:
1948 if a <> ANIM_MESS then
1949 Continue;
1951 if g_Frames_Get(FramesID, 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1952 '_'+ANIMTABLE[ANIM_DIE].name) then
1953 begin
1954 FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1955 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1956 FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1957 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1958 Continue;
1959 end;
1960 end;
1962 FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1963 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1965 // Åñëè åñòü îòäåëüíàÿ ëåâàÿ àíèìàöèÿ - çàãðóæàåì:
1966 if MONSTER_ANIMTABLE[MonsterType].LeftAnim then
1967 begin
1968 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1969 '_'+ANIMTABLE[a].name+'_L';
1970 if g_Frames_Exists(s) then
1971 g_Frames_Get(FramesID, s);
1972 end;
1974 FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1975 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1976 end;
1978 // Äëÿ êîëäóíà çàãðóæàåì òàêæå àíèìàöèþ îãíÿ:
1979 if MonsterType = MONSTER_VILE then
1980 begin
1981 g_Frames_Get(FramesID, 'FRAMES_FIRE');
1982 vilefire := TAnimation.Create(FramesID, True, 2);
1983 end
1984 else
1985 vilefire := nil;
1986 end;
1988 function TMonster.Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
1989 var
1990 c, it: Integer;
1991 p: TPlayer;
1992 begin
1993 Result := False;
1995 // Óìèðàåò, óìåð èëè âîñêðåøàåòñÿ => óðîí äåëàòü íåêîìó:
1996 if (FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE) or (FState = MONSTATE_REVIVE) then
1997 Exit;
1999 // Ðûáó â âîäå áüåò òîêîì => ïàíèêà áåç óðîíà:
2000 if (t = HIT_ELECTRO) and (FMonsterType = MONSTER_FISH) and g_Game_IsServer then
2001 begin
2002 FSleep := 20;
2003 if Random(2) = 0 then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
2004 Result := True;
2005 SetState(MONSTATE_RUN);
2006 Exit;
2007 end;
2009 // Ëîâóøêà óáèâàåò ñðàçó:
2010 if t = HIT_TRAP then
2011 FHealth := -100;
2013 // Ðîáîòó óðîíà íåò:
2014 if FMonsterType = MONSTER_ROBO then
2015 aDamage := 0;
2017 // Íàíîñèì óðîí:
2018 if g_Game_IsServer then Dec(FHealth, aDamage);
2020 // Óñèëèâàåì áîëü ìîíñòðà îò óðîíà:
2021 if FPain = 0 then
2022 FPain := 3;
2023 FPain := FPain+aDamage;
2025 // Åñëè áîëü ñóùåñòâåííàÿ, òî ìåíÿåì ñîñòîÿíèå íà áîëåâîå:
2026 if FState <> MONSTATE_PAIN then
2027 if (FPain >= MONSTERTABLE[FMonsterType].MinPain) and
2028 (FMonsterType <> MONSTER_BARREL) then
2029 SetState(MONSTATE_PAIN);
2031 // Åñëè ðàçðåøåíà êðîâü - ñîçäàåì áðûçãè êðîâè:
2032 if (gBloodCount > 0) then
2033 begin
2034 c := Min(aDamage, 200);
2035 c := c*gBloodCount - (aDamage div 4) + Random(c div 2);
2037 if (VelX = 0) and (VelY = 0) then
2038 MakeBloodSimple(c)
2039 else
2040 case t of
2041 HIT_TRAP, HIT_ACID, HIT_ELECTRO, HIT_FLAME: MakeBloodSimple(c);
2042 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, VelX, VelY);
2043 end;
2044 end;
2046 // Òåïåðü öåëü - óäàðèâøèé, åñëè òîëüêî íå ñàì ñåáÿ:
2047 if (SpawnerUID <> FUID) and (BehaviourDamage(SpawnerUID, FBehaviour, FMonsterType)) then
2048 begin
2049 FTargetUID := SpawnerUID;
2050 FTargetTime := 0;
2051 end;
2053 // Çäîðîâüå çàêîí÷èëîñü:
2054 if FHealth <= 0 then
2055 begin
2056 // Åñëè ýòî íå áî÷êà è óáèë èãðîê, òî åìó +1:
2057 if (FMonsterType <> MONSTER_BARREL) then
2058 begin
2059 if (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2060 begin
2061 p := g_Player_Get(SpawnerUID);
2062 if (p <> nil) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2063 begin
2064 p.MonsterKills := p.MonsterKills+1;
2065 if gGameSettings.GameMode = GM_COOP then
2066 p.Frags := p.Frags + 1;
2067 // Uncomment this if you want to double-kill monsters
2068 //p.FragCombo();
2069 end;
2070 end;
2071 if gLMSRespawn = LMS_RESPAWN_NONE then
2072 begin
2073 Inc(gCoopMonstersKilled);
2074 if g_Game_IsNet then
2075 MH_SEND_GameStats;
2076 end;
2077 end;
2079 // Âûáèðàåì ëóò:
2080 case FMonsterType of
2081 MONSTER_ZOMBY: c := ITEM_AMMO_BULLETS;
2082 MONSTER_SERG: c := ITEM_WEAPON_SHOTGUN1;
2083 MONSTER_CGUN: c := ITEM_WEAPON_CHAINGUN;
2084 MONSTER_MAN: c := ITEM_KEY_RED;
2085 else c := 0;
2086 end;
2088 // Áðîñàåì ëóò:
2089 if c <> 0 then
2090 begin
2091 it := g_Items_Create(FObj.X + (FObj.Rect.Width div 2),
2092 FObj.Y + (FObj.Rect.Height div 2),
2093 c, True, False);
2094 g_Items_SetDrop(it); // mark it as monster drop
2095 g_Obj_Push(g_Items_ObjByIdx(it), (FObj.Vel.X div 2)-3+Random(7),
2096 (FObj.Vel.Y div 2)-Random(4));
2097 //positionChanged(); // this updates spatial accelerators
2098 if g_Game_IsServer and g_Game_IsNet then
2099 MH_SEND_ItemSpawn(True, it);
2100 end;
2102 // Òðóï äàëüøå íå èäåò:
2103 FObj.Vel.X := 0;
2105 // Ó òðóïà ðàçìåðû ìåíüøå:
2106 if (FMonsterType <> MONSTER_FISH) and (FMonsterType <> MONSTER_PAIN) then
2107 begin
2108 FObj.Rect.Y := FObj.Rect.Y + FObj.Rect.Height-12;
2109 FObj.Rect.Height := 12;
2110 positionChanged();
2111 end;
2113 // Óðîí áûë ñèëüíûì => ñëàáûå - â êàøó:
2114 if (FHealth <= -30) and
2115 ((FMonsterType = MONSTER_IMP) or (FMonsterType = MONSTER_ZOMBY) or
2116 (FMonsterType = MONSTER_SERG) or (FMonsterType = MONSTER_CGUN) or
2117 (FMonsterType = MONSTER_MAN)) then
2118 begin
2119 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
2120 SetState(MONSTATE_DIE, ANIM_MESS);
2121 end
2122 else
2123 begin
2124 DieSound();
2125 SetState(MONSTATE_DIE);
2126 end;
2128 // Àêòèâèðîâàòü òðèããåðû, æäóùèå ñìåðòè ýòîãî ìîíñòðà:
2129 if g_Game_IsServer then ActivateTriggers();
2131 FHealth := 0;
2132 end
2133 else
2134 if FState = MONSTATE_SLEEP then
2135 begin // Ñïàë, ðàçáóäèëè íåñìåðòåëüíûì óäàðîì:
2136 FPain := MONSTERTABLE[FMonsterType].Pain;
2137 SetState(MONSTATE_GO);
2138 end;
2140 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
2141 Result := True;
2142 end;
2144 function TMonster.Heal(Value: Word): Boolean;
2145 begin
2146 Result := False;
2147 if g_Game_IsClient then
2148 Exit;
2149 if not alive then
2150 Exit;
2152 if FHealth < FMaxHealth then
2153 begin
2154 IncMax(FHealth, Value, FMaxHealth);
2155 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
2156 Result := True;
2157 end;
2158 end;
2160 destructor TMonster.Destroy();
2161 var
2162 a: Integer;
2163 begin
2164 for a := 0 to High(FAnim) do
2165 begin
2166 FAnim[a, TDirection.D_LEFT].Free();
2167 FAnim[a, TDirection.D_RIGHT].Free();
2168 end;
2170 vilefire.Free();
2172 if (mProxyId <> -1) then
2173 begin
2174 if (monsGrid <> nil) then
2175 begin
2176 monsGrid.removeBody(mProxyId);
2177 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
2178 e_WriteLog(Format('monster #%d:(%u): removed from grid; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
2179 {$ENDIF}
2180 end;
2181 mProxyId := -1;
2182 end;
2184 if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then
2185 begin
2186 freeInds.release(mArrIdx);
2187 gMonsters[mArrIdx] := nil;
2188 end;
2189 mArrIdx := -1;
2191 uidMap[FUID] := nil;
2193 inherited Destroy();
2194 end;
2196 procedure TMonster.Draw();
2197 var
2198 m: TMirrorType;
2199 dx, dy, c: Integer;
2200 o: TObj;
2201 begin
2202 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, 'TYPE: '+IntToStr(FMonsterType));
2203 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y+16, 'STATE: '+IntToStr(FState));
2205 // Åñëè êîëäóí ñòðåëÿåò, òî ðèñóåì îãîíü:
2206 if FMonsterType = MONSTER_VILE then
2207 if FState = MONSTATE_SHOOT then
2208 if GetPos(FTargetUID, @o) then
2209 vilefire.Draw(o.X+o.Rect.X+(o.Rect.Width div 2)-32,
2210 o.Y+o.Rect.Y+o.Rect.Height-128, TMirrorType.None);
2212 // Íå â îáëàñòè ðèñîâàíèÿ íå ðåñóåì:
2213 //FIXME!
2214 if (g_dbg_scale = 1.0) then
2215 begin
2216 if not g_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height,
2217 sX-128, sY-128, sWidth+256, sHeight+256) then
2218 Exit;
2219 end;
2221 // Ýòè ìîíñòðû, óìèðàÿ, íå îñòàâëÿþò òðóïîâ:
2222 if FState = MONSTATE_DEAD then
2223 case FMonsterType of
2224 MONSTER_BARREL, MONSTER_SOUL, MONSTER_PAIN: Exit;
2225 end;
2227 // Åñòü ÷òî ðèñîâàòü ïðè òåêóùåì ïîâåäåíèè:
2228 if FAnim[FCurAnim, FDirection] <> nil then
2229 begin
2230 // Åñëè íåò ëåâîé àíèìàöèè èëè îíà ñîâïàäàåò ñ ïðàâîé => îòðàæàåì ïðàâóþ:
2231 if (FDirection = TDirection.D_LEFT) and
2232 ((not MONSTER_ANIMTABLE[FMonsterType].LeftAnim) or
2233 (FAnim[FCurAnim, TDirection.D_LEFT].FramesID = FAnim[FCurAnim, TDirection.D_RIGHT].FramesID)) and
2234 (FMonsterType <> MONSTER_BARREL) then
2235 m := TMirrorType.Horizontal
2236 else
2237 m := TMirrorType.None;
2239 // Ëåâàÿ àíèìàöèÿ => ìåíÿåì ñìåùåíèå îòíîñèòåëüíî öåíòðà:
2240 if (FDirection = TDirection.D_LEFT) and
2241 (FMonsterType <> MONSTER_BARREL) then
2242 begin
2243 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].X;
2244 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].Y;
2246 if m = TMirrorType.Horizontal then
2247 begin // Íåò îòäåëüíîé ëåâîé àíèìàöèè
2248 // Ðàññòîÿíèå îò êðàÿ òåêñòóðû äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2249 c := (MONSTERTABLE[FMonsterType].Rect.X - dx) + MONSTERTABLE[FMonsterType].Rect.Width;
2250 // Ðàññòîÿíèå îò êðàÿ õèò áîêñà äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2251 dx := FAnim[FCurAnim, FDirection].Width - c - MONSTERTABLE[FMonsterType].Rect.X;
2252 // Ò.ê. äâèãàòü òåêñòóðó íóæíî áóäåò â ïðîòèâîïîëîæíîì íàïðàâëåíèè:
2253 dx := -dx;
2254 // Ýòî çíà÷èò: dX := -frameWidth - animDeltaX + hitX + hitWidth + hitX
2255 end;
2256 end
2257 else // Ïðàâàÿ àíèìàöèÿ
2258 begin
2259 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].X;
2260 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].Y;
2261 end;
2263 // Ðèñóåì:
2264 FAnim[FCurAnim, FDirection].Draw(Obj.X+dx, Obj.Y+dy, m);
2265 end;
2267 if g_debug_Frames then
2268 begin
2269 e_DrawQuad(FObj.X+FObj.Rect.X,
2270 FObj.Y+FObj.Rect.Y,
2271 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2272 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2273 0, 255, 0);
2274 end;
2275 end;
2277 procedure TMonster.MakeBloodSimple(Count: Word);
2278 begin
2279 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)+8,
2280 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2281 Count div 2, 3, -1, 16, (FObj.Rect.Height*2 div 3),
2282 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2283 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-8,
2284 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2285 Count div 2, -3, -1, 16, (FObj.Rect.Height*2) div 3,
2286 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2287 end;
2289 procedure TMonster.MakeBloodVector(Count: Word; VelX, VelY: Integer);
2290 begin
2291 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2292 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2293 Count, VelX, VelY, 16, (FObj.Rect.Height*2) div 3,
2294 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2295 end;
2297 procedure TMonster.Push(vx, vy: Integer);
2298 begin
2299 FObj.Accel.X := FObj.Accel.X + vx;
2300 FObj.Accel.Y := FObj.Accel.Y + vy;
2301 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2302 end;
2304 procedure TMonster.SetState(State: Byte; ForceAnim: Byte = 255);
2305 var
2306 Anim: Byte;
2307 begin
2308 // Åñëè ñîñòîÿíèå = íà÷àëè óìèðàòü, à ýòîò ìîíñòð = Lost_Soul,
2309 // òî ñîáëþäàåì îãðàíè÷åíèå êîëè÷åñòâà Lost_Soul'îâ:
2310 if (State = MONSTATE_DIE) and (MonsterType = MONSTER_SOUL) then
2311 soulcount := soulcount-1;
2313 // Ïðèñìåðòè - íåëüçÿ ñðàçó íà÷èíàòü àòàêîâàòü èëè áåãàòü:
2314 case FState of
2315 MONSTATE_DIE, MONSTATE_DEAD, MONSTATE_REVIVE:
2316 if (State <> MONSTATE_DEAD) and (State <> MONSTATE_REVIVE) and
2317 (State <> MONSTATE_GO) then
2318 Exit;
2319 end;
2321 // Ñìåíà ñîñòîÿíèÿ:
2322 FState := State;
2324 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID, ForceAnim);
2326 // Íîâàÿ àíèìàöèÿ ïðè íîâîì ñîñòîÿíèè:
2327 case FState of
2328 MONSTATE_SLEEP: Anim := ANIM_SLEEP;
2329 MONSTATE_PAIN: Anim := ANIM_PAIN;
2330 MONSTATE_WAIT: Anim := ANIM_SLEEP;
2331 MONSTATE_CLIMB, MONSTATE_RUN, MONSTATE_RUNOUT, MONSTATE_GO: Anim := ANIM_GO;
2332 MONSTATE_SHOOT: Anim := ANIM_ATTACK;
2333 MONSTATE_ATTACK: Anim := ANIM_ATTACK;
2334 MONSTATE_DIE: Anim := ANIM_DIE;
2335 MONSTATE_REVIVE:
2336 begin // íà÷àëè âîñðåøàòüñÿ
2337 Anim := FCurAnim;
2338 FAnim[Anim, FDirection].Revert(True);
2340 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
2341 FHealth := MONSTERTABLE[FMonsterType].Health;
2342 FAmmo := 0;
2343 FPain := 0;
2344 end;
2345 else Exit;
2346 end;
2348 // Íàäî ñìåíèòü àíèìàöèþ íà íåñòàíäàðòíóþ:
2349 if ForceAnim <> 255 then
2350 Anim := ForceAnim;
2352 // Åñëè àíèìàöèÿ íîâàÿ - ïåðåçàïóñêàåì å¸:
2353 if FCurAnim <> Anim then
2354 if FAnim[Anim, FDirection] <> nil then
2355 begin
2356 FAnim[Anim, FDirection].Reset();
2357 FCurAnim := Anim;
2358 end;
2359 end;
2361 function TMonster.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
2362 var
2363 TA: TAnimation;
2364 FramesID: DWORD;
2365 begin
2366 Result := False;
2368 //  òî÷êå íàçíà÷åíèÿ ñòåíà:
2369 if g_CollideLevel(X, Y, FObj.Rect.Width, FObj.Rect.Height) then
2370 begin
2371 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
2372 if g_Game_IsServer and g_Game_IsNet then
2373 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
2374 Exit;
2375 end;
2377 TA := nil;
2379 // Ýôôåêò òåëåïîðòà â ïîçèöèè ìîíñòðà:
2380 if not silent then
2381 begin
2382 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
2383 TA := TAnimation.Create(FramesID, False, 6);
2384 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', Obj.X, Obj.Y);
2385 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2386 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2388 if g_Game_IsServer and g_Game_IsNet then
2389 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2390 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 1,
2391 NET_GFX_TELE);
2392 end;
2394 FObj.X := X - FObj.Rect.X;
2395 FObj.Y := Y - FObj.Rect.Y;
2396 positionChanged();
2398 if dir = 1 then
2399 FDirection := TDirection.D_LEFT
2400 else
2401 if dir = 2 then
2402 FDirection := TDirection.D_RIGHT
2403 else
2404 if dir = 3 then
2405 begin // îáðàòíîå
2406 if FDirection = TDirection.D_RIGHT then
2407 FDirection := TDirection.D_LEFT
2408 else
2409 FDirection := TDirection.D_RIGHT;
2410 end;
2412 // Ýôôåêò òåëåïîðòà â òî÷êå íàçíà÷åíèÿ:
2413 if not silent and (TA <> nil) then
2414 begin
2415 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2416 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2417 TA.Free();
2419 if g_Game_IsServer and g_Game_IsNet then
2420 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2421 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 0,
2422 NET_GFX_TELE);
2423 end;
2425 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2426 Result := True;
2427 end;
2429 procedure TMonster.Update();
2430 var
2431 a, b, sx, sy, wx, wy, oldvelx: Integer;
2432 st: Word;
2433 o, co: TObj;
2434 fall: Boolean;
2435 mon: TMonster;
2436 label
2437 _end;
2438 begin
2439 fall := True;
2441 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
2442 if FMonsterType = MONSTER_FISH then
2443 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
2444 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2445 fall := False;
2447 // Ëåòàþùèå ìîíòñðû:
2448 if ((FMonsterType = MONSTER_SOUL) or
2449 (FMonsterType = MONSTER_PAIN) or
2450 (FMonsterType = MONSTER_CACO)) and
2451 (FState <> MONSTATE_DIE) and
2452 (FState <> MONSTATE_DEAD) then
2453 fall := False;
2455 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
2456 if gTime mod (GAME_TICK*2) <> 0 then
2457 begin
2458 g_Obj_Move(@FObj, fall, True, True);
2459 positionChanged(); // this updates spatial accelerators
2460 Exit;
2461 end;
2463 if FPainTicks > 0 then
2464 Dec(FPainTicks)
2465 else
2466 FPainSound := False;
2468 // Äâèãàåìñÿ:
2469 st := g_Obj_Move(@FObj, fall, True, True);
2470 positionChanged(); // this updates spatial accelerators
2472 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
2473 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
2474 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
2475 begin
2476 FRemoved := True;
2477 if alive and (gLMSRespawn = LMS_RESPAWN_NONE) then
2478 begin
2479 Inc(gCoopMonstersKilled);
2480 if g_Game_IsNet then
2481 MH_SEND_GameStats;
2482 end;
2483 ActivateTriggers();
2484 Exit;
2485 end;
2487 oldvelx := FObj.Vel.X;
2489 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
2490 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
2491 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
2493 if FFireTime > 0 then
2494 begin
2495 if WordBool(st and MOVE_INWATER) then
2496 FFireTime := 0
2497 else
2498 begin
2499 OnFireFlame(1);
2500 FFireTime := FFireTime - 1;
2501 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2502 if FFirePainTime = 0 then
2503 begin
2504 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
2505 FFirePainTime := 18;
2506 end
2507 else
2508 FFirePainTime := FFirePainTime - 1;
2509 end;
2510 end;
2512 // Ìåðòâûé íè÷åãî íå äåëàåò:
2513 if (FState = MONSTATE_DEAD) then
2514 goto _end;
2516 // AI ìîíñòðîâ âûêëþ÷åí:
2517 if g_debug_MonsterOff then
2518 begin
2519 FSleep := 1;
2520 if FState <> MONSTATE_SLEEP then
2521 SetState(MONSTATE_SLEEP);
2522 end;
2524 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
2525 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
2526 case FMonsterType of
2527 MONSTER_FISH:
2528 if Random(4) = 0 then
2529 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2530 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2531 MONSTER_ROBO, MONSTER_BARREL:
2532 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2533 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2534 else begin
2535 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
2536 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
2537 if Random(2) = 0 then
2538 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
2539 else
2540 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
2541 end;
2542 end;
2544 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
2545 if FMonsterType = MONSTER_BARREL then
2546 begin
2547 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
2548 (FAnim[FCurAnim, FDirection].Counter = 0) then
2549 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2550 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
2551 60, FUID);
2552 end;
2554 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
2555 if FMonsterType = MONSTER_SOUL then
2556 if WordBool(st and MOVE_HITAIR) then
2557 g_Obj_SetSpeed(@FObj, 16);
2559 if FAmmo < 0 then
2560 FAmmo := FAmmo + 1;
2562 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
2563 if FObj.Vel.Y < 0 then
2564 if WordBool(st and MOVE_INWATER) then
2565 FObj.Vel.Y := -4;
2567 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
2568 FTargetTime := FTargetTime + 1;
2570 // Ãèëüçû
2571 if FShellTimer > -1 then
2572 if FShellTimer = 0 then
2573 begin
2574 if FShellType = SHELL_SHELL then
2575 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2576 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2577 GameVelX, GameVelY-2, SHELL_SHELL)
2578 else if FShellType = SHELL_DBLSHELL then
2579 begin
2580 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2581 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2582 GameVelX-1, GameVelY-2, SHELL_SHELL);
2583 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2584 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2585 GameVelX+1, GameVelY-2, SHELL_SHELL);
2586 end;
2587 FShellTimer := -1;
2588 end else Dec(FShellTimer);
2590 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
2591 if fall then
2592 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
2593 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
2594 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2595 FObj.Rect.Width, FObj.Rect.Height, 50) then
2596 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2597 (FObj.Accel.Y = 0) then
2598 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2600 case FState of
2601 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
2602 begin
2603 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
2604 if FPain >= MONSTERTABLE[FMonsterType].Pain then
2605 begin
2606 FPain := MONSTERTABLE[FMonsterType].Pain;
2607 if gSoundEffectsDF then PainSound();
2608 end;
2609 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
2610 PainSound();
2612 // Ñíèæàåì áîëü ñî âðåìåíåì:
2613 FPain := FPain - 5;
2615 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
2616 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
2617 begin
2618 FPain := 0;
2619 FAmmo := -9;
2620 SetState(MONSTATE_GO);
2621 end;
2622 end;
2624 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
2625 begin
2626 // Ñïèì:
2627 FSleep := FSleep + 1;
2629 // Ïðîñïàëè äîñòàòî÷íî:
2630 if FSleep >= 18 then
2631 FSleep := 0
2632 else // åùå ñïèì
2633 goto _end;
2635 // Íà èãðîêîâ èäóò òîëüêî îáû÷íûå ìîíñòðû, êèëëåðû è ìàíüÿêè
2636 if (FBehaviour = BH_NORMAL) or (FBehaviour = BH_KILLER) or (FBehaviour = BH_MANIAC) then
2637 // Åñëè åñòü èãðîê ðÿäîì, ïðîñûïàåìñÿ è èäåì ê íåìó:
2638 if (gPlayers <> nil) then
2639 for a := 0 to High(gPlayers) do
2640 if (gPlayers[a] <> nil) and (gPlayers[a].alive)
2641 and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
2642 with gPlayers[a] do
2643 if g_Look(@FObj, @Obj, FDirection) then
2644 begin
2645 FTargetUID := gPlayers[a].UID;
2646 FTargetTime := 0;
2647 WakeUpSound();
2648 SetState(MONSTATE_GO);
2649 Break;
2650 end;
2652 // Íà ìîíñòðîâ òÿíåò ìàíüÿêîâ, ïîåõàâøèõ è êàííèáàëîâ
2653 if (FTargetUID = 0) and ((FBehaviour = BH_MANIAC)
2654 or (FBehaviour = BH_INSANE) or (FBehaviour = BH_CANNIBAL)) then
2655 // Åñëè åñòü ïîäõîäÿùèé ìîíñòð ðÿäîì:
2656 if gMonsters <> nil then
2657 for a := 0 to High(gMonsters) do
2658 if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
2659 (gMonsters[a].FUID <> FUID) then
2660 begin
2661 // Ìàíüÿêè íàïàäàþò íà âñåõ ìîíñòðîâ, êðîìå äðóçåé
2662 if (FBehaviour = BH_MANIAC) and
2663 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2664 Continue;
2665 // Ïîåõàâøèå òàêæå, íî ìîãóò îáîçëèòüñÿ íà áî÷êó
2666 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL) and
2667 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2668 Continue;
2669 // Êàííèáàëû íàïàäàþò íà ñåáå ïîäîáíûõ
2670 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
2671 Continue;
2672 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
2673 begin
2674 FTargetUID := gMonsters[a].UID;
2675 FTargetTime := 0;
2676 WakeUpSound();
2677 SetState(MONSTATE_GO);
2678 Break;
2679 end;
2680 end;
2681 end;
2683 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
2684 begin
2685 // Æäåì:
2686 FSleep := FSleep - 1;
2688 // Âûæäàëè äîñòàòî÷íî - èäåì:
2689 if FSleep < 0 then
2690 SetState(MONSTATE_GO);
2691 end;
2693 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
2694 begin
2695 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2696 if WordBool(st and MOVE_BLOCK) then
2697 begin
2698 Turn();
2699 FSleep := 40;
2700 SetState(MONSTATE_RUNOUT);
2702 goto _end;
2703 end;
2705 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
2706 if (FMonsterType = MONSTER_VILE) then
2707 if isCorpse(@FObj, False) <> -1 then
2708 begin
2709 FObj.Vel.X := 0;
2710 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
2712 goto _end;
2713 end;
2715 // Öåëü ïîãèáëà èëè äàâíî æäåì:
2716 if (not GetPos(FTargetUID, @o)) or (FTargetTime > MAX_ATM) then
2717 if not findNewPrey() then
2718 begin // Íîâûõ öåëåé íåò
2719 FTargetUID := 0;
2720 o.X := FObj.X+pt_x;
2721 o.Y := FObj.Y+pt_y;
2722 o.Vel.X := 0;
2723 o.Vel.Y := 0;
2724 o.Accel.X := 0;
2725 o.Accel.Y := 0;
2726 o.Rect := _Rect(0, 0, 0, 1);
2727 end
2728 else // Íîâàÿ öåëü åñòü - áåðåì åå êîîðäèíàòû
2729 GetPos(FTargetUID, @o);
2731 // Öåëü î÷åíü áëèçêî - ïèíàåì:
2732 if g_Obj_Collide(@FObj, @o) and (FTargetUID <> 0) then
2733 begin
2734 FTargetTime := 0;
2735 if (FMonsterType <> MONSTER_CYBER) or (Random(2) = 0) then
2736 begin
2737 if kick(@o) then
2738 goto _end;
2739 end;
2740 end;
2742 // Ðàññòîÿíèå äî öåëè:
2743 sx := o.X+o.Rect.X+(o.Rect.Width div 2)-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
2744 sy := o.Y+o.Rect.Y+(o.Rect.Height div 2)-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
2746 // Ïîâîðà÷èâàåìñÿ â ñòîðîíó öåëè:
2747 if sx > 0 then
2748 FDirection := TDirection.D_RIGHT
2749 else
2750 FDirection := TDirection.D_LEFT;
2752 // Åñëè ìîíñòð óìååò ñòðåëÿòü è åñòü ïî êîìó - ñòðåëÿåì:
2753 if canShoot(FMonsterType) and (FTargetUID <> 0) then
2754 if Abs(sx) > Abs(sy) then // óãîë âûñòðåëà óäîáíûé
2755 if shoot(@o, False) then
2756 goto _end;
2758 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
2759 if Abs(sx) < 40 then
2760 if FMonsterType <> MONSTER_FISH then
2761 begin
2762 FSleep := 15;
2763 SetState(MONSTATE_RUN);
2764 if Random(2) = 0 then
2765 FDirection := TDirection.D_LEFT
2766 else
2767 FDirection := TDirection.D_RIGHT;
2769 goto _end;
2770 end;
2772 // Óïåðëèñü â ñòåíó:
2773 if WordBool(st and MOVE_HITWALL) then
2774 begin
2775 if g_Triggers_PressR(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width,
2776 FObj.Rect.Height, FUID, ACTIVATE_MONSTERPRESS) <> nil then
2777 begin // Ñìîãëè íàæàòü êíîïêó - íåáîëüøîå îæèäàíèå
2778 FSleep := 4;
2779 SetState(MONSTATE_WAIT);
2781 goto _end;
2782 end;
2784 case FMonsterType of
2785 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
2786 else // Íå ëåòàþò:
2787 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2788 (FObj.Accel.Y = 0) then
2789 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
2790 // Ïðûæîê ÷åðåç ñòåíó:
2791 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2792 SetState(MONSTATE_CLIMB);
2793 end;
2794 end;
2796 goto _end;
2797 end;
2799 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
2800 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
2801 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
2802 begin
2803 if FMonsterType = MONSTER_FISH then
2804 begin // Ðûáà
2805 if not WordBool(st and MOVE_INWATER) then
2806 begin // Ðûáà âíå âîäû:
2807 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2808 begin // "Ñòîèò" òâåðäî
2809 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
2810 if FObj.Accel.Y = 0 then FObj.Vel.Y := -6;
2811 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
2812 end;
2814 // Ðûáå áîëüíî:
2815 SetState(MONSTATE_PAIN);
2816 FPain := FPain + 50;
2817 end
2818 else // Ðûáà â âîäå
2819 begin
2820 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2821 if Abs(sy) > 8 then
2822 FObj.Vel.Y := g_basic.Sign(sy)*4
2823 else
2824 FObj.Vel.Y := 0;
2826 // Ðûáà ïëûâåò ââåðõ:
2827 if FObj.Vel.Y < 0 then
2828 if not g_Obj_CollideLiquid(@FObj, 0, -16) then
2829 begin
2830 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
2831 FObj.Vel.Y := 0;
2832 // Ïëàâàåì òóäà-ñþäà:
2833 if Random(2) = 0 then
2834 FDirection := TDirection.D_LEFT
2835 else
2836 FDirection := TDirection.D_RIGHT;
2837 FSleep := 20;
2838 SetState(MONSTATE_RUN);
2839 end;
2840 end;
2841 end
2842 else // Ëåòàþùèå ìîíñòðû
2843 begin
2844 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2845 if Abs(sy) > 8 then
2846 FObj.Vel.Y := g_basic.Sign(sy)*4
2847 else
2848 FObj.Vel.Y := 0;
2849 end;
2850 end
2851 else // "Íàçåìíûå" ìîíñòðû
2852 begin
2853 // Âîçìîæíî, ïèíàåì êóñêè:
2854 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
2855 begin
2856 b := Abs(FObj.Vel.X);
2857 if b > 1 then b := b * (Random(8 div b) + 1);
2858 for a := 0 to High(gGibs) do
2859 begin
2860 if gGibs[a].alive and
2861 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2862 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
2863 begin
2864 // Ïèíàåì êóñêè
2865 if FObj.Vel.X < 0 then
2866 begin
2867 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
2868 end
2869 else
2870 begin
2871 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
2872 end;
2873 end;
2874 end;
2875 end;
2876 // Áîññû ìîãóò ïèíàòü òðóïû:
2877 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
2878 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
2879 begin
2880 b := Abs(FObj.Vel.X);
2881 if b > 1 then b := b * (Random(8 div b) + 1);
2882 for a := 0 to High(gCorpses) do
2883 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
2884 begin
2885 co := gCorpses[a].Obj;
2886 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2887 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
2888 // Ïèíàåì òðóïû
2889 if FObj.Vel.X < 0 then
2890 gCorpses[a].Damage(b*2, -b, Random(7)) // íàëåâî
2891 else
2892 gCorpses[a].Damage(b*2, b, Random(7)); // íàïðàâî
2893 end;
2894 end;
2895 // Åñëè öåëü âûñîêî, òî, âîçìîæíî, ïðûãàåì:
2896 if sy < -40 then
2897 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2898 // ñòîèò òâåðäî
2899 if (Random(4) = 0) and (FObj.Accel.Y = 0) then
2900 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2901 end;
2903 FSleep := FSleep + 1;
2905 // Èíîãäà ðû÷èì:
2906 if FSleep >= 8 then
2907 begin
2908 FSleep := 0;
2909 if Random(8) = 0 then
2910 ActionSound();
2911 end;
2913 // Áåæèì â âûáðàííóþ ñòîðîíó:
2914 if FDirection = TDirection.D_RIGHT then
2915 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2916 else
2917 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2919 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2920 if WordBool(st and MOVE_INWATER) then
2921 FObj.Vel.X := FObj.Vel.X div 2
2922 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2923 if FMonsterType = MONSTER_FISH then
2924 FObj.Vel.X := 0;
2925 end;
2927 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
2928 begin
2929 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2930 if WordBool(st and MOVE_BLOCK) then
2931 begin
2932 Turn();
2933 FSleep := 40;
2934 SetState(MONSTATE_RUNOUT);
2936 goto _end;
2937 end;
2939 FSleep := FSleep - 1;
2941 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
2942 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
2943 begin
2944 FSleep := 0;
2945 SetState(MONSTATE_GO);
2946 // Ñòåíà - èäåì îáðàòíî:
2947 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
2948 Turn();
2949 // Èíîãäà ðû÷èì:
2950 if Random(8) = 0 then
2951 ActionSound();
2952 end;
2954 // Áåæèì â âûáðàííóþ ñòîðîíó:
2955 if FDirection = TDirection.D_RIGHT then
2956 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2957 else
2958 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2960 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2961 if WordBool(st and MOVE_INWATER) then
2962 FObj.Vel.X := FObj.Vel.X div 2
2963 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2964 if FMonsterType = MONSTER_FISH then
2965 FObj.Vel.X := 0;
2966 end;
2968 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
2969 begin
2970 // Âûøëè èç ÁëîêÌîíà:
2971 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
2972 FSleep := 0;
2974 FSleep := FSleep - 1;
2976 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
2977 if FSleep <= -18 then
2978 begin
2979 FSleep := 0;
2980 SetState(MONSTATE_GO);
2981 // Ñòåíà/ÁëîêÌîí - èäåì îáðàòíî:
2982 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
2983 Turn();
2984 // Èíîãäà ðû÷èì:
2985 if Random(8) = 0 then
2986 ActionSound();
2987 end;
2989 // Áåæèì â âûáðàííóþ ñòîðîíó:
2990 if FDirection = TDirection.D_RIGHT then
2991 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2992 else
2993 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2995 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2996 if WordBool(st and MOVE_INWATER) then
2997 FObj.Vel.X := FObj.Vel.X div 2
2998 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2999 if FMonsterType = MONSTER_FISH then
3000 FObj.Vel.X := 0;
3001 end;
3003 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
3004 begin
3005 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
3006 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
3007 (not WordBool(st and MOVE_HITWALL)) then
3008 begin
3009 FSleep := 0;
3010 SetState(MONSTATE_GO);
3012 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
3013 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3014 begin
3015 Turn();
3016 FSleep := 15;
3017 SetState(MONSTATE_RUN);
3018 end;
3019 end;
3021 // Áåæèì â âûáðàííóþ ñòîðîíó:
3022 if FDirection = TDirection.D_RIGHT then
3023 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3024 else
3025 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3027 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3028 if WordBool(st and MOVE_INWATER) then
3029 FObj.Vel.X := FObj.Vel.X div 2
3030 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3031 if FMonsterType = MONSTER_FISH then
3032 FObj.Vel.X := 0;
3033 end;
3035 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
3036 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
3037 begin
3038 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
3039 if FMonsterType = MONSTER_SOUL then
3040 begin
3041 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
3042 SetState(MONSTATE_GO);
3044 goto _end;
3045 end;
3047 // Çàìåäëÿåìñÿ ïðè àòàêå:
3048 if FMonsterType <> MONSTER_FISH then
3049 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3051 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
3052 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
3053 begin
3054 // Öåëü ïîãèáëà => èäåì äàëüøå:
3055 if not GetPos(FTargetUID, @o) then
3056 begin
3057 SetState(MONSTATE_GO);
3059 goto _end;
3060 end;
3062 // Öåëü íå âèäíî => èäåì äàëüøå:
3063 if not g_Look(@FObj, @o, FDirection) then
3064 begin
3065 SetState(MONSTATE_GO);
3067 goto _end;
3068 end;
3070 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
3071 if g_Obj_CollideWater(@o, 0, 0) then
3072 begin
3073 SetState(MONSTATE_GO);
3075 goto _end;
3076 end;
3078 // Æàðèì öåëü:
3079 tx := o.X+o.Rect.X+(o.Rect.Width div 2);
3080 ty := o.Y+o.Rect.Y+(o.Rect.Height div 2);
3081 g_Weapon_HitUID(FTargetUID, 2, FUID, HIT_SOME);
3082 end;
3083 end;
3084 end; // case FState of ...
3086 _end:
3088 // Ñîñòîÿíèå - Âîñêðåøåíèå:
3089 if FState = MONSTATE_REVIVE then
3090 if FAnim[FCurAnim, FDirection].Played then
3091 begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
3092 FAnim[FCurAnim, FDirection].Revert(False);
3093 SetState(MONSTATE_GO);
3094 end;
3096 // Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
3097 if vilefire <> nil then
3098 vilefire.Update();
3100 // Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
3101 if (FState = MONSTATE_DIE) and
3102 (FAnim[FCurAnim, FDirection] <> nil) and
3103 (FAnim[FCurAnim, FDirection].Played) then
3104 begin
3105 // Óìåð:
3106 SetState(MONSTATE_DEAD);
3108 // Pain_Elemental ïðè ñìåðòè âûïóñêàåò 3 Lost_Soul'à:
3109 if (FMonsterType = MONSTER_PAIN) then
3110 begin
3111 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-30,
3112 FObj.Y+FObj.Rect.Y+20, TDirection.D_LEFT);
3113 if mon <> nil then
3114 begin
3115 mon.SetState(MONSTATE_GO);
3116 mon.FNoRespawn := True;
3117 Inc(gTotalMonsters);
3118 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3119 end;
3121 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3122 FObj.Y+FObj.Rect.Y+20, TDirection.D_RIGHT);
3123 if mon <> nil then
3124 begin
3125 mon.SetState(MONSTATE_GO);
3126 mon.FNoRespawn := True;
3127 Inc(gTotalMonsters);
3128 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3129 end;
3131 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-15,
3132 FObj.Y+FObj.Rect.Y, TDirection.D_RIGHT);
3133 if mon <> nil then
3134 begin
3135 mon.SetState(MONSTATE_GO);
3136 mon.FNoRespawn := True;
3137 Inc(gTotalMonsters);
3138 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3139 end;
3141 if g_Game_IsNet then MH_SEND_CoopStats();
3142 end;
3144 // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
3145 if (FMonsterType = MONSTER_PAIN) or
3146 (FMonsterType = MONSTER_SOUL) or
3147 (FMonsterType = MONSTER_BARREL) then
3148 FRemoved := True;
3149 end;
3151 // Ñîâåðøåíèå àòàêè è ñòðåëüáû:
3152 if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
3153 if (FAnim[FCurAnim, FDirection] <> nil) then
3154 // Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
3155 if (FAnim[FCurAnim, FDirection].Played) then
3156 begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
3157 if FState = MONSTATE_ATTACK then
3158 begin // Ñîñòîÿíèå - Àòàêà
3159 // Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
3160 if FMonsterType <> MONSTER_SOUL then
3161 SetState(MONSTATE_GO);
3162 end
3163 else // Ñîñòîÿíèå - Ñòðåëüáà
3164 begin
3165 // Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
3166 if not FChainFire then
3167 SetState(MONSTATE_GO)
3168 else
3169 begin // Íàäî ñòðåëÿòü åùå
3170 FChainFire := False;
3171 // Ò.ê. ñîñòîÿíèå íå èçìåíèëîñü, è íóæåí
3172 // íîâûé öèêë îæèäàíèÿ çàâåðøåíèÿ àíèìàöèè:
3173 FAnim[FCurAnim, FDirection].Reset();
3174 end;
3175 end;
3177 FWaitAttackAnim := False;
3178 end
3180 else // Àíèìàöèÿ àòàêè åùå èäåò (èñêëþ÷åíèå - Lost_Soul):
3181 if (FMonsterType = MONSTER_SOUL) or
3182 ( (not FWaitAttackAnim) and
3183 (FAnim[FCurAnim, FDirection].CurrentFrame =
3184 (FAnim[FCurAnim, FDirection].TotalFrames div 2))
3185 ) then
3186 begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
3187 if FState = MONSTATE_ATTACK then
3188 begin // Ñîñòîÿíèå - Àòàêà
3189 // Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
3190 if FMonsterType = MONSTER_SOUL then
3191 FAnim[FCurAnim, FDirection].Reset();
3193 case FMonsterType of
3194 MONSTER_SOUL, MONSTER_IMP, MONSTER_DEMON:
3195 // Ãðûçåì ïåðâîãî ïîïàâøåãîñÿ:
3196 if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
3197 // Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
3198 if FMonsterType = MONSTER_SOUL then
3199 SetState(MONSTATE_GO);
3201 MONSTER_FISH:
3202 // Ðûáà êóñàåò ïåðâîãî ïîïàâøåãîñÿ ñî çâóêîì:
3203 if g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME) <> 0 then
3204 g_Sound_PlayExAt('SOUND_MONSTER_FISH_ATTACK', FObj.X, FObj.Y);
3206 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
3207 // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
3208 if FCurAnim = ANIM_ATTACK2 then
3209 begin
3210 o := FObj;
3211 o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
3212 if g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME) <> 0 then
3213 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_HIT', FObj.X, FObj.Y);
3214 end;
3216 MONSTER_VILE:
3217 // Êîëäóí ïûòàåòñÿ âîñêðåøàòü:
3218 if FCurAnim = ANIM_ATTACK2 then
3219 begin
3220 sx := isCorpse(@FObj, True);
3221 if sx <> -1 then
3222 begin // Íàøëè, êîãî âîñêðåñèòü
3223 gMonsters[sx].SetState(MONSTATE_REVIVE);
3224 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
3225 // Âîñêðåøàòü - ñåáå âðåäèòü:
3226 {g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
3227 end;
3228 end;
3229 end;
3230 end
3232 else // Ñîñòîÿíèå - Ñòðåëüáà
3233 begin
3234 // Âû÷èñëÿåì êîîðäèíàòû, îòêóäà âûëåòèò ïóëÿ:
3235 wx := MONSTER_ANIMTABLE[FMonsterType].wX;
3237 if FDirection = TDirection.D_LEFT then
3238 begin
3239 wx := MONSTER_ANIMTABLE[FMonsterType].wX-(MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2));
3240 wx := MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2)-wx;
3241 end; // Ýòî çíà÷èò: wx := hitX + (hitWidth / 2) - (wx - (hitX + (hitWidth / 2)))
3243 wx := FObj.X + wx;
3244 wy := FObj.Y + MONSTER_ANIMTABLE[FMonsterType].wY;
3246 // Ìîíñòð íå ìîæåò öåëèòüñÿ â îáúåêò çà ñïèíîé, ñòðåëÿÿ âëåâî:
3247 if (FDirection = TDirection.D_LEFT) and (tx > wx) then
3248 begin
3249 tx := wx - 32;
3250 ty := wy + Random(11) - 5;
3251 end;
3252 // È àíàëîãè÷íî, ñòðåëÿÿ âïðàâî:
3253 if (FDirection = TDirection.D_RIGHT) and (tx < wx) then
3254 begin
3255 tx := wx + 32;
3256 ty := wy + Random(11) - 5;
3257 end;
3259 // Äåëàåì âûñòðåë íóæíûì îðóæèåì:
3260 case FMonsterType of
3261 MONSTER_IMP:
3262 g_Weapon_ball1(wx, wy, tx, ty, FUID);
3263 MONSTER_ZOMBY:
3264 begin
3265 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3266 g_Weapon_gun(wx, wy, tx, ty, 1, 3, FUID, True);
3267 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3268 end;
3269 MONSTER_SERG:
3270 begin
3271 g_Weapon_shotgun(wx, wy, tx, ty, FUID);
3272 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3273 FShellTimer := 10;
3274 FShellType := SHELL_SHELL;
3275 end;
3276 MONSTER_MAN:
3277 begin
3278 g_Weapon_dshotgun(wx, wy, tx, ty, FUID);
3279 FShellTimer := 13;
3280 FShellType := SHELL_DBLSHELL;
3281 FAmmo := -36;
3282 end;
3283 MONSTER_CYBER:
3284 begin
3285 g_Weapon_rocket(wx, wy, tx, ty, FUID);
3286 // MH_SEND_MonsterAttack(FUID, wx, wy, tx, ty);
3287 end;
3288 MONSTER_SKEL:
3289 g_Weapon_revf(wx, wy, tx, ty, FUID, FTargetUID);
3290 MONSTER_CGUN:
3291 begin
3292 g_Weapon_mgun(wx, wy, tx, ty, FUID);
3293 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3294 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3295 end;
3296 MONSTER_SPIDER:
3297 begin
3298 g_Weapon_mgun(wx, wy, tx, ty, FUID);
3299 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3300 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
3301 end;
3302 MONSTER_BSP:
3303 g_Weapon_aplasma(wx, wy, tx, ty, FUID);
3304 MONSTER_ROBO:
3305 g_Weapon_plasma(wx, wy, tx, ty, FUID);
3306 MONSTER_MANCUB:
3307 g_Weapon_manfire(wx, wy, tx, ty, FUID);
3308 MONSTER_BARON, MONSTER_KNIGHT:
3309 g_Weapon_ball7(wx, wy, tx, ty, FUID);
3310 MONSTER_CACO:
3311 g_Weapon_ball2(wx, wy, tx, ty, FUID);
3312 MONSTER_PAIN:
3313 begin // Ñîçäàåì Lost_Soul:
3314 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+(FObj.Rect.Width div 2),
3315 FObj.Y+FObj.Rect.Y, FDirection);
3317 if mon <> nil then
3318 begin // Öåëü - öåëü Pain_Elemental'à. Ëåòèì ê íåé:
3319 mon.FTargetUID := FTargetUID;
3320 GetPos(FTargetUID, @o);
3321 mon.FTargetTime := 0;
3322 mon.FNoRespawn := True;
3323 mon.SetState(MONSTATE_GO);
3324 mon.shoot(@o, True);
3325 Inc(gTotalMonsters);
3327 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3328 end;
3329 end;
3330 end;
3332 if FMonsterType <> MONSTER_PAIN then
3333 if g_Game_IsNet then
3334 MH_SEND_MonsterShot(FUID, wx, wy, tx, ty);
3336 // Ñêîðîñòðåëüíûå ìîíñòðû:
3337 if (FMonsterType = MONSTER_CGUN) or
3338 (FMonsterType = MONSTER_SPIDER) or
3339 (FMonsterType = MONSTER_BSP) or
3340 (FMonsterType = MONSTER_MANCUB) or
3341 (FMonsterType = MONSTER_ROBO) then
3342 if not GetPos(FTargetUID, @o) then
3343 // Öåëü ìåðòâà - èùåì íîâóþ:
3344 findNewPrey()
3345 else // Öåëü æèâà - ïðîäîëæàåì ñòðåëÿòü:
3346 if shoot(@o, False) then
3347 FChainFire := True;
3348 end;
3350 // Àòàêà òîëüêî 1 ðàç çà àíèìàöèþ àòàêè:
3351 FWaitAttackAnim := True;
3352 end;
3354 // Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
3355 if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
3356 case FState of
3357 MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
3358 // Çâóêè ïðè ïåðåäâèæåíèè:
3359 case FMonsterType of
3360 MONSTER_CYBER:
3361 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3362 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3363 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_WALK', FObj.X, FObj.Y);
3364 MONSTER_SPIDER:
3365 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3366 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3367 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_WALK', FObj.X, FObj.Y);
3368 MONSTER_BSP:
3369 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3370 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3371 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3372 MONSTER_ROBO:
3373 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3374 (FAnim[FCurAnim, FDirection].CurrentFrame = 5) then
3375 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3376 end;
3377 end;
3379 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
3380 not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
3381 FObj.Vel.X := oldvelx;
3383 // Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
3384 if FAnim[FCurAnim, FDirection] <> nil then
3385 FAnim[FCurAnim, FDirection].Update();
3386 end;
3388 procedure TMonster.SetDeadAnim;
3389 begin
3390 if FAnim <> nil then
3391 FAnim[FCurAnim, FDirection].CurrentFrame := FAnim[FCurAnim, FDirection].TotalFrames - 1;
3392 end;
3394 procedure TMonster.RevertAnim(R: Boolean = True);
3395 begin
3396 if FAnim <> nil then
3397 if FAnim[FCurAnim, FDirection].IsReverse <> R then
3398 FAnim[FCurAnim, FDirection].Revert(R);
3399 end;
3401 function TMonster.AnimIsReverse: Boolean;
3402 begin
3403 if FAnim <> nil then
3404 Result := FAnim[FCurAnim, FDirection].IsReverse
3405 else
3406 Result := False;
3407 end;
3409 procedure TMonster.ClientUpdate();
3410 var
3411 a, b, sx, sy, oldvelx: Integer;
3412 st: Word;
3413 o, co: TObj;
3414 fall: Boolean;
3415 label
3416 _end;
3417 begin
3418 sx := 0; // SHUT UP COMPILER
3419 sy := 0;
3420 fall := True;
3421 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
3422 if FMonsterType = MONSTER_FISH then
3423 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3424 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
3425 fall := False;
3427 // Ëåòàþùèå ìîíòñðû:
3428 if ((FMonsterType = MONSTER_SOUL) or
3429 (FMonsterType = MONSTER_PAIN) or
3430 (FMonsterType = MONSTER_CACO)) and
3431 (FState <> MONSTATE_DIE) and
3432 (FState <> MONSTATE_DEAD) then
3433 fall := False;
3435 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
3436 if gTime mod (GAME_TICK*2) <> 0 then
3437 begin
3438 g_Obj_Move(@FObj, fall, True, True);
3439 positionChanged(); // this updates spatial accelerators
3440 Exit;
3441 end;
3443 if FPainTicks > 0 then
3444 Dec(FPainTicks)
3445 else
3446 FPainSound := False;
3448 // Äâèãàåìñÿ:
3449 st := g_Obj_Move(@FObj, fall, True, True);
3450 positionChanged(); // this updates spatial accelerators
3452 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
3453 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
3454 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
3455 begin
3456 FRemoved := True;
3457 Exit;
3458 end;
3460 oldvelx := FObj.Vel.X;
3462 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
3463 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
3464 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3466 if FFireTime > 0 then
3467 begin
3468 if WordBool(st and MOVE_INWATER) then
3469 FFireTime := 0
3470 else
3471 begin
3472 OnFireFlame(1);
3473 FFireTime := FFireTime - 1;
3474 end;
3475 end;
3477 // Ìåðòâûé íè÷åãî íå äåëàåò:
3478 if (FState = MONSTATE_DEAD) then
3479 goto _end;
3481 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
3482 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
3483 case FMonsterType of
3484 MONSTER_FISH:
3485 if Random(4) = 0 then
3486 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
3487 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
3488 MONSTER_ROBO, MONSTER_BARREL:
3489 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
3490 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
3491 else begin
3492 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
3493 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
3494 if Random(2) = 0 then
3495 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
3496 else
3497 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
3498 end;
3499 end;
3501 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
3502 if FMonsterType = MONSTER_BARREL then
3503 begin
3504 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
3505 (FAnim[FCurAnim, FDirection].Counter = 0) then
3506 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3507 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
3508 60, FUID);
3509 end;
3511 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
3512 if FMonsterType = MONSTER_SOUL then
3513 if WordBool(st and MOVE_HITAIR) then
3514 g_Obj_SetSpeed(@FObj, 16);
3516 if FAmmo < 0 then
3517 FAmmo := FAmmo + 1;
3519 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
3520 if FObj.Vel.Y < 0 then
3521 if WordBool(st and MOVE_INWATER) then
3522 FObj.Vel.Y := -4;
3524 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
3525 FTargetTime := FTargetTime + 1;
3527 if FShellTimer > -1 then
3528 if FShellTimer = 0 then
3529 begin
3530 if FShellType = SHELL_SHELL then
3531 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3532 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3533 GameVelX, GameVelY-2, SHELL_SHELL)
3534 else if FShellType = SHELL_DBLSHELL then
3535 begin
3536 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3537 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3538 GameVelX-1, GameVelY-2, SHELL_SHELL);
3539 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3540 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3541 GameVelX+1, GameVelY-2, SHELL_SHELL);
3542 end;
3543 FShellTimer := -1;
3544 end else Dec(FShellTimer);
3546 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
3547 if fall then
3548 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
3549 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
3550 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3551 FObj.Rect.Width, FObj.Rect.Height, 50) then
3552 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
3553 (FObj.Accel.Y = 0) then
3554 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
3556 case FState of
3557 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
3558 begin
3559 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
3560 if FPain >= MONSTERTABLE[FMonsterType].Pain then
3561 begin
3562 FPain := MONSTERTABLE[FMonsterType].Pain;
3563 if gSoundEffectsDF then PainSound();
3564 end;
3565 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
3566 PainSound();
3568 // Ñíèæàåì áîëü ñî âðåìåíåì:
3569 FPain := FPain - 5;
3571 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
3572 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
3573 begin
3574 SetState(MONSTATE_GO);
3575 FPain := 0;
3576 end;
3577 end;
3579 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
3580 begin
3581 // Ñïèì:
3582 FSleep := FSleep + 1;
3584 // Ïðîñïàëè äîñòàòî÷íî:
3585 if FSleep >= 18 then
3586 FSleep := 0
3587 else // åùå ñïèì
3588 goto _end;
3589 end;
3591 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
3592 begin
3593 // Æäåì:
3594 FSleep := FSleep - 1;
3595 end;
3597 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
3598 begin
3599 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
3600 if WordBool(st and MOVE_BLOCK) then
3601 begin
3602 Turn();
3603 FSleep := 40;
3604 SetState(MONSTATE_RUNOUT);
3606 goto _end;
3607 end;
3609 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
3610 if (FMonsterType = MONSTER_VILE) then
3611 if isCorpse(@FObj, False) <> -1 then
3612 begin
3613 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
3614 FObj.Vel.X := 0;
3616 goto _end;
3617 end;
3619 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
3620 if Abs(sx) < 40 then
3621 if FMonsterType <> MONSTER_FISH then
3622 begin
3623 SetState(MONSTATE_RUN);
3624 FSleep := 15;
3626 goto _end;
3627 end;
3629 // Óïåðëèñü â ñòåíó:
3630 if WordBool(st and MOVE_HITWALL) then
3631 begin
3632 case FMonsterType of
3633 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
3634 else // Íå ëåòàþò:
3635 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
3636 (FObj.Accel.Y = 0) then
3637 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
3638 // Ïðûæîê ÷åðåç ñòåíó:
3639 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
3640 SetState(MONSTATE_CLIMB);
3641 end;
3642 end;
3644 goto _end;
3645 end;
3647 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
3648 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
3649 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
3650 begin
3651 if FMonsterType = MONSTER_FISH then
3652 begin // Ðûáà
3653 if not WordBool(st and MOVE_INWATER) then
3654 begin // Ðûáà âíå âîäû:
3655 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
3656 begin // "Ñòîèò" òâåðäî
3657 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
3658 if FObj.Accel.Y = 0 then
3659 FObj.Vel.Y := -6;
3660 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
3661 end;
3663 // Ðûáå áîëüíî:
3664 SetState(MONSTATE_PAIN);
3665 FPain := FPain + 50;
3666 end
3667 else // Ðûáà â âîäå
3668 begin
3669 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
3670 if Abs(sy) > 8 then
3671 FObj.Vel.Y := g_basic.Sign(sy)*4
3672 else
3673 FObj.Vel.Y := 0;
3675 // Ðûáà ïëûâåò ââåðõ:
3676 if FObj.Vel.Y < 0 then
3677 if not g_Obj_CollideLiquid(@FObj, 0, -16) then
3678 begin
3679 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
3680 FObj.Vel.Y := 0;
3681 // Ïëàâàåì òóäà-ñþäà:
3682 SetState(MONSTATE_RUN);
3683 FSleep := 20;
3684 end;
3685 end;
3686 end
3687 else // Ëåòàþùèå ìîíñòðû
3688 begin
3689 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
3690 if Abs(sy) > 8 then
3691 FObj.Vel.Y := g_basic.Sign(sy)*4
3692 else
3693 FObj.Vel.Y := 0;
3694 end;
3695 end
3696 else // "Íàçåìíûå" ìîíñòðû
3697 begin
3698 // Âîçìîæíî, ïèíàåì êóñêè:
3699 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
3700 begin
3701 b := Abs(FObj.Vel.X);
3702 if b > 1 then b := b * (Random(8 div b) + 1);
3703 for a := 0 to High(gGibs) do
3704 begin
3705 if gGibs[a].alive and
3706 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
3707 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
3708 begin
3709 // Ïèíàåì êóñêè
3710 if FObj.Vel.X < 0 then
3711 begin
3712 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
3713 end
3714 else
3715 begin
3716 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
3717 end;
3718 positionChanged(); // this updates spatial accelerators
3719 end;
3720 end;
3721 end;
3722 // Áîññû ìîãóò ïèíàòü òðóïû:
3723 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
3724 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
3725 begin
3726 b := Abs(FObj.Vel.X);
3727 if b > 1 then b := b * (Random(8 div b) + 1);
3728 for a := 0 to High(gCorpses) do
3729 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
3730 begin
3731 co := gCorpses[a].Obj;
3732 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
3733 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
3734 // Ïèíàåì òðóïû
3735 if FObj.Vel.X < 0 then
3736 gCorpses[a].Damage(b*2, -b, Random(7)) // íàëåâî
3737 else
3738 gCorpses[a].Damage(b*2, b, Random(7)); // íàïðàâî
3739 end;
3740 end;
3741 end;
3743 FSleep := FSleep + 1;
3745 // Èíîãäà ðû÷èì:
3746 if FSleep >= 8 then
3747 begin
3748 FSleep := 0;
3749 if Random(8) = 0 then
3750 ActionSound();
3751 end;
3753 // Áåæèì â âûáðàííóþ ñòîðîíó:
3754 if FDirection = TDirection.D_RIGHT then
3755 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3756 else
3757 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3759 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3760 if WordBool(st and MOVE_INWATER) then
3761 FObj.Vel.X := FObj.Vel.X div 2
3762 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3763 if FMonsterType = MONSTER_FISH then
3764 FObj.Vel.X := 0;
3765 end;
3767 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
3768 begin
3769 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
3770 if WordBool(st and MOVE_BLOCK) then
3771 begin
3772 SetState(MONSTATE_RUNOUT);
3773 FSleep := 40;
3775 goto _end;
3776 end;
3778 FSleep := FSleep - 1;
3780 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
3781 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
3782 begin
3783 SetState(MONSTATE_GO);
3784 FSleep := 0;
3786 // Èíîãäà ðû÷èì:
3787 if Random(8) = 0 then
3788 ActionSound();
3789 end;
3791 // Áåæèì â âûáðàííóþ ñòîðîíó:
3792 if FDirection = TDirection.D_RIGHT then
3793 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3794 else
3795 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3797 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3798 if WordBool(st and MOVE_INWATER) then
3799 FObj.Vel.X := FObj.Vel.X div 2
3800 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3801 if FMonsterType = MONSTER_FISH then
3802 FObj.Vel.X := 0;
3803 end;
3805 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
3806 begin
3807 // Âûøëè èç ÁëîêÌîíà:
3808 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
3809 FSleep := 0;
3811 FSleep := FSleep - 1;
3813 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
3814 if FSleep <= -18 then
3815 begin
3816 SetState(MONSTATE_GO);
3817 FSleep := 0;
3819 // Èíîãäà ðû÷èì:
3820 if Random(8) = 0 then
3821 ActionSound();
3822 end;
3824 // Áåæèì â âûáðàííóþ ñòîðîíó:
3825 if FDirection = TDirection.D_RIGHT then
3826 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3827 else
3828 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3830 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3831 if WordBool(st and MOVE_INWATER) then
3832 FObj.Vel.X := FObj.Vel.X div 2
3833 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3834 if FMonsterType = MONSTER_FISH then
3835 FObj.Vel.X := 0;
3836 end;
3838 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
3839 begin
3840 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
3841 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
3842 (not WordBool(st and MOVE_HITWALL)) then
3843 begin
3844 SetState(MONSTATE_GO);
3845 FSleep := 0;
3847 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
3848 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3849 begin
3850 SetState(MONSTATE_RUN);
3851 FSleep := 15;
3852 end;
3853 end;
3855 // Áåæèì â âûáðàííóþ ñòîðîíó:
3856 if FDirection = TDirection.D_RIGHT then
3857 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3858 else
3859 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3861 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3862 if WordBool(st and MOVE_INWATER) then
3863 FObj.Vel.X := FObj.Vel.X div 2
3864 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3865 if FMonsterType = MONSTER_FISH then
3866 FObj.Vel.X := 0;
3867 end;
3869 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
3870 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
3871 begin
3872 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
3873 if FMonsterType = MONSTER_SOUL then
3874 begin
3875 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
3876 SetState(MONSTATE_GO);
3878 goto _end;
3879 end;
3881 // Çàìåäëÿåìñÿ ïðè àòàêå:
3882 if FMonsterType <> MONSTER_FISH then
3883 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3885 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
3886 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
3887 begin
3888 // Öåëü ïîãèáëà => èäåì äàëüøå:
3889 if not GetPos(FTargetUID, @o) then
3890 begin
3891 SetState(MONSTATE_GO);
3893 goto _end;
3894 end;
3896 // Öåëü íå âèäíî => èäåì äàëüøå:
3897 if not g_Look(@FObj, @o, FDirection) then
3898 begin
3899 SetState(MONSTATE_GO);
3901 goto _end;
3902 end;
3904 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
3905 if g_Obj_CollideWater(@o, 0, 0) then
3906 begin
3907 SetState(MONSTATE_GO);
3909 goto _end;
3910 end;
3911 end;
3912 end;
3913 end; // case FState of ...
3915 _end:
3917 // Ñîñòîÿíèå - Âîñêðåøåíèå:
3918 if FState = MONSTATE_REVIVE then
3919 if FAnim[FCurAnim, FDirection].Played then
3920 begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
3921 FAnim[FCurAnim, FDirection].Revert(False);
3922 SetState(MONSTATE_GO);
3923 end;
3925 // Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
3926 if vilefire <> nil then
3927 vilefire.Update();
3929 // Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
3930 if (FState = MONSTATE_DIE) and
3931 (FAnim[FCurAnim, FDirection] <> nil) and
3932 (FAnim[FCurAnim, FDirection].Played) then
3933 begin
3934 // Óìåð:
3935 SetState(MONSTATE_DEAD);
3937 // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
3938 if (FMonsterType = MONSTER_PAIN) or
3939 (FMonsterType = MONSTER_SOUL) or
3940 (FMonsterType = MONSTER_BARREL) then
3941 FRemoved := True
3942 else
3943 FAnim[FCurAnim, FDirection].CurrentFrame := FAnim[FCurAnim, FDirection].TotalFrames - 1;
3944 end;
3946 // Ñîâåðøåíèå àòàêè è ñòðåëüáû:
3947 if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
3948 if (FAnim[FCurAnim, FDirection] <> nil) then
3949 // Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
3950 if (FAnim[FCurAnim, FDirection].Played) then
3951 begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
3952 if FState = MONSTATE_ATTACK then
3953 begin // Ñîñòîÿíèå - Àòàêà
3954 // Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
3955 if FMonsterType <> MONSTER_SOUL then
3956 SetState(MONSTATE_GO);
3957 end
3958 else // Ñîñòîÿíèå - Ñòðåëüáà
3959 begin
3960 // Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
3961 if not FChainFire then
3962 SetState(MONSTATE_GO)
3963 else
3964 begin // Íàäî ñòðåëÿòü åùå
3965 FChainFire := False;
3966 // Ò.ê. ñîñòîÿíèå íå èçìåíèëîñü, è íóæåí
3967 // íîâûé öèêë îæèäàíèÿ çàâåðøåíèÿ àíèìàöèè:
3968 FAnim[FCurAnim, FDirection].Reset();
3969 end;
3970 end;
3972 FWaitAttackAnim := False;
3973 end
3975 else // Àíèìàöèÿ àòàêè åùå èäåò (èñêëþ÷åíèå - Lost_Soul):
3976 if (FMonsterType = MONSTER_SOUL) or
3977 ( (not FWaitAttackAnim) and
3978 (FAnim[FCurAnim, FDirection].CurrentFrame =
3979 (FAnim[FCurAnim, FDirection].TotalFrames div 2))
3980 ) then
3981 begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
3982 if FState = MONSTATE_ATTACK then
3983 begin // Ñîñòîÿíèå - Àòàêà
3984 // Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
3985 if FMonsterType = MONSTER_SOUL then
3986 FAnim[FCurAnim, FDirection].Reset();
3988 case FMonsterType of
3989 MONSTER_SOUL, MONSTER_IMP, MONSTER_DEMON:
3990 // Ãðûçåì ïåðâîãî ïîïàâøåãîñÿ:
3991 if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
3992 // Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
3993 if FMonsterType = MONSTER_SOUL then
3994 SetState(MONSTATE_GO);
3996 MONSTER_FISH:
3997 g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME);
3999 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
4000 // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
4001 if FCurAnim = ANIM_ATTACK2 then
4002 begin
4003 o := FObj;
4004 o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
4005 g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME);
4006 end;
4008 MONSTER_VILE:
4009 // Êîëäóí ïûòàåòñÿ âîñêðåøàòü:
4010 if FCurAnim = ANIM_ATTACK2 then
4011 begin
4012 sx := isCorpse(@FObj, True);
4013 if sx <> -1 then
4014 begin // Íàøëè, êîãî âîñêðåñèòü
4015 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
4016 // Âîñêðåøàòü - ñåáå âðåäèòü:
4017 {g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
4018 end;
4019 end;
4020 end;
4021 end
4023 else // Ñîñòîÿíèå - Ñòðåëüáà
4024 begin
4025 // Ñêîðîñòðåëüíûå ìîíñòðû:
4026 if (FMonsterType = MONSTER_CGUN) or
4027 (FMonsterType = MONSTER_SPIDER) or
4028 (FMonsterType = MONSTER_BSP) or
4029 (FMonsterType = MONSTER_MANCUB) or
4030 (FMonsterType = MONSTER_ROBO) then
4031 if not GetPos(FTargetUID, @o) then
4032 // Öåëü ìåðòâà - èùåì íîâóþ:
4033 findNewPrey()
4034 else // Öåëü æèâà - ïðîäîëæàåì ñòðåëÿòü:
4035 if shoot(@o, False) then
4036 FChainFire := True;
4037 end;
4039 // Àòàêà òîëüêî 1 ðàç çà àíèìàöèþ àòàêè:
4040 FWaitAttackAnim := True;
4041 end;
4043 // Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
4044 if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
4045 case FState of
4046 MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
4047 // Çâóêè ïðè ïåðåäâèæåíèè:
4048 case FMonsterType of
4049 MONSTER_CYBER:
4050 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4051 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4052 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_WALK', FObj.X, FObj.Y);
4053 MONSTER_SPIDER:
4054 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4055 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4056 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_WALK', FObj.X, FObj.Y);
4057 MONSTER_BSP:
4058 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4059 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4060 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
4061 MONSTER_ROBO:
4062 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4063 (FAnim[FCurAnim, FDirection].CurrentFrame = 5) then
4064 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
4065 end;
4066 end;
4068 // Êîñòûëü äëÿ ïîòîêîâ
4069 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
4070 not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
4071 FObj.Vel.X := oldvelx;
4073 // Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
4074 if FAnim[FCurAnim, FDirection] <> nil then
4075 FAnim[FCurAnim, FDirection].Update();
4076 end;
4078 procedure TMonster.ClientAttack(wx, wy, atx, aty: Integer);
4079 begin
4080 case FMonsterType of
4081 MONSTER_ZOMBY:
4082 begin
4083 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
4084 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
4085 end;
4086 MONSTER_SERG:
4087 begin
4088 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
4089 FShellTimer := 10;
4090 FShellType := SHELL_SHELL;
4091 end;
4092 MONSTER_MAN:
4093 begin
4094 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', wx, wy);
4095 FShellTimer := 13;
4096 FShellType := SHELL_DBLSHELL;
4097 end;
4098 MONSTER_CGUN, MONSTER_SPIDER:
4099 begin
4100 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
4101 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
4102 end;
4103 MONSTER_IMP:
4104 g_Weapon_ball1(wx, wy, atx, aty, FUID);
4105 MONSTER_CYBER:
4106 g_Weapon_rocket(wx, wy, atx, aty, FUID);
4107 MONSTER_SKEL:
4108 g_Weapon_revf(wx, wy, atx, aty, FUID, FTargetUID);
4109 MONSTER_BSP:
4110 g_Weapon_aplasma(wx, wy, atx, aty, FUID);
4111 MONSTER_ROBO:
4112 g_Weapon_plasma(wx, wy, atx, aty, FUID);
4113 MONSTER_MANCUB:
4114 g_Weapon_manfire(wx, wy, atx, aty, FUID);
4115 MONSTER_BARON, MONSTER_KNIGHT:
4116 g_Weapon_ball7(wx, wy, atx, aty, FUID);
4117 MONSTER_CACO:
4118 g_Weapon_ball2(wx, wy, atx, aty, FUID);
4119 end;
4120 end;
4122 procedure TMonster.Turn();
4123 begin
4124 // Ðàçâîðà÷èâàåìñÿ:
4125 if FDirection = TDirection.D_LEFT then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
4127 // Áåæèì â âûáðàííóþ ñòîðîíó:
4128 if FDirection = TDirection.D_RIGHT then
4129 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
4130 else
4131 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
4132 end;
4134 function TMonster.findNewPrey(): Boolean;
4135 var
4136 a: DWORD;
4137 l, l2: Integer;
4138 PlayersSee, MonstersSee: Array of DWORD;
4139 PlayerNear, MonsterNear: Integer;
4140 begin
4141 Result := False;
4142 SetLength(MonstersSee, 0);
4143 SetLength(PlayersSee, 0);
4145 FTargetUID := 0;
4146 l := 32000;
4147 PlayerNear := -1;
4148 MonsterNear := -1;
4150 // Ïîåõàâøèå, êàííèáàëû, è äîáðûå èãðîêîâ íå òðîãàþò
4151 if (gPlayers <> nil) and (FBehaviour <> BH_INSANE) and
4152 (FBehaviour <> BH_CANNIBAL) and (FBehaviour <> BH_GOOD) then
4153 for a := 0 to High(gPlayers) do
4154 if (gPlayers[a] <> nil) and (gPlayers[a].alive)
4155 and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
4156 begin
4157 if g_Look(@FObj, @gPlayers[a].Obj, FDirection) then
4158 begin
4159 SetLength(PlayersSee, Length(PlayersSee) + 1);
4160 PlayersSee[High(PlayersSee)] := a;
4161 end;
4162 l2 := Abs(gPlayers[a].GameX-FObj.X)+
4163 Abs(gPlayers[a].GameY-FObj.Y);
4164 if l2 < l then
4165 begin
4166 l := l2;
4167 PlayerNear := Integer(a);
4168 end;
4169 end;
4171 // Êèëëåðû è äîáðûå íå òðîãàþò ìîíñòðîâ
4172 if (gMonsters <> nil) and (FBehaviour <> BH_KILLER) and (FBehaviour <> BH_GOOD) then
4173 for a := 0 to High(gMonsters) do
4174 if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
4175 (gMonsters[a].FUID <> FUID) then
4176 begin
4177 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
4178 Continue; // Êàííèáàëû àòàêóþò òîëüêî ñîðîäè÷åé
4179 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL)
4180 and (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
4181 Continue; // Ïîåõàâøèå íå òðîãàþò äðóçåé, íî èì íå íðàâÿòñÿ áî÷êè
4182 if ((FBehaviour = BH_NORMAL) or (FBehaviour = BH_MANIAC))
4183 and (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
4184 Continue; // Îñòàâøèåñÿ òèïû, êðîìå êàííèáàëîâ, íå òðîãàþò ñâîèõ äðóçåé
4186 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
4187 begin
4188 SetLength(MonstersSee, Length(MonstersSee) + 1);
4189 MonstersSee[High(MonstersSee)] := a;
4190 end;
4191 l2 := Abs(gMonsters[a].FObj.X-FObj.X)+
4192 Abs(gMonsters[a].FObj.Y-FObj.Y);
4193 if l2 < l then
4194 begin
4195 l := l2;
4196 MonsterNear := Integer(a);
4197 end;
4198 end;
4200 case FBehaviour of
4201 BH_NORMAL, BH_KILLER:
4202 begin
4203 // Îáû÷íûé è êèëëåð ñíà÷àëà èùóò èãðîêîâ â ïîëå çðåíèÿ
4204 if (FTargetUID = 0) and (Length(PlayersSee) > 0) then
4205 begin
4206 a := PlayersSee[Random(Length(PlayersSee))];
4207 FTargetUID := gPlayers[a].UID;
4208 end;
4209 // Çàòåì ïîáëèçîñòè
4210 if (FTargetUID = 0) and (PlayerNear > -1) then
4211 begin
4212 a := PlayerNear;
4213 FTargetUID := gPlayers[a].UID;
4214 end;
4215 // Ïîòîì îáû÷íûå èùóò ìîíñòðîâ â ïîëå çðåíèÿ
4216 if (FTargetUID = 0) and (Length(MonstersSee) > 0) then
4217 begin
4218 a := MonstersSee[Random(Length(MonstersSee))];
4219 FTargetUID := gMonsters[a].UID;
4220 end;
4221 // Çàòåì ïîáëèçîñòè
4222 if (FTargetUID = 0) and (MonsterNear > -1) then
4223 begin
4224 a := MonsterNear;
4225 FTargetUID := gMonsters[a].UID;
4226 end;
4227 end;
4228 BH_MANIAC, BH_INSANE, BH_CANNIBAL:
4229 begin
4230 // Ìàíüÿêè, ïîåõàâøèå è êàííèáàëû ñíà÷àëà èñòðåáëÿþò âñ¸ â ïîëå çðåíèÿ
4231 if (FTargetUID = 0) and (Length(PlayersSee) > 0) then
4232 begin
4233 a := PlayersSee[Random(Length(PlayersSee))];
4234 FTargetUID := gPlayers[a].UID;
4235 end;
4236 if (FTargetUID = 0) and (Length(MonstersSee) > 0) then
4237 begin
4238 a := MonstersSee[Random(Length(MonstersSee))];
4239 FTargetUID := gMonsters[a].UID;
4240 end;
4241 // Çàòåì èùóò êîãî-òî ïîáëèçîñòè
4242 if (FTargetUID = 0) and (PlayerNear > -1) then
4243 begin
4244 a := PlayerNear;
4245 FTargetUID := gPlayers[a].UID;
4246 end;
4247 if (FTargetUID = 0) and (MonsterNear > -1) then
4248 begin
4249 a := MonsterNear;
4250 FTargetUID := gMonsters[a].UID;
4251 end;
4252 end;
4253 end;
4255 // Åñëè è ìîíñòðîâ íåò - íà÷èíàåì æäàòü öåëü:
4256 if FTargetUID = 0 then
4257 begin
4258 // Ïîåõàâøèé ïûòàåòñÿ ñàìîóáèòüñÿ
4259 if FBehaviour = BH_INSANE then
4260 FTargetUID := FUID
4261 else
4262 FTargetTime := MAX_ATM;
4263 end
4264 else
4265 begin // Öåëü íàøëè
4266 FTargetTime := 0;
4267 Result := True;
4268 end;
4269 end;
4271 function TMonster.kick(o: PObj): Boolean;
4272 begin
4273 Result := False;
4275 case FMonsterType of
4276 MONSTER_FISH:
4277 begin
4278 SetState(MONSTATE_ATTACK);
4279 Result := True;
4280 end;
4281 MONSTER_DEMON:
4282 begin
4283 SetState(MONSTATE_ATTACK);
4284 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ATTACK', FObj.X, FObj.Y);
4285 Result := True;
4286 end;
4287 MONSTER_IMP:
4288 begin
4289 SetState(MONSTATE_ATTACK);
4290 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ATTACK', FObj.X, FObj.Y);
4291 Result := True;
4292 end;
4293 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
4294 begin
4295 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
4296 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ATTACK', FObj.X, FObj.Y);
4297 Result := True;
4298 end;
4299 MONSTER_BARON, MONSTER_KNIGHT,
4300 MONSTER_CACO, MONSTER_MANCUB:
4301 // Ýòè ìîíñòðû íå ïèíàþò - îíè ñòðåëÿþò â óïîð:
4302 if not g_Game_IsClient then Result := shoot(o, True);
4303 end;
4304 end;
4306 function TMonster.shoot(o: PObj; immediately: Boolean): Boolean;
4307 var
4308 xd, yd, m: Integer;
4309 begin
4310 Result := False;
4312 // Ñòðåëÿòü ðàíî:
4313 if FAmmo < 0 then
4314 Exit;
4316 // Æäàòü âðåìåíè ãîòîâíîñòè ê âûñòðåëó:
4317 if not immediately then
4318 case FMonsterType of
4319 MONSTER_FISH, MONSTER_BARREL, MONSTER_DEMON:
4320 Exit; // íå ñòðåëÿþò
4321 MONSTER_CGUN, MONSTER_BSP, MONSTER_ROBO:
4322 begin
4323 FAmmo := FAmmo + 1;
4324 // Âðåìÿ âûñòðåëà óïóùåíî:
4325 if FAmmo >= 50 then
4326 FAmmo := IfThen(FMonsterType = MONSTER_ROBO, -200, -50);
4327 end;
4328 MONSTER_MAN: ;
4329 MONSTER_MANCUB:
4330 begin
4331 FAmmo := FAmmo + 1;
4332 // Âðåìÿ âûñòðåëà óïóùåíî:
4333 if FAmmo >= 5 then
4334 FAmmo := -50;
4335 end;
4336 MONSTER_SPIDER:
4337 begin
4338 FAmmo := FAmmo + 1;
4339 // Âðåìÿ âûñòðåëà óïóùåíî:
4340 if FAmmo >= 100 then
4341 FAmmo := -50;
4342 end;
4343 MONSTER_CYBER:
4344 begin
4345 // Ñòðåëÿåò íå âñåãäà:
4346 if Random(2) = 0 then
4347 Exit;
4348 FAmmo := FAmmo + 1;
4349 // Âðåìÿ âûñòðåëà óïóùåíî:
4350 if FAmmo >= 10 then
4351 FAmmo := -50;
4352 end;
4353 MONSTER_BARON, MONSTER_KNIGHT: if Random(8) <> 0 then Exit;
4354 MONSTER_SKEL: if Random(32) <> 0 then Exit;
4355 MONSTER_VILE: if Random(8) <> 0 then Exit;
4356 MONSTER_PAIN: if Random(8) <> 0 then Exit;
4357 else if Random(16) <> 0 then Exit;
4358 end;
4360 // Öåëè íå âèäíî:
4361 if not g_Look(@FObj, o, FDirection) then
4362 Exit;
4364 FTargetTime := 0;
4366 tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2)+((o^.Vel.X{+o^.Accel.X})*12);
4367 ty := o^.Y+o^.Rect.Y+(o^.Rect.Height div 2)+((o^.Vel.Y{+o^.Accel.Y})*12);
4369 // Ðàçíèöà ïî âûñîòå áîëüøå ðàçíèöû ïî ãîðèçîíòàëè
4370 // (íå ìîæåò ñòðåëÿòü ïîä òàêèì áîëüøèì óãëîì):
4371 if Abs(tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2))) <
4372 Abs(ty-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2))) then
4373 Exit;
4375 case FMonsterType of
4376 MONSTER_IMP, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO:
4377 begin
4378 SetState(MONSTATE_SHOOT);
4379 {nn}
4380 end;
4381 MONSTER_SKEL:
4382 begin
4383 SetState(MONSTATE_SHOOT);
4384 {nn}
4385 end;
4386 MONSTER_VILE:
4387 begin // Çàæèãàåì îãîíü
4388 tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2);
4389 ty := o^.Y+o^.Rect.Y;
4390 SetState(MONSTATE_SHOOT);
4392 vilefire.Reset();
4394 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ATTACK', FObj.X, FObj.Y);
4395 g_Sound_PlayExAt('SOUND_FIRE', o^.X, o^.Y);
4396 end;
4397 MONSTER_SOUL:
4398 begin // Ëåòèò â ñòîðîíó öåëè:
4399 SetState(MONSTATE_ATTACK);
4400 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_ATTACK', FObj.X, FObj.Y);
4402 xd := tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
4403 yd := ty-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
4404 m := Max(Abs(xd), Abs(yd));
4405 if m = 0 then
4406 m := 1;
4408 FObj.Vel.X := (xd*16) div m;
4409 FObj.Vel.Y := (yd*16) div m;
4410 end;
4411 MONSTER_MANCUB, MONSTER_ZOMBY, MONSTER_SERG, MONSTER_BSP, MONSTER_ROBO,
4412 MONSTER_CYBER, MONSTER_CGUN, MONSTER_SPIDER, MONSTER_PAIN, MONSTER_MAN:
4413 begin
4414 // Ìàíêóáóñ ðÿâêàåò ïåðåä ïåðâîé àòàêîé:
4415 if FMonsterType = MONSTER_MANCUB then
4416 if FAmmo = 1 then
4417 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ATTACK', FObj.X, FObj.Y);
4419 SetState(MONSTATE_SHOOT);
4420 end;
4421 else Exit;
4422 end;
4424 Result := True;
4425 end;
4427 function TMonster.alive(): Boolean;
4428 begin
4429 Result := (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) and (FHealth > 0);
4430 end;
4432 procedure TMonster.SetHealth(aH: Integer);
4433 begin
4434 if (aH > 0) and (aH < 1000000) then
4435 begin
4436 FHealth := aH;
4437 if FHealth > FMaxHealth then
4438 FMaxHealth := FHealth;
4439 end;
4440 end;
4442 procedure TMonster.WakeUp();
4443 begin
4444 if g_Game_IsClient then Exit;
4445 SetState(MONSTATE_GO);
4446 FTargetTime := MAX_ATM;
4447 WakeUpSound();
4448 end;
4450 procedure TMonster.SaveState (st: TStream);
4451 var
4452 i: Integer;
4453 b: Byte;
4454 anim: Boolean;
4455 begin
4456 assert(st <> nil);
4458 // Ñèãíàòóðà ìîíñòðà:
4459 utils.writeSign(st, 'MONS');
4460 utils.writeInt(st, Byte(0)); // version
4461 // UID ìîíñòðà:
4462 utils.writeInt(st, Word(FUID));
4463 // Íàïðàâëåíèå
4464 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
4465 utils.writeInt(st, Byte(b));
4466 // Íàäî ëè óäàëèòü åãî
4467 utils.writeBool(st, FRemoved);
4468 // Îñòàëîñü çäîðîâüÿ
4469 utils.writeInt(st, LongInt(FHealth));
4470 // Ñîñòîÿíèå
4471 utils.writeInt(st, Byte(FState));
4472 // Òåêóùàÿ àíèìàöèÿ
4473 utils.writeInt(st, Byte(FCurAnim));
4474 // UID öåëè
4475 utils.writeInt(st, Word(FTargetUID));
4476 // Âðåìÿ ïîñëå ïîòåðè öåëè
4477 utils.writeInt(st, LongInt(FTargetTime));
4478 // Ïîâåäåíèå ìîíñòðà
4479 utils.writeInt(st, Byte(FBehaviour));
4480 // Ãîòîâíîñòü ê âûñòðåëó
4481 utils.writeInt(st, LongInt(FAmmo));
4482 // Áîëü
4483 utils.writeInt(st, LongInt(FPain));
4484 // Âðåìÿ îæèäàíèÿ
4485 utils.writeInt(st, LongInt(FSleep));
4486 // Îçâó÷èâàòü ëè áîëü
4487 utils.writeBool(st, FPainSound);
4488 // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè
4489 utils.writeBool(st, FWaitAttackAnim);
4490 // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå
4491 utils.writeBool(st, FChainFire);
4492 // Ïîäëåæèò ëè ðåñïàâíó
4493 utils.writeBool(st, FNoRespawn);
4494 // Êîîðäèíàòû öåëè
4495 utils.writeInt(st, LongInt(tx));
4496 utils.writeInt(st, LongInt(ty));
4497 // ID ìîíñòðà ïðè ñòàðòå êàðòû
4498 utils.writeInt(st, LongInt(FStartID));
4499 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà
4500 utils.writeInt(st, LongInt(FSpawnTrigger));
4501 // Îáúåêò ìîíñòðà
4502 Obj_SaveState(st, @FObj);
4503 // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà
4504 anim := (vilefire <> nil);
4505 utils.writeBool(st, anim);
4506 // Åñëè åñòü - ñîõðàíÿåì:
4507 if anim then vilefire.SaveState(st);
4508 // Àíèìàöèè
4509 for i := ANIM_SLEEP to ANIM_PAIN do
4510 begin
4511 // Åñòü ëè ëåâàÿ àíèìàöèÿ
4512 anim := (FAnim[i, TDirection.D_LEFT] <> nil);
4513 utils.writeBool(st, anim);
4514 // Åñëè åñòü - ñîõðàíÿåì
4515 if anim then FAnim[i, TDirection.D_LEFT].SaveState(st);
4516 // Åñòü ëè ïðàâàÿ àíèìàöèÿ
4517 anim := (FAnim[i, TDirection.D_RIGHT] <> nil);
4518 utils.writeBool(st, anim);
4519 // Åñëè åñòü - ñîõðàíÿåì
4520 if anim then FAnim[i, TDirection.D_RIGHT].SaveState(st);
4521 end;
4522 end;
4525 procedure TMonster.LoadState (st: TStream);
4526 var
4527 i: Integer;
4528 b: Byte;
4529 anim: Boolean;
4530 begin
4531 assert(st <> nil);
4533 // Ñèãíàòóðà ìîíñòðà:
4534 if not utils.checkSign(st, 'MONS') then raise XStreamError.Create('invalid monster signature');
4535 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid monster version');
4536 if (uidMap[FUID] <> nil) and (uidMap[FUID] <> self) then raise Exception.Create('internal error in monster loader (0)');
4537 uidMap[FUID] := nil;
4538 // UID ìîíñòðà:
4539 FUID := utils.readWord(st);
4540 //if (arrIdx = -1) then raise Exception.Create('internal error in monster loader');
4541 if (uidMap[FUID] <> nil) then raise Exception.Create('internal error in monster loader (1)');
4542 uidMap[FUID] := self;
4543 // Íàïðàâëåíèå
4544 b := utils.readByte(st);
4545 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
4546 // Íàäî ëè óäàëèòü åãî
4547 FRemoved := utils.readBool(st);
4548 // Îñòàëîñü çäîðîâüÿ
4549 FHealth := utils.readLongInt(st);
4550 // Ñîñòîÿíèå
4551 FState := utils.readByte(st);
4552 // Òåêóùàÿ àíèìàöèÿ
4553 FCurAnim := utils.readByte(st);
4554 // UID öåëè
4555 FTargetUID := utils.readWord(st);
4556 // Âðåìÿ ïîñëå ïîòåðè öåëè
4557 FTargetTime := utils.readLongInt(st);
4558 // Ïîâåäåíèå ìîíñòðà
4559 FBehaviour := utils.readByte(st);
4560 // Ãîòîâíîñòü ê âûñòðåëó
4561 FAmmo := utils.readLongInt(st);
4562 // Áîëü
4563 FPain := utils.readLongInt(st);
4564 // Âðåìÿ îæèäàíèÿ
4565 FSleep := utils.readLongInt(st);
4566 // Îçâó÷èâàòü ëè áîëü
4567 FPainSound := utils.readBool(st);
4568 // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè
4569 FWaitAttackAnim := utils.readBool(st);
4570 // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå
4571 FChainFire := utils.readBool(st);
4572 // Ïîäëåæèò ëè ðåñïàâíó
4573 FNoRespawn := utils.readBool(st);
4574 // Êîîðäèíàòû öåëè
4575 tx := utils.readLongInt(st);
4576 ty := utils.readLongInt(st);
4577 // ID ìîíñòðà ïðè ñòàðòå êàðòû
4578 FStartID := utils.readLongInt(st);
4579 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà
4580 FSpawnTrigger := utils.readLongInt(st);
4581 // Îáúåêò ìîíñòðà
4582 Obj_LoadState(@FObj, st);
4583 // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà
4584 anim := utils.readBool(st);
4585 // Åñëè åñòü - çàãðóæàåì:
4586 if anim then
4587 begin
4588 Assert(vilefire <> nil, 'TMonster.LoadState: no vilefire anim');
4589 vilefire.LoadState(st);
4590 end;
4591 // Àíèìàöèè
4592 for i := ANIM_SLEEP to ANIM_PAIN do
4593 begin
4594 // Åñòü ëè ëåâàÿ àíèìàöèÿ
4595 anim := utils.readBool(st);
4596 // Åñëè åñòü - çàãðóæàåì
4597 if anim then
4598 begin
4599 Assert(FAnim[i, TDirection.D_LEFT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_left anim');
4600 FAnim[i, TDirection.D_LEFT].LoadState(st);
4601 end;
4602 // Åñòü ëè ïðàâàÿ àíèìàöèÿ
4603 anim := utils.readBool(st);
4604 // Åñëè åñòü - çàãðóæàåì
4605 if anim then
4606 begin
4607 Assert(FAnim[i, TDirection.D_RIGHT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_right anim');
4608 FAnim[i, TDirection.D_RIGHT].LoadState(st);
4609 end;
4610 end;
4611 end;
4614 procedure TMonster.ActivateTriggers();
4615 var
4616 a: Integer;
4617 begin
4618 if FDieTriggers <> nil then
4619 for a := 0 to High(FDieTriggers) do
4620 g_Triggers_Press(FDieTriggers[a], ACTIVATE_MONSTERPRESS);
4621 if FSpawnTrigger > -1 then
4622 begin
4623 g_Triggers_DecreaseSpawner(FSpawnTrigger);
4624 FSpawnTrigger := -1;
4625 end;
4626 end;
4628 procedure TMonster.AddTrigger(t: Integer);
4629 begin
4630 SetLength(FDieTriggers, Length(FDieTriggers)+1);
4631 FDieTriggers[High(FDieTriggers)] := t;
4632 end;
4634 procedure TMonster.ClearTriggers();
4635 begin
4636 SetLength(FDieTriggers, 0);
4637 end;
4639 procedure TMonster.CatchFire(Attacker: Word);
4640 begin
4641 FFireTime := 100;
4642 FFireAttacker := Attacker;
4643 if g_Game_IsNet and g_Game_IsServer then MH_SEND_MonsterState(FUID);
4644 end;
4646 procedure TMonster.OnFireFlame(Times: DWORD = 1);
4647 var
4648 id, i: DWORD;
4649 Anim: TAnimation;
4650 begin
4651 if (Random(10) = 1) and (Times = 1) then
4652 Exit;
4654 if g_Frames_Get(id, 'FRAMES_FLAME') then
4655 begin
4656 for i := 1 to Times do
4657 begin
4658 Anim := TAnimation.Create(id, False, 3);
4659 Anim.Alpha := 0;
4660 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
4661 Obj.Y+8+Random(8+Times*2)+IfThen(FState = MONSTATE_DEAD, 16, 0), Anim, ONCEANIM_SMOKE);
4662 Anim.Free();
4663 end;
4664 end;
4665 end;
4668 // ////////////////////////////////////////////////////////////////////////// //
4669 // throws on invalid uid
4670 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
4671 begin
4672 result := g_Mons_ByIdx_NC(uid);
4673 if (result = nil) then raise Exception.Create('g_Mons_ByIdx: invalid monster id');
4674 end;
4676 // can return null
4677 function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
4678 begin
4679 if (uid < 0) or (uid > High(gMonsters)) then begin result := nil; exit; end;
4680 result := gMonsters[uid];
4681 end;
4683 function g_Mons_TotalCount (): Integer; inline;
4684 begin
4685 result := Length(gMonsters);
4686 end;
4689 function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
4690 var
4691 idx: Integer;
4692 mon: TMonster;
4693 begin
4694 result := false;
4695 if (gMonsters = nil) or not assigned(cb) then exit;
4696 for idx := 0 to High(gMonsters) do
4697 begin
4698 mon := gMonsters[idx];
4699 if (mon <> nil) then
4700 begin
4701 result := cb(mon);
4702 if result then exit;
4703 end;
4704 end;
4705 end;
4708 function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
4709 var
4710 idx: Integer;
4711 mon: TMonster;
4712 begin
4713 result := false;
4714 if (gMonsters = nil) or not assigned(cb) then exit;
4715 for idx := 0 to High(gMonsters) do
4716 begin
4717 mon := gMonsters[idx];
4718 if (mon <> nil) and mon.alive then
4719 begin
4720 result := cb(mon);
4721 if result then exit;
4722 end;
4723 end;
4724 end;
4727 function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
4728 (*
4729 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4730 begin
4731 result := mon.alive;// and g_Obj_Collide(x, y, width, height, @mon.Obj));
4732 end;
4733 *)
4734 var
4735 idx: Integer;
4736 mon: TMonster;
4737 mit: PMonster;
4738 it: TMonsterGrid.Iter;
4739 begin
4740 result := false;
4741 if (width < 1) or (height < 1) then exit;
4742 if gmon_debug_use_sqaccel then
4743 begin
4744 //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4745 it := monsGrid.forEachInAABB(x, y, width, height);
4746 for mit in it do if (mit.alive) then begin result := true; break; end;
4747 it.release();
4748 end
4749 else
4750 begin
4751 for idx := 0 to High(gMonsters) do
4752 begin
4753 mon := gMonsters[idx];
4754 if (mon <> nil) and mon.alive then
4755 begin
4756 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4757 begin
4758 result := true;
4759 exit;
4760 end;
4761 end;
4762 end;
4763 end;
4764 end;
4767 function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
4768 (*
4769 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4770 begin
4771 result := cb(mon);
4772 end;
4773 *)
4774 var
4775 idx: Integer;
4776 mon: TMonster;
4777 mit: PMonster;
4778 it: TMonsterGrid.Iter;
4779 begin
4780 result := false;
4781 if (width < 1) or (height < 1) then exit;
4782 if gmon_debug_use_sqaccel then
4783 begin
4784 //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4785 it := monsGrid.forEachInAABB(x, y, width, height);
4786 for mit in it do if (cb(mit^)) then begin result := true; break; end;
4787 it.release();
4788 end
4789 else
4790 begin
4791 for idx := 0 to High(gMonsters) do
4792 begin
4793 mon := gMonsters[idx];
4794 if (mon <> nil) and mon.alive then
4795 begin
4796 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4797 begin
4798 result := cb(mon);
4799 if result then exit;
4800 end;
4801 end;
4802 end;
4803 end;
4804 end;
4807 function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
4808 (*
4809 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4810 begin
4811 //result := false;
4812 //if mon.alive and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
4813 if mon.alive then result := cb(mon) else result := false;
4814 end;
4815 *)
4816 var
4817 idx: Integer;
4818 mon: TMonster;
4819 mit: PMonster;
4820 it: TMonsterGrid.Iter;
4821 begin
4822 result := false;
4823 if (width < 1) or (height < 1) then exit;
4824 if gmon_debug_use_sqaccel then
4825 begin
4827 if (width = 1) and (height = 1) then
4828 begin
4829 result := (monsGrid.forEachAtPoint(x, y, monsCollCheck) <> nil);
4830 end
4831 else
4832 begin
4833 result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4834 end;
4836 it := monsGrid.forEachInAABB(x, y, width, height);
4837 for mit in it do
4838 begin
4839 if (mit^.alive) then
4840 begin
4841 if (cb(mit^)) then begin result := true; break; end;
4842 end;
4843 end;
4844 it.release();
4845 end
4846 else
4847 begin
4848 for idx := 0 to High(gMonsters) do
4849 begin
4850 mon := gMonsters[idx];
4851 if (mon <> nil) and mon.alive then
4852 begin
4853 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4854 begin
4855 result := cb(mon);
4856 if result then exit;
4857 end;
4858 end;
4859 end;
4860 end;
4861 end;
4864 end.