DEADSOFTWARE

update year in credits (extremely important)
[d2df-sdl.git] / src / game / g_monsters.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 {$M+}
17 {.$DEFINE D2F_DEBUG_MONS_MOVE}
18 unit g_monsters;
20 interface
22 uses
23 SysUtils, Classes,
24 mempool,
25 g_basic, e_graphics, g_phys, g_textures, g_grid,
26 g_saveload, g_panel, xprofiler;
28 const
29 MONSTATE_SLEEP = 0;
30 MONSTATE_GO = 1;
31 MONSTATE_RUN = 2;
32 MONSTATE_CLIMB = 3;
33 MONSTATE_DIE = 4;
34 MONSTATE_DEAD = 5;
35 MONSTATE_ATTACK = 6;
36 MONSTATE_SHOOT = 7;
37 MONSTATE_PAIN = 8;
38 MONSTATE_WAIT = 9;
39 MONSTATE_REVIVE = 10;
40 MONSTATE_RUNOUT = 11;
42 MON_BURN_TIME = 100;
44 { in mapdef now
45 BH_NORMAL = 0;
46 BH_KILLER = 1;
47 BH_MANIAC = 2;
48 BH_INSANE = 3;
49 BH_CANNIBAL = 4;
50 BH_GOOD = 5;
51 }
53 type
54 PMonster = ^TMonster;
55 TMonster = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
56 private
57 FMonsterType: Byte;
58 FUID: Word;
59 FDirection: TDirection;
60 FStartDirection: TDirection;
61 FStartX, FStartY: Integer;
62 FRemoved: Boolean;
63 FHealth: Integer;
64 FMaxHealth: Integer;
65 FState: Byte;
66 FCurAnim: Byte;
67 FAnim: Array of Array [TDirection.D_LEFT..TDirection.D_RIGHT] of TAnimation;
68 FTargetUID: Word;
69 FTargetTime: Integer;
70 FBehaviour: Byte;
71 FAmmo: Integer;
72 FPain: Integer;
73 FSleep: Integer;
74 FPainSound: Boolean;
75 FPainTicks: Integer;
76 FWaitAttackAnim: Boolean;
77 FChainFire: Boolean;
78 tx, ty: Integer;
79 FStartID: Integer;
80 FObj: TObj;
81 FBloodRed: Byte;
82 FBloodGreen: Byte;
83 FBloodBlue: Byte;
84 FBloodKind: Byte;
85 FShellTimer: Integer;
86 FShellType: Byte;
87 FFirePainTime: Integer;
88 FFireAttacker: Word;
89 vilefire: TAnimation;
90 mProxyId: Integer; // node in dyntree or -1
91 mArrIdx: Integer; // in gMonsters
93 FDieTriggers: Array of Integer;
94 FSpawnTrigger: Integer;
96 mNeedSend: Boolean; // for network
98 mEDamageType: Integer;
100 procedure Turn();
101 function findNewPrey(): Boolean;
102 procedure ActivateTriggers();
104 procedure setGameX (v: Integer); inline;
105 procedure setGameY (v: Integer); inline;
107 procedure doDamage (v: Integer);
109 public
110 FNoRespawn: Boolean;
111 FFireTime: Integer;
112 trapCheckFrameId: DWord; // for `g_weapons.CheckTrap()`
113 mplatCheckFrameId: LongWord;
115 constructor Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
116 destructor Destroy(); override;
117 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
118 function Collide(Panel: TPanel): Boolean; overload;
119 function Collide(X, Y: Integer): Boolean; overload;
120 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
121 function alive(): Boolean;
122 procedure SetHealth(aH: Integer);
123 procedure Push(vx, vy: Integer);
124 function Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
125 function Heal(Value: Word): Boolean;
126 procedure BFGHit();
127 procedure Update();
128 procedure ClientUpdate();
129 procedure ClientAttack(wx, wy, atx, aty: Integer);
130 procedure SetDeadAnim;
131 procedure Draw();
132 procedure WakeUp();
133 procedure WakeUpSound();
134 procedure DieSound();
135 procedure PainSound();
136 procedure ActionSound();
137 procedure AddTrigger(t: Integer);
138 procedure ClearTriggers();
139 procedure Respawn();
140 procedure SaveState (st: TStream);
141 procedure LoadState (st: TStream);
142 procedure SetState(State: Byte; ForceAnim: Byte = 255);
143 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
144 procedure MakeBloodSimple(Count: Word);
145 procedure RevertAnim(R: Boolean = True);
146 function AnimIsReverse: Boolean;
147 function shoot(o: PObj; immediately: Boolean): Boolean;
148 function kick(o: PObj): Boolean;
149 procedure CatchFire(Attacker: Word; Timeout: Integer = MON_BURN_TIME);
150 procedure OnFireFlame(Times: DWORD = 1);
152 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
154 procedure setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline;
155 procedure moveBy (dx, dy: Integer); inline;
157 procedure getMapBox (out x, y, w, h: Integer); inline;
159 // get-and-clear
160 function gncNeedSend (): Boolean; inline;
161 procedure setDirty (); inline; // why `dirty`? 'cause i may introduce property `needSend` later
163 public
164 property Obj: TObj read FObj;
166 property proxyId: Integer read mProxyId;
167 property arrIdx: Integer read mArrIdx;
169 property MonsterType: Byte read FMonsterType;
170 property MonsterHealth: Integer read FHealth write FHealth;
171 property MonsterAmmo: Integer read FAmmo write FAmmo;
172 property MonsterTargetUID: Word read FTargetUID write FTargetUID;
173 property MonsterTargetTime: Integer read FTargetTime write FTargetTime;
174 property MonsterBehaviour: Byte read FBehaviour write FBehaviour;
175 property MonsterSleep: Integer read FSleep write FSleep;
176 property MonsterState: Byte read FState write FState;
177 property MonsterRemoved: Boolean read FRemoved write FRemoved;
178 property MonsterPain: Integer read FPain write FPain;
179 property MonsterAnim: Byte read FCurAnim write FCurAnim;
181 property UID: Word read FUID write FUID;
182 property SpawnTrigger: Integer read FSpawnTrigger write FSpawnTrigger;
184 property GameX: Integer read FObj.X write setGameX;
185 property GameY: Integer read FObj.Y write setGameY;
186 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
187 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
188 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
189 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
190 property GameDirection: TDirection read FDirection write FDirection;
192 property StartID: Integer read FStartID;
194 published
195 property eMonsterType: Byte read FMonsterType;
196 property eMonsterHealth: Integer read FHealth write FHealth;
197 property eMonsterAmmo: Integer read FAmmo write FAmmo;
198 property eMonsterTargetUID: Word read FTargetUID write FTargetUID;
199 property eMonsterTargetTime: Integer read FTargetTime write FTargetTime;
200 property eMonsterBehaviour: Byte read FBehaviour write FBehaviour;
201 property eMonsterSleep: Integer read FSleep write FSleep;
202 property eMonsterState: Byte read FState write FState;
203 property eMonsterRemoved: Boolean read FRemoved;
204 property eMonsterPain: Integer read FPain write FPain;
205 property eMonsterAnim: Byte read FCurAnim;
207 property eUID: Word read FUID;
208 property eSpawnTrigger: Integer read FSpawnTrigger;
210 property eGameX: Integer read FObj.X write setGameX;
211 property eGameY: Integer read FObj.Y write setGameY;
212 property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
213 property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
214 property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
215 property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
216 property eGameDirection: TDirection read FDirection write FDirection;
218 property eStartID: Integer read FStartID;
220 // set this before assigning something to `eDamage`
221 property eDamageType: Integer read mEDamageType write mEDamageType;
222 property eDamage: Integer write doDamage;
223 end;
226 // will be called from map loader
227 procedure g_Mons_InitTree (x, y, w, h: Integer);
229 procedure g_Monsters_LoadData ();
230 procedure g_Monsters_FreeData ();
231 procedure g_Monsters_Init ();
232 procedure g_Monsters_Free (clearGrid: Boolean=true);
233 function g_Monsters_Create (MonsterType: Byte; X, Y: Integer; Direction: TDirection;
234 AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
235 procedure g_Monsters_Update ();
236 procedure g_Monsters_Draw ();
237 procedure g_Monsters_DrawHealth ();
238 function g_Monsters_ByUID (UID: Word): TMonster;
239 procedure g_Monsters_killedp ();
240 procedure g_Monsters_SaveState (st: TStream);
241 procedure g_Monsters_LoadState (st: TStream);
243 function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
244 function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
246 function g_Mons_TypeLo (): Integer; inline;
247 function g_Mons_TypeHi (): Integer; inline;
249 function g_Mons_TypeIdByName (const name: AnsiString): Integer;
250 function g_Mons_NameByTypeId (monType: Integer): AnsiString;
251 function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
254 type
255 TEachMonsterCB = function (mon: TMonster): Boolean is nested; // return `true` to stop
257 // throws on invalid uid
258 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
260 // can return null
261 function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
263 function g_Mons_TotalCount (): Integer; inline;
265 function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
267 function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
268 function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
270 function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
271 function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
273 function g_Mons_getNewTrapFrameId (): DWord; inline;
274 function g_Mons_getNewMPlatFrameId (): LongWord; inline;
278 type
279 TMonsAlongLineCB = function (mon: TMonster; tag: Integer): Boolean is nested;
281 function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
285 var
286 gmon_debug_use_sqaccel: Boolean = true;
289 //HACK!
290 procedure g_Mons_ProfilersBegin ();
291 procedure g_Mons_ProfilersEnd ();
293 procedure g_Mons_LOS_Start (); inline;
294 procedure g_Mons_LOS_End (); inline;
296 var
297 profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
300 type
301 TMonsterGrid = specialize TBodyGridBase<TMonster>;
303 var
304 monsGrid: TMonsterGrid = nil; // DO NOT USE! public for debugging only!
307 var
308 gmon_debug_think: Boolean = true;
309 gmon_debug_one_think_step: Boolean = false;
312 implementation
314 uses
315 e_log, e_texture, g_main, g_sound, g_gfx, g_player, g_game,
316 g_weapons, g_triggers, MAPDEF, g_items, g_options,
317 g_console, g_map, Math, g_menu, wadreader,
318 g_language, g_netmsg, idpool, utils, xstreams;
322 // ////////////////////////////////////////////////////////////////////////// //
323 procedure g_Mons_ProfilersBegin ();
324 begin
325 if (profMonsLOS = nil) then profMonsLOS := TProfiler.Create('LOS CALC', g_profile_history_size);
326 if (profMonsLOS <> nil) then profMonsLOS.mainBegin(g_profile_los);
327 if g_profile_los and (profMonsLOS <> nil) then
328 begin
329 profMonsLOS.sectionBegin('loscalc');
330 profMonsLOS.sectionEnd();
331 end;
332 end;
334 procedure g_Mons_ProfilersEnd ();
335 begin
336 if (profMonsLOS <> nil) and (g_profile_los) then profMonsLOS.mainEnd();
337 end;
339 procedure g_Mons_LOS_Start (); inline;
340 begin
341 if (profMonsLOS <> nil) then profMonsLOS.sectionBeginAccum('loscalc');
342 end;
344 procedure g_Mons_LOS_End (); inline;
345 begin
346 if (profMonsLOS <> nil) then profMonsLOS.sectionEnd();
347 end;
350 // ////////////////////////////////////////////////////////////////////////// //
351 var
352 monCheckTrapLastFrameId: DWord = 0;
353 monCheckMPlatLastFrameId: LongWord = 0;
356 procedure TMonster.getMapBox (out x, y, w, h: Integer); inline;
357 begin
358 x := FObj.X+FObj.Rect.X;
359 y := FObj.Y+FObj.Rect.Y;
360 w := FObj.Rect.Width;
361 h := FObj.Rect.Height;
362 end;
364 function TMonster.gncNeedSend (): Boolean; inline; begin result := mNeedSend; mNeedSend := false; end;
366 procedure TMonster.setDirty (); inline; begin mNeedSend := true; end;
369 // ////////////////////////////////////////////////////////////////////////// //
371 function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
372 begin
373 if not assigned(cb) then begin result := nil; exit; end;
374 result := monsGrid.forEachAlongLine(x0, y0, x1, y1, cb, -1, log);
375 end;
379 //WARNING! call this after monster position was changed, or coldet will not work right!
380 procedure TMonster.positionChanged ();
381 var
382 x, y, w, h: Integer;
383 nx, ny, nw, nh: Integer;
384 begin
385 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
386 //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);
387 {$ENDIF}
388 if (mProxyId = -1) then
389 begin
390 //mNeedSend := true;
391 mProxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
392 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
393 monsGrid.getBodyXY(mProxyId, x, y);
394 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);
395 {$ENDIF}
396 end
397 else
398 begin
399 monsGrid.getBodyDims(mProxyId, x, y, w, h);
400 getMapBox(nx, ny, nw, nh);
402 if (w <> nw) or (h <> nh) then
403 begin
404 //mNeedSend := true;
405 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
406 e_WriteLog(Format('monster #%d:(%u): resized; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
407 {$ENDIF}
408 monsGrid.moveResizeBody(mProxyId, nx, ny, nw, nh);
409 end
410 else if (x <> nx) or (y <> ny) then
411 begin
412 //mNeedSend := true;
413 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
414 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);
415 {$ENDIF}
416 monsGrid.moveBody(mProxyId, nx, ny);
417 end
418 else
419 begin
420 exit; // nothing to do
421 end;
422 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
423 monsGrid.getBodyXY(mProxyId, x, y);
424 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);
425 {$ENDIF}
426 end;
427 end;
430 // ////////////////////////////////////////////////////////////////////////// //
431 const
432 ANIM_SLEEP = 0;
433 ANIM_GO = 1;
434 ANIM_DIE = 2;
435 ANIM_MESS = 3;
436 ANIM_ATTACK = 4;
437 ANIM_ATTACK2 = 5;
438 ANIM_PAIN = 6;
440 MONSTER_SIGNATURE = $534E4F4D; // 'MONS'
442 // Òàáëèöà òèïîâ àíèìàöèè ìîíñòðîâ:
443 ANIMTABLE: Array [ANIM_SLEEP..ANIM_PAIN] of
444 record
445 name: String;
446 loop: Boolean;
447 end = ((name: 'SLEEP'; loop: True),
448 (name: 'GO'; loop: True),
449 (name: 'DIE'; loop: False),
450 (name: 'MESS'; loop: False),
451 (name: 'ATTACK'; loop: False),
452 (name: 'ATTACK2'; loop: False),
453 (name: 'PAIN'; loop: False));
455 // Òàáëèöà õàðàêòåðèñòèê ìîíñòðîâ:
456 MONSTERTABLE: Array [MONSTER_DEMON..MONSTER_MAN] of
457 record
458 Name: String;
459 Rect: TRectWH;
460 Health: Word;
461 RunVel: Byte;
462 MinPain: Byte;
463 Pain: Byte;
464 Jump: Byte;
465 end =
466 ((Name:'DEMON'; Rect:(X:7; Y:8; Width:50; Height:52); Health:60;
467 RunVel: 7; MinPain: 10; Pain: 20; Jump: 10),
469 (Name:'IMP'; Rect:(X:15; Y:10; Width:34; Height:50); Health:25;
470 RunVel: 3; MinPain: 0; Pain: 15; Jump: 10),
472 (Name:'ZOMBY'; Rect:(X:15; Y:8; Width:34; Height:52); Health:15;
473 RunVel: 3; MinPain: 0; Pain: 10; Jump: 10),
475 (Name:'SERG'; Rect:(X:15; Y:8; Width:34; Height:52); Health:20;
476 RunVel: 3; MinPain: 0; Pain: 10; Jump: 10),
478 (Name:'CYBER'; Rect:(X:24; Y:9; Width:80; Height:110); Health:500;
479 RunVel: 5; MinPain: 50; Pain: 70; Jump: 10),
481 (Name:'CGUN'; Rect:(X:15; Y:4; Width:34; Height:56); Health:60;
482 RunVel: 3; MinPain: 10; Pain: 20; Jump: 10),
484 (Name:'BARON'; Rect:(X:39; Y:32; Width:50; Height:64); Health:150;
485 RunVel: 3; MinPain: 30; Pain: 40; Jump: 10),
487 (Name:'KNIGHT'; Rect:(X:39; Y:32; Width:50; Height:64); Health:75;
488 RunVel: 3; MinPain: 30; Pain: 40; Jump: 10),
490 (Name:'CACO'; Rect:(X:34; Y:36; Width:60; Height:56); Health:100;
491 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
493 (Name:'SOUL'; Rect:(X:16; Y:14; Width:32; Height:36); Health:60;
494 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
496 (Name:'PAIN'; Rect:(X:34; Y:36; Width:60; Height:56); Health:100;
497 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
499 (Name:'SPIDER'; Rect:(X:23; Y:14; Width:210; Height:100); Health:500;
500 RunVel: 4; MinPain: 50; Pain: 70; Jump: 10),
502 (Name:'BSP'; Rect:(X:14; Y:17; Width:100; Height:42); Health:150;
503 RunVel: 4; MinPain: 0; Pain: 20; Jump: 10),
505 (Name:'MANCUB'; Rect:(X:28; Y:34; Width:72; Height:60); Health:200;
506 RunVel: 3; MinPain: 20; Pain: 40; Jump: 7),
508 (Name:'SKEL'; Rect:(X:30; Y:28; Width:68; Height:72); Health:200;
509 RunVel: 6; MinPain: 20; Pain: 40; Jump: 11),
511 (Name:'VILE'; Rect:(X:30; Y:28; Width:68; Height:72); Health:150;
512 RunVel: 7; MinPain: 10; Pain: 30; Jump: 12),
514 (Name:'FISH'; Rect:(X:6; Y:11; Width:20; Height:10); Health:35;
515 RunVel: 14; MinPain: 10; Pain: 20; Jump: 6),
517 (Name:'BARREL'; Rect:(X:20; Y:13; Width:24; Height:36); Health:20;
518 RunVel: 0; MinPain: 0; Pain: 0; Jump: 0),
520 (Name:'ROBO'; Rect:(X:30; Y:26; Width:68; Height:76); Health:20;
521 RunVel: 3; MinPain: 20; Pain: 40; Jump: 6),
523 (Name:'MAN'; Rect:(X:15; Y:6; Width:34; Height:52); Health:400;
524 RunVel: 8; MinPain: 50; Pain: 70; Jump: 10));
526 // Òàáëèöà ïàðàìåòðîâ àíèìàöèè ìîíñòðîâ:
527 MONSTER_ANIMTABLE: Array [MONSTER_DEMON..MONSTER_MAN] of
528 record
529 LeftAnim: Boolean;
530 wX, wY: Integer; // Îòêóäà âûëåòèò ïóëÿ
531 AnimSpeed: Array [ANIM_SLEEP..ANIM_PAIN] of Byte;
532 AnimDeltaRight: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
533 AnimDeltaLeft: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
534 end = // SLEEP GO DIE MESS ATTACK ATTACK2 PAIN
535 ((LeftAnim: False; wX: 54; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //DEMON
536 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));
537 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))),
539 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //IMP
540 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));
541 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))),
543 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //ZOMBY
544 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));
545 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))),
547 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //SERG
548 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));
549 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))),
551 (LeftAnim: True; wX: 70; wY: 73; AnimSpeed:(3, 3, 3, 3, 3, 4, 3); //CYBER
552 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));
553 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))),
555 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 1, 0, 4); //CGUN
556 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));
557 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))),
559 (LeftAnim: True; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //BARON
560 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));
561 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))),
563 (LeftAnim: True; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //KNIGHT
564 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));
565 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))),
567 (LeftAnim: False; wX: 88; wY: 69; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //CACO
568 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));
569 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))),
571 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 4, 1, 0, 4); //SOUL
572 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));
573 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))),
575 (LeftAnim: False; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //PAIN
576 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));
577 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))),
579 (LeftAnim: True; wX: 128; wY: 64; AnimSpeed:(3, 2, 4, 4, 1, 0, 4); //SPIDER
580 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));
581 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))),
583 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 2, 3, 4, 1, 0, 4); //BSP
584 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));
585 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))),
587 (LeftAnim: False; wX: 64; wY: 64; AnimSpeed:(3, 2, 2, 4, 2, 0, 4); //MANCUB
588 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));
589 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))),
591 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 3, 3, 3, 3, 3, 3); //SKEL
592 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));
593 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))),
595 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 3, 3, 3, 3, 3, 3); //VILE
596 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));
597 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))),
599 (LeftAnim: False; wX: 8; wY: 8; AnimSpeed:(2, 2, 2, 2, 3, 0, 1); //FISH
600 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));
601 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 ))),
603 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 0, 3, 0, 0, 0, 5); //BARREL
604 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));
605 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))),
607 (LeftAnim: False; wX: 95; wY: 57; AnimSpeed:(1, 2, 1, 0, 1, 1, 0); //ROBO
608 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));
609 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))),
611 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 2, 0, 5); //MAN
612 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));
613 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))) );
615 MAX_ATM = 89; // Âðåìÿ îæèäàíèÿ ïîñëå ïîòåðè öåëè
616 MAX_SOUL = 512; // Îãðàíè÷åíèå Lost_Soul'îâ
619 // ////////////////////////////////////////////////////////////////////////// //
620 var
621 gMonsters: array of TMonster;
622 uidMap: array [0..65535] of TMonster; // monster knows it's index
623 freeInds: TIdPool = nil;
626 procedure clearUidMap ();
627 var
628 idx: Integer;
629 begin
630 for idx := 0 to High(uidMap) do uidMap[idx] := nil;
631 freeInds.clear();
632 end;
635 function g_Mons_getNewTrapFrameId (): DWord; inline;
636 var
637 f: Integer;
638 begin
639 Inc(monCheckTrapLastFrameId);
640 if (monCheckTrapLastFrameId = 0) then
641 begin
642 // wraparound
643 monCheckTrapLastFrameId := 1;
644 for f := 0 to High(gMonsters) do
645 begin
646 if (gMonsters[f] <> nil) then gMonsters[f].trapCheckFrameId := 0;
647 end;
648 end;
649 result := monCheckTrapLastFrameId;
650 end;
653 function g_Mons_getNewMPlatFrameId (): LongWord; inline;
654 var
655 f: Integer;
656 begin
657 Inc(monCheckMPlatLastFrameId);
658 if (monCheckMPlatLastFrameId = 0) then
659 begin
660 // wraparound
661 monCheckMPlatLastFrameId := 1;
662 for f := 0 to High(gMonsters) do
663 begin
664 if (gMonsters[f] <> nil) then gMonsters[f].mplatCheckFrameId := 0;
665 end;
666 end;
667 result := monCheckMPlatLastFrameId;
668 end;
671 var
672 pt_x: Integer = 0;
673 pt_xs: Integer = 1;
674 pt_y: Integer = 0;
675 pt_ys: Integer = 1;
676 soulcount: Integer = 0;
679 function allocMonster (): DWORD;
680 var
681 f, olen: Integer;
682 begin
683 result := freeInds.alloc();
684 if (result > High(gMonsters)) then
685 begin
686 olen := Length(gMonsters);
687 SetLength(gMonsters, result+64);
688 for f := olen to High(gMonsters) do gMonsters[f] := nil;
689 end;
690 end;
693 function IsFriend(a, b: Byte): Boolean;
694 begin
695 Result := True;
697 // Áî÷êà - âñåì äðóã:
698 if (a = MONSTER_BARREL) or (b = MONSTER_BARREL) then
699 Exit;
701 // Ìîíñòðû îäíîãî âèäà:
702 if a = b then
703 case a of
704 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
705 MONSTER_SOUL, MONSTER_PAIN, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
706 Exit; // Ýòè íå áüþò ñâîèõ
707 end;
709 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
710 if (a = MONSTER_SOUL) and (b = MONSTER_PAIN) then
711 Exit;
712 // Pain_Elemental íå ìîæåò ðàíèòü Lost_Soul'à:
713 if (b = MONSTER_SOUL) and (a = MONSTER_PAIN) then
714 Exit;
716 //  îñòàëüíûõ ñëó÷àÿõ - áóäóò áèòü äðóã äðóãà:
717 Result := False;
718 end;
721 function BehaviourDamage(SpawnerUID: Word; BH, SelfType: Byte): Boolean;
722 var
723 m: TMonster;
724 UIDType, MonsterType: Byte;
725 begin
726 Result := False;
727 MonsterType := 0;
729 UIDType := g_GetUIDType(SpawnerUID);
730 if UIDType = UID_MONSTER then
731 begin
732 m := g_Monsters_ByUID(SpawnerUID);
733 if m = nil then Exit;
734 MonsterType := m.FMonsterType;
735 end;
737 case BH of
738 BH_NORMAL: Result := (UIDType = UID_PLAYER) or
739 ((UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType)));
741 BH_KILLER: Result := UIDType = UID_PLAYER;
742 BH_MANIAC: Result := (UIDType = UID_PLAYER) or
743 ((UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType)));
745 BH_INSANE: Result := (UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType));
746 BH_CANNIBAL: Result := (UIDType = UID_MONSTER) and (MonsterType = SelfType);
747 end;
748 end;
751 function canShoot(m: Byte): Boolean;
752 begin
753 Result := False;
755 case m of
756 MONSTER_DEMON, MONSTER_FISH, MONSTER_BARREL:
757 Exit;
758 else
759 Result := True;
760 end;
761 end;
764 function isCorpse (o: PObj; immediately: Boolean): Integer;
766 (*
767 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
768 begin
769 atag := atag; // shut up, fpc!
770 result := false; // don't stop
771 if (mon.FState = MONSTATE_DEAD) and g_Obj_Collide(o, @mon.FObj) then
772 begin
773 case mon.FMonsterType of // Íå âîñêðåñèòü:
774 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
775 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: exit;
776 end;
777 // Îñòàëüíûõ ìîæíî âîñêðåñèòü
778 result := true;
779 end;
780 end;
781 *)
783 var
784 a: Integer;
785 mon: PMonster;
786 mres: TMonster = nil;
787 it: TMonsterGrid.Iter;
788 begin
789 result := -1;
791 // Åñëè íóæíà âåðîÿòíîñòü
792 if not immediately and (Random(8) <> 0) then exit;
794 // Èùåì ìåðòâûõ ìîíñòðîâ ïîáëèçîñòè
795 if gmon_debug_use_sqaccel then
796 begin
797 //mon := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height, monsCollCheck);
798 //if (mon <> nil) then result := mon.mArrIdx;
799 it := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height);
800 for mon in it do
801 begin
802 case mon.FMonsterType of // Íå âîñêðåñèòü:
803 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
804 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: begin end;
805 // Îñòàëüíûõ ìîæíî âîñêðåñèòü
806 else mres := mon^;
807 end;
808 if (mres <> nil) then break;
809 end;
810 it.release();
811 if (mres <> nil) then result := mres.mArrIdx;
812 end
813 else
814 begin
815 for a := 0 to High(gMonsters) do
816 begin
817 if (gMonsters[a] <> nil) and (gMonsters[a].FState = MONSTATE_DEAD) and g_Obj_Collide(o, @gMonsters[a].FObj) then
818 begin
819 case gMonsters[a].FMonsterType of // Íå âîñêðåñèòü:
820 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
821 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: Continue;
822 else // Îñòàëüíûõ ìîæíî âîñêðåñèòü
823 begin
824 Result := a;
825 Exit;
826 end;
827 end;
828 end;
829 end;
830 end;
831 end;
833 procedure g_Monsters_LoadData();
834 begin
835 e_WriteLog('Loading monsters data...', TMsgType.Notify);
837 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES], 133, False);
838 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_SLEEP', GameWAD+':MTEXTURES\BARREL_SLEEP', 64, 64, 3);
839 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_DIE', GameWAD+':MTEXTURES\BARREL_DIE', 64, 64, 4);
840 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_PAIN', GameWAD+':MTEXTURES\BARREL_PAIN', 64, 64, 1);
841 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_SLEEP', GameWAD+':MTEXTURES\ZOMBY_SLEEP', 64, 64, 2);
842 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_GO', GameWAD+':MTEXTURES\ZOMBY_GO', 64, 64, 4);
843 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_DIE', GameWAD+':MTEXTURES\ZOMBY_DIE', 64, 64, 6);
844 g_Game_StepLoading(6);
845 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_MESS', GameWAD+':MTEXTURES\ZOMBY_MESS', 64, 64, 9);
846 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK', GameWAD+':MTEXTURES\ZOMBY_ATTACK', 64, 64, 2);
847 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK_L', GameWAD+':MTEXTURES\ZOMBY_ATTACK_L', 64, 64, 2);
848 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_PAIN', GameWAD+':MTEXTURES\ZOMBY_PAIN', 64, 64, 1);
849 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_SLEEP', GameWAD+':MTEXTURES\SERG_SLEEP', 64, 64, 2);
850 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_GO', GameWAD+':MTEXTURES\SERG_GO', 64, 64, 4);
851 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_DIE', GameWAD+':MTEXTURES\SERG_DIE', 64, 64, 5);
852 g_Game_StepLoading(13);
853 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_MESS', GameWAD+':MTEXTURES\SERG_MESS', 64, 64, 9);
854 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK', GameWAD+':MTEXTURES\SERG_ATTACK', 64, 64, 2);
855 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK_L', GameWAD+':MTEXTURES\SERG_ATTACK_L', 64, 64, 2);
856 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_PAIN', GameWAD+':MTEXTURES\SERG_PAIN', 64, 64, 1);
857 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_SLEEP', GameWAD+':MTEXTURES\MAN_SLEEP', 64, 64, 2);
858 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_GO', GameWAD+':MTEXTURES\MAN_GO', 64, 64, 4);
859 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_DIE', GameWAD+':MTEXTURES\MAN_DIE', 64, 64, 7);
860 g_Game_StepLoading(20);
861 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_MESS', GameWAD+':MTEXTURES\MAN_MESS', 64, 64, 9);
862 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_ATTACK', GameWAD+':MTEXTURES\MAN_ATTACK', 64, 64, 2);
863 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_PAIN', GameWAD+':MTEXTURES\MAN_PAIN', 64, 64, 1);
864 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP', GameWAD+':MTEXTURES\CGUN_SLEEP', 64, 64, 2);
865 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP_L', GameWAD+':MTEXTURES\CGUN_SLEEP_L', 64, 64, 2);
866 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO', GameWAD+':MTEXTURES\CGUN_GO', 64, 64, 4);
867 g_Game_StepLoading(26);
868 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO_L', GameWAD+':MTEXTURES\CGUN_GO_L', 64, 64, 4);
869 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_DIE', GameWAD+':MTEXTURES\CGUN_DIE', 64, 64, 7);
870 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_MESS', GameWAD+':MTEXTURES\CGUN_MESS', 64, 64, 6);
871 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK', GameWAD+':MTEXTURES\CGUN_ATTACK', 64, 64, 2);
872 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK_L', GameWAD+':MTEXTURES\CGUN_ATTACK_L', 64, 64, 2);
873 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN', GameWAD+':MTEXTURES\CGUN_PAIN', 64, 64, 1);
874 g_Game_StepLoading(32);
875 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN_L', GameWAD+':MTEXTURES\CGUN_PAIN_L', 64, 64, 1);
876 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_SLEEP', GameWAD+':MTEXTURES\IMP_SLEEP', 64, 64, 2);
877 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_GO', GameWAD+':MTEXTURES\IMP_GO', 64, 64, 4);
878 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_DIE', GameWAD+':MTEXTURES\IMP_DIE', 64, 64, 5);
879 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_MESS', GameWAD+':MTEXTURES\IMP_MESS', 64, 64, 8);
880 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_ATTACK', GameWAD+':MTEXTURES\IMP_ATTACK', 64, 64, 3);
881 g_Game_StepLoading(38);
882 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_PAIN', GameWAD+':MTEXTURES\IMP_PAIN', 64, 64, 1);
883 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_SLEEP', GameWAD+':MTEXTURES\DEMON_SLEEP', 64, 64, 2);
884 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_GO', GameWAD+':MTEXTURES\DEMON_GO', 64, 64, 4);
885 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_DIE', GameWAD+':MTEXTURES\DEMON_DIE', 64, 64, 6);
886 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_ATTACK', GameWAD+':MTEXTURES\DEMON_ATTACK', 64, 64, 3);
887 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_PAIN', GameWAD+':MTEXTURES\DEMON_PAIN', 64, 64, 1);
888 g_Game_StepLoading(44);
889 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_SLEEP', GameWAD+':MTEXTURES\SOUL_SLEEP', 64, 64, 2);
890 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_GO', GameWAD+':MTEXTURES\SOUL_GO', 64, 64, 2);
891 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_PAIN', GameWAD+':MTEXTURES\SOUL_PAIN', 64, 64, 1);
892 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_ATTACK', GameWAD+':MTEXTURES\SOUL_ATTACK', 64, 64, 2);
893 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_DIE', GameWAD+':MTEXTURES\SOUL_DIE', 128, 128, 7);
894 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_SLEEP', GameWAD+':MTEXTURES\FISH_SLEEP', 32, 32, 2);
895 g_Game_StepLoading(50);
896 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_GO', GameWAD+':MTEXTURES\FISH_GO', 32, 32, 4);
897 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_PAIN', GameWAD+':MTEXTURES\FISH_PAIN', 32, 32, 3);
898 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_ATTACK', GameWAD+':MTEXTURES\FISH_ATTACK', 32, 32, 2);
899 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_DIE', GameWAD+':MTEXTURES\FISH_DIE', 32, 32, 1);
900 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_SLEEP', GameWAD+':MTEXTURES\SPIDER_SLEEP', 256, 128, 2);
901 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_GO', GameWAD+':MTEXTURES\SPIDER_GO', 256, 128, 6);
902 g_Game_StepLoading(56);
903 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN', GameWAD+':MTEXTURES\SPIDER_PAIN', 256, 128, 1);
904 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN_L', GameWAD+':MTEXTURES\SPIDER_PAIN_L', 256, 128, 1);
905 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_ATTACK', GameWAD+':MTEXTURES\SPIDER_ATTACK', 256, 128, 2);
906 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_DIE', GameWAD+':MTEXTURES\SPIDER_DIE', 256, 128, 10);
907 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_SLEEP', GameWAD+':MTEXTURES\BSP_SLEEP', 128, 64, 2);
908 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_GO', GameWAD+':MTEXTURES\BSP_GO', 128, 64, 6);
909 g_Game_StepLoading(62);
910 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN', GameWAD+':MTEXTURES\BSP_PAIN', 128, 64, 1);
911 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN_L', GameWAD+':MTEXTURES\BSP_PAIN_L', 128, 64, 1);
912 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_ATTACK', GameWAD+':MTEXTURES\BSP_ATTACK', 128, 64, 2);
913 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_DIE', GameWAD+':MTEXTURES\BSP_DIE', 128, 64, 7);
914 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_SLEEP', GameWAD+':MTEXTURES\CACO_SLEEP', 128, 128, 1);
915 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_GO', GameWAD+':MTEXTURES\CACO_GO', 128, 128, 1);
916 g_Game_StepLoading(68);
917 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_PAIN', GameWAD+':MTEXTURES\CACO_PAIN', 128, 128, 1);
918 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_ATTACK', GameWAD+':MTEXTURES\CACO_ATTACK', 128, 128, 6);
919 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_DIE', GameWAD+':MTEXTURES\CACO_DIE', 128, 128, 7);
920 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_SLEEP', GameWAD+':MTEXTURES\PAIN_SLEEP', 128, 128, 4);
921 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_GO', GameWAD+':MTEXTURES\PAIN_GO', 128, 128, 4);
922 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_PAIN', GameWAD+':MTEXTURES\PAIN_PAIN', 128, 128, 1);
923 g_Game_StepLoading(74);
924 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_ATTACK', GameWAD+':MTEXTURES\PAIN_ATTACK', 128, 128, 4);
925 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_DIE', GameWAD+':MTEXTURES\PAIN_DIE', 128, 128, 7);
926 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP', GameWAD+':MTEXTURES\BARON_SLEEP', 128, 128, 2);
927 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP_L', GameWAD+':MTEXTURES\BARON_SLEEP_L', 128, 128, 2);
928 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_GO', GameWAD+':MTEXTURES\BARON_GO', 128, 128, 4);
929 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN', GameWAD+':MTEXTURES\BARON_PAIN', 128, 128, 1);
930 g_Game_StepLoading(80);
931 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN_L', GameWAD+':MTEXTURES\BARON_PAIN_L', 128, 128, 1);
932 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK', GameWAD+':MTEXTURES\BARON_ATTACK', 128, 128, 3);
933 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK_L', GameWAD+':MTEXTURES\BARON_ATTACK_L', 128, 128, 3);
934 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_DIE', GameWAD+':MTEXTURES\BARON_DIE', 128, 128, 7);
935 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP', GameWAD+':MTEXTURES\KNIGHT_SLEEP', 128, 128, 2);
936 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP_L', GameWAD+':MTEXTURES\KNIGHT_SLEEP_L', 128, 128, 2);
937 g_Game_StepLoading(86);
938 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_GO', GameWAD+':MTEXTURES\KNIGHT_GO', 128, 128, 4);
939 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN', GameWAD+':MTEXTURES\KNIGHT_PAIN', 128, 128, 1);
940 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN_L', GameWAD+':MTEXTURES\KNIGHT_PAIN_L', 128, 128, 1);
941 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK', GameWAD+':MTEXTURES\KNIGHT_ATTACK', 128, 128, 3);
942 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK_L', GameWAD+':MTEXTURES\KNIGHT_ATTACK_L', 128, 128, 3);
943 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_DIE', GameWAD+':MTEXTURES\KNIGHT_DIE', 128, 128, 7);
944 g_Game_StepLoading(92);
945 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_SLEEP', GameWAD+':MTEXTURES\MANCUB_SLEEP', 128, 128, 2);
946 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_GO', GameWAD+':MTEXTURES\MANCUB_GO', 128, 128, 6);
947 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_PAIN', GameWAD+':MTEXTURES\MANCUB_PAIN', 128, 128, 1);
948 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_ATTACK', GameWAD+':MTEXTURES\MANCUB_ATTACK', 128, 128, 3);
949 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_DIE', GameWAD+':MTEXTURES\MANCUB_DIE', 128, 128, 10);
950 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP', GameWAD+':MTEXTURES\SKEL_SLEEP', 128, 128, 2);
951 g_Game_StepLoading(98);
952 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP_L', GameWAD+':MTEXTURES\SKEL_SLEEP_L', 128, 128, 2);
953 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_GO', GameWAD+':MTEXTURES\SKEL_GO', 128, 128, 6);
954 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN', GameWAD+':MTEXTURES\SKEL_PAIN', 128, 128, 1);
955 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN_L', GameWAD+':MTEXTURES\SKEL_PAIN_L', 128, 128, 1);
956 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK', GameWAD+':MTEXTURES\SKEL_ATTACK', 128, 128, 2);
957 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK_L', GameWAD+':MTEXTURES\SKEL_ATTACK_L', 128, 128, 2);
958 g_Game_StepLoading(104);
959 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2', GameWAD+':MTEXTURES\SKEL_ATTACK2', 128, 128, 2);
960 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2_L', GameWAD+':MTEXTURES\SKEL_ATTACK2_L', 128, 128, 2);
961 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_DIE', GameWAD+':MTEXTURES\SKEL_DIE', 128, 128, 5);
962 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP', GameWAD+':MTEXTURES\VILE_SLEEP', 128, 128, 2);
963 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP_L', GameWAD+':MTEXTURES\VILE_SLEEP_L', 128, 128, 2);
964 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_GO', GameWAD+':MTEXTURES\VILE_GO', 128, 128, 6);
965 g_Game_StepLoading(110);
966 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN', GameWAD+':MTEXTURES\VILE_PAIN', 128, 128, 1);
967 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN_L', GameWAD+':MTEXTURES\VILE_PAIN_L', 128, 128, 1);
968 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK', GameWAD+':MTEXTURES\VILE_ATTACK', 128, 128, 10);
969 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK_L', GameWAD+':MTEXTURES\VILE_ATTACK_L', 128, 128, 10);
970 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2', GameWAD+':MTEXTURES\VILE_ATTACK2', 128, 128, 3);
971 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2_L', GameWAD+':MTEXTURES\VILE_ATTACK2_L', 128, 128, 3);
972 g_Game_StepLoading(116);
973 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_DIE', GameWAD+':MTEXTURES\VILE_DIE', 128, 128, 9);
974 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_SLEEP', GameWAD+':MTEXTURES\ROBO_SLEEP', 128, 128, 1);
975 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_GO', GameWAD+':MTEXTURES\ROBO_GO', 128, 128, 12);
976 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK', GameWAD+':MTEXTURES\ROBO_ATTACK', 128, 128, 2);
977 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK2', GameWAD+':MTEXTURES\ROBO_ATTACK2', 128, 128, 4);
978 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_DIE', GameWAD+':MTEXTURES\ROBO_DIE', 128, 128, 1);
979 g_Game_StepLoading(122);
980 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP', GameWAD+':MTEXTURES\CYBER_SLEEP', 128, 128, 2);
981 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP_L', GameWAD+':MTEXTURES\CYBER_SLEEP_L', 128, 128, 2);
982 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO', GameWAD+':MTEXTURES\CYBER_GO', 128, 128, 4);
983 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO_L', GameWAD+':MTEXTURES\CYBER_GO_L', 128, 128, 4);
984 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN', GameWAD+':MTEXTURES\CYBER_PAIN', 128, 128, 1);
985 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN_L', GameWAD+':MTEXTURES\CYBER_PAIN_L', 128, 128, 1);
986 g_Game_StepLoading(128);
987 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK', GameWAD+':MTEXTURES\CYBER_ATTACK', 128, 128, 2);
988 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK_L', GameWAD+':MTEXTURES\CYBER_ATTACK_L', 128, 128, 2);
989 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2', GameWAD+':MTEXTURES\CYBER_ATTACK2', 128, 128, 2);
990 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2_L', GameWAD+':MTEXTURES\CYBER_ATTACK2_L', 128, 128, 2);
991 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_DIE', GameWAD+':MTEXTURES\CYBER_DIE', 128, 128, 9);
992 g_Game_StepLoading(133);
994 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_SOUNDS], 0, False);
996 g_Sound_CreateWADEx('SOUND_MONSTER_BARREL_DIE', GameWAD+':MSOUNDS\BARREL_DIE');
998 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN', GameWAD+':MSOUNDS\PAIN');
999 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN2', GameWAD+':MSOUNDS\PAIN2');
1000 g_Sound_CreateWADEx('SOUND_MONSTER_ACTION', GameWAD+':MSOUNDS\ACTION');
1001 g_Sound_CreateWADEx('SOUND_MONSTER_ACTION2', GameWAD+':MSOUNDS\ACTION2');
1002 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_1', GameWAD+':MSOUNDS\ALERT_1');
1003 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_2', GameWAD+':MSOUNDS\ALERT_2');
1004 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_3', GameWAD+':MSOUNDS\ALERT_3');
1005 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_1', GameWAD+':MSOUNDS\DIE_1');
1006 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_2', GameWAD+':MSOUNDS\DIE_2');
1007 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_3', GameWAD+':MSOUNDS\DIE_3');
1008 g_Sound_CreateWADEx('SOUND_MONSTER_SLOP', GameWAD+':MSOUNDS\SLOP');
1010 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_ATTACK', GameWAD+':MSOUNDS\DEMON_ATTACK');
1011 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_ALERT', GameWAD+':MSOUNDS\DEMON_ALERT');
1012 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_DIE', GameWAD+':MSOUNDS\DEMON_DIE');
1014 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ALERT_1', GameWAD+':MSOUNDS\IMP_ALERT_1');
1015 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ALERT_2', GameWAD+':MSOUNDS\IMP_ALERT_2');
1016 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_DIE_1', GameWAD+':MSOUNDS\IMP_DIE_1');
1017 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_DIE_2', GameWAD+':MSOUNDS\IMP_DIE_2');
1018 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ACTION', GameWAD+':MSOUNDS\IMP_ACTION');
1019 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ATTACK', GameWAD+':MSOUNDS\IMP_ATTACK');
1021 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_PAIN', GameWAD+':MSOUNDS\MAN_PAIN');
1022 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_ALERT', GameWAD+':MSOUNDS\MAN_ALERT');
1023 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_DIE', GameWAD+':MSOUNDS\MAN_DIE');
1024 g_Sound_CreateWADEx('SOUND_MONSTER_HAHA', GameWAD+':MSOUNDS\HAHA');
1025 g_Sound_CreateWADEx('SOUND_MONSTER_TRUP', GameWAD+':MSOUNDS\TRUP');
1027 g_Sound_CreateWADEx('SOUND_MONSTER_SOUL_ATTACK', GameWAD+':MSOUNDS\SOUL_ATTACK');
1028 g_Sound_CreateWADEx('SOUND_MONSTER_SOUL_DIE', GameWAD+':MSOUNDS\SOUL_DIE');
1030 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_ACTION', GameWAD+':MSOUNDS\BSP_ACTION');
1031 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_DIE', GameWAD+':MSOUNDS\BSP_DIE');
1032 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_ALERT', GameWAD+':MSOUNDS\BSP_ALERT');
1033 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_WALK', GameWAD+':MSOUNDS\BSP_WALK');
1035 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ACTION', GameWAD+':MSOUNDS\VILE_ACTION');
1036 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_PAIN', GameWAD+':MSOUNDS\VILE_PAIN');
1037 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_DIE', GameWAD+':MSOUNDS\VILE_DIE');
1038 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ALERT', GameWAD+':MSOUNDS\VILE_ALERT');
1039 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ATTACK', GameWAD+':MSOUNDS\VILE_ATTACK');
1041 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ACTION', GameWAD+':MSOUNDS\SKEL_ACTION');
1042 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_DIE', GameWAD+':MSOUNDS\SKEL_DIE');
1043 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ALERT', GameWAD+':MSOUNDS\SKEL_ALERT');
1044 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ATTACK', GameWAD+':MSOUNDS\SKEL_ATTACK');
1045 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_HIT', GameWAD+':MSOUNDS\SKEL_HIT');
1047 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_PAIN', GameWAD+':MSOUNDS\MANCUB_PAIN');
1048 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_DIE', GameWAD+':MSOUNDS\MANCUB_DIE');
1049 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_ALERT', GameWAD+':MSOUNDS\MANCUB_ALERT');
1050 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_ATTACK', GameWAD+':MSOUNDS\MANCUB_ATTACK');
1052 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_PAIN', GameWAD+':MSOUNDS\PAIN_PAIN');
1053 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_DIE', GameWAD+':MSOUNDS\PAIN_DIE');
1054 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_ALERT', GameWAD+':MSOUNDS\PAIN_ALERT');
1056 g_Sound_CreateWADEx('SOUND_MONSTER_BARON_DIE', GameWAD+':MSOUNDS\BARON_DIE');
1057 g_Sound_CreateWADEx('SOUND_MONSTER_BARON_ALERT', GameWAD+':MSOUNDS\BARON_ALERT');
1059 g_Sound_CreateWADEx('SOUND_MONSTER_CACO_DIE', GameWAD+':MSOUNDS\CACO_DIE');
1060 g_Sound_CreateWADEx('SOUND_MONSTER_CACO_ALERT', GameWAD+':MSOUNDS\CACO_ALERT');
1062 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_DIE', GameWAD+':MSOUNDS\CYBER_DIE');
1063 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_ALERT', GameWAD+':MSOUNDS\CYBER_ALERT');
1064 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_WALK', GameWAD+':MSOUNDS\CYBER_WALK');
1066 g_Sound_CreateWADEx('SOUND_MONSTER_KNIGHT_DIE', GameWAD+':MSOUNDS\KNIGHT_DIE');
1067 g_Sound_CreateWADEx('SOUND_MONSTER_KNIGHT_ALERT', GameWAD+':MSOUNDS\KNIGHT_ALERT');
1069 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_DIE', GameWAD+':MSOUNDS\SPIDER_DIE');
1070 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_ALERT', GameWAD+':MSOUNDS\SPIDER_ALERT');
1071 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_WALK', GameWAD+':MSOUNDS\SPIDER_WALK');
1073 g_Sound_CreateWADEx('SOUND_MONSTER_FISH_ATTACK', GameWAD+':MSOUNDS\FISH_ATTACK');
1075 freeInds := TIdPool.Create();
1076 clearUidMap();
1077 monCheckTrapLastFrameId := 0;
1078 monCheckMPlatLastFrameId := 0;
1079 end;
1081 procedure g_Monsters_FreeData();
1082 begin
1083 e_WriteLog('Releasing monsters data...', TMsgType.Notify);
1085 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_SLEEP');
1086 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_PAIN');
1087 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_DIE');
1088 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_SLEEP');
1089 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_GO');
1090 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_DIE');
1091 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_MESS');
1092 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK');
1093 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK_L');
1094 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_PAIN');
1095 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_SLEEP');
1096 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_GO');
1097 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_DIE');
1098 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_MESS');
1099 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK');
1100 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK_L');
1101 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_PAIN');
1102 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_SLEEP');
1103 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_GO');
1104 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_DIE');
1105 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_MESS');
1106 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_ATTACK');
1107 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_PAIN');
1108 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_SLEEP');
1109 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_SLEEP_L');
1110 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_GO');
1111 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_GO_L');
1112 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_DIE');
1113 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_MESS');
1114 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_ATTACK');
1115 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_ATTACK_L');
1116 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_PAIN');
1117 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_PAIN_L');
1118 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_SLEEP');
1119 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_GO');
1120 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_DIE');
1121 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_MESS');
1122 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_ATTACK');
1123 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_PAIN');
1124 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_SLEEP');
1125 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_GO');
1126 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_DIE');
1127 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_ATTACK');
1128 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_PAIN');
1129 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_SLEEP');
1130 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_GO');
1131 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_PAIN');
1132 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_ATTACK');
1133 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_DIE');
1134 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_SLEEP');
1135 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_GO');
1136 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_PAIN');
1137 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_ATTACK');
1138 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_DIE');
1139 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_SLEEP');
1140 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_GO');
1141 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_PAIN');
1142 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_PAIN_L');
1143 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_ATTACK');
1144 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_DIE');
1145 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_SLEEP');
1146 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_GO');
1147 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_PAIN');
1148 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_PAIN_L');
1149 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_ATTACK');
1150 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_DIE');
1151 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_SLEEP');
1152 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_GO');
1153 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_PAIN');
1154 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_ATTACK');
1155 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_DIE');
1156 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_SLEEP');
1157 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_GO');
1158 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_PAIN');
1159 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_ATTACK');
1160 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_DIE');
1161 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_SLEEP');
1162 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_SLEEP_L');
1163 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_GO');
1164 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_PAIN');
1165 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_PAIN_L');
1166 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_ATTACK');
1167 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_ATTACK_L');
1168 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_DIE');
1169 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_SLEEP');
1170 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_SLEEP_L');
1171 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_GO');
1172 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_PAIN');
1173 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_PAIN_L');
1174 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_ATTACK');
1175 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_ATTACK_L');
1176 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_DIE');
1177 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_SLEEP');
1178 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_GO');
1179 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_PAIN');
1180 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_ATTACK');
1181 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_DIE');
1182 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_SLEEP');
1183 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_SLEEP_L');
1184 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_GO');
1185 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_PAIN');
1186 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_PAIN_L');
1187 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK');
1188 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK_L');
1189 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK2');
1190 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK2_L');
1191 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_DIE');
1192 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_SLEEP');
1193 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_SLEEP_L');
1194 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_GO');
1195 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_PAIN');
1196 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_PAIN_L');
1197 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK');
1198 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK_L');
1199 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK2');
1200 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK2_L');
1201 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_DIE');
1202 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_SLEEP');
1203 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_GO');
1204 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_ATTACK');
1205 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_ATTACK2');
1206 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_DIE');
1207 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_SLEEP');
1208 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_SLEEP_L');
1209 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_GO');
1210 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_GO_L');
1211 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN');
1212 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN_L');
1213 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK');
1214 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK_L');
1215 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2');
1216 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2_L');
1217 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_DIE');
1219 g_Sound_Delete('SOUND_MONSTER_BARREL_DIE');
1221 g_Sound_Delete('SOUND_MONSTER_PAIN');
1222 g_Sound_Delete('SOUND_MONSTER_PAIN2');
1223 g_Sound_Delete('SOUND_MONSTER_ACTION');
1224 g_Sound_Delete('SOUND_MONSTER_ACTION2');
1225 g_Sound_Delete('SOUND_MONSTER_ALERT_1');
1226 g_Sound_Delete('SOUND_MONSTER_ALERT_2');
1227 g_Sound_Delete('SOUND_MONSTER_ALERT_3');
1228 g_Sound_Delete('SOUND_MONSTER_DIE_1');
1229 g_Sound_Delete('SOUND_MONSTER_DIE_2');
1230 g_Sound_Delete('SOUND_MONSTER_DIE_3');
1231 g_Sound_Delete('SOUND_MONSTER_SLOP');
1233 g_Sound_Delete('SOUND_MONSTER_DEMON_ATTACK');
1234 g_Sound_Delete('SOUND_MONSTER_DEMON_ALERT');
1235 g_Sound_Delete('SOUND_MONSTER_DEMON_DIE');
1237 g_Sound_Delete('SOUND_MONSTER_IMP_ALERT_1');
1238 g_Sound_Delete('SOUND_MONSTER_IMP_ALERT_2');
1239 g_Sound_Delete('SOUND_MONSTER_IMP_DIE_1');
1240 g_Sound_Delete('SOUND_MONSTER_IMP_DIE_2');
1241 g_Sound_Delete('SOUND_MONSTER_IMP_ACTION');
1242 g_Sound_Delete('SOUND_MONSTER_IMP_ATTACK');
1244 g_Sound_Delete('SOUND_MONSTER_MAN_PAIN');
1245 g_Sound_Delete('SOUND_MONSTER_MAN_ALERT');
1246 g_Sound_Delete('SOUND_MONSTER_MAN_DIE');
1247 g_Sound_Delete('SOUND_MONSTER_HAHA');
1248 g_Sound_Delete('SOUND_MONSTER_TRUP');
1250 g_Sound_Delete('SOUND_MONSTER_SOUL_ATTACK');
1251 g_Sound_Delete('SOUND_MONSTER_SOUL_DIE');
1253 g_Sound_Delete('SOUND_MONSTER_BSP_ACTION');
1254 g_Sound_Delete('SOUND_MONSTER_BSP_DIE');
1255 g_Sound_Delete('SOUND_MONSTER_BSP_ALERT');
1256 g_Sound_Delete('SOUND_MONSTER_BSP_WALK');
1258 g_Sound_Delete('SOUND_MONSTER_VILE_ACTION');
1259 g_Sound_Delete('SOUND_MONSTER_VILE_PAIN');
1260 g_Sound_Delete('SOUND_MONSTER_VILE_DIE');
1261 g_Sound_Delete('SOUND_MONSTER_VILE_ALERT');
1262 g_Sound_Delete('SOUND_MONSTER_VILE_ATTACK');
1264 g_Sound_Delete('SOUND_MONSTER_SKEL_ACTION');
1265 g_Sound_Delete('SOUND_MONSTER_SKEL_DIE');
1266 g_Sound_Delete('SOUND_MONSTER_SKEL_ALERT');
1267 g_Sound_Delete('SOUND_MONSTER_SKEL_ATTACK');
1268 g_Sound_Delete('SOUND_MONSTER_SKEL_HIT');
1270 g_Sound_Delete('SOUND_MONSTER_MANCUB_PAIN');
1271 g_Sound_Delete('SOUND_MONSTER_MANCUB_DIE');
1272 g_Sound_Delete('SOUND_MONSTER_MANCUB_ALERT');
1273 g_Sound_Delete('SOUND_MONSTER_MANCUB_ATTACK');
1275 g_Sound_Delete('SOUND_MONSTER_PAIN_PAIN');
1276 g_Sound_Delete('SOUND_MONSTER_PAIN_DIE');
1277 g_Sound_Delete('SOUND_MONSTER_PAIN_ALERT');
1279 g_Sound_Delete('SOUND_MONSTER_BARON_DIE');
1280 g_Sound_Delete('SOUND_MONSTER_BARON_ALERT');
1282 g_Sound_Delete('SOUND_MONSTER_CACO_DIE');
1283 g_Sound_Delete('SOUND_MONSTER_CACO_ALERT');
1285 g_Sound_Delete('SOUND_MONSTER_CYBER_DIE');
1286 g_Sound_Delete('SOUND_MONSTER_CYBER_ALERT');
1287 g_Sound_Delete('SOUND_MONSTER_CYBER_WALK');
1289 g_Sound_Delete('SOUND_MONSTER_KNIGHT_DIE');
1290 g_Sound_Delete('SOUND_MONSTER_KNIGHT_ALERT');
1292 g_Sound_Delete('SOUND_MONSTER_SPIDER_DIE');
1293 g_Sound_Delete('SOUND_MONSTER_SPIDER_ALERT');
1294 g_Sound_Delete('SOUND_MONSTER_SPIDER_WALK');
1296 g_Sound_Delete('SOUND_MONSTER_FISH_ATTACK');
1298 freeInds.Free();
1299 freeInds := nil;
1300 end;
1302 procedure g_Monsters_Init();
1303 begin
1304 soulcount := 0;
1305 end;
1307 procedure g_Monsters_Free (clearGrid: Boolean=true);
1308 var
1309 a: Integer;
1310 begin
1311 e_LogWritefln('Cleared monster data (clearGrid=%s)', [clearGrid]);
1312 if (clearGrid) then
1313 begin
1314 monsGrid.Free();
1315 monsGrid := nil;
1316 end;
1317 for a := 0 to High(gMonsters) do gMonsters[a].Free();
1318 gMonsters := nil;
1319 clearUidMap();
1320 monCheckTrapLastFrameId := 0;
1321 monCheckMPlatLastFrameId := 0;
1322 end;
1325 // will be called from map loader
1326 procedure g_Mons_InitTree (x, y, w, h: Integer);
1327 begin
1328 monsGrid.Free();
1329 monsGrid := TMonsterGrid.Create(x, y, w, h);
1330 //clearUidMap(); // why not?
1331 e_LogWritefln('%s', ['Recreated monster tree']);
1332 end;
1335 function g_Monsters_Create(MonsterType: Byte; X, Y: Integer;
1336 Direction: TDirection; AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
1337 var
1338 find_id: DWORD;
1339 mon: TMonster;
1340 begin
1341 result := nil;
1343 // Íåò òàêîãî ìîíñòðà
1344 if (MonsterType > MONSTER_MAN) or (MonsterType = 0) then exit;
1346 // Ñîáëþäàåì îãðàíè÷åíèå Lost_Soul'îâ
1347 if MonsterType = MONSTER_SOUL then
1348 begin
1349 if soulcount > MAX_SOUL then exit;
1350 soulcount := soulcount + 1;
1351 end;
1353 find_id := allocMonster();
1355 mon := TMonster.Create(MonsterType, find_id, ForcedUID);
1356 gMonsters[find_id] := mon;
1357 mon.mArrIdx := find_id;
1358 mon.mProxyId := -1;
1360 uidMap[mon.FUID] := mon;
1362 // Íàñòðàèâàåì ïîëîæåíèå
1363 with mon do
1364 begin
1365 if AdjCoord then
1366 begin
1367 FObj.X := X-FObj.Rect.X - (FObj.Rect.Width div 2);
1368 FObj.Y := Y-FObj.Rect.Y - FObj.Rect.Height;
1369 end
1370 else
1371 begin
1372 FObj.X := X-FObj.Rect.X;
1373 FObj.Y := Y-FObj.Rect.Y;
1374 end;
1376 FDirection := Direction;
1377 FStartDirection := Direction;
1378 FStartX := GameX;
1379 FStartY := GameY;
1380 end;
1382 mon.positionChanged();
1384 result := mon;
1385 end;
1387 procedure g_Monsters_killedp();
1388 var
1389 a, h: Integer;
1390 begin
1391 if gMonsters = nil then
1392 Exit;
1394 // Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
1395 h := High(gMonsters);
1396 for a := 0 to h do
1397 begin
1398 if (gMonsters[a] <> nil) then
1399 begin
1400 with gMonsters[a] do
1401 begin
1402 if (FMonsterType = MONSTER_MAN) and
1403 (FState <> MONSTATE_DEAD) and
1404 (FState <> MONSTATE_SLEEP) and
1405 (FState <> MONSTATE_DIE) then
1406 begin
1407 g_Sound_PlayExAt('SOUND_MONSTER_TRUP', FObj.X, FObj.Y);
1408 Exit;
1409 end;
1410 end;
1411 end;
1412 end;
1413 end;
1415 procedure g_Monsters_Update();
1416 var
1417 a: Integer;
1418 begin
1419 // Öåëåóêàçàòåëü
1420 if gTime mod (GAME_TICK*2) = 0 then
1421 begin
1422 pt_x := pt_x+pt_xs;
1423 pt_y := pt_y+pt_ys;
1424 if abs(pt_x) > 246 then pt_xs := -pt_xs;
1425 if abs(pt_y) > 100 then pt_ys := -pt_ys;
1426 end;
1428 gMon := True; // Äëÿ ðàáîòû BlockMon'à
1430 if gmon_debug_think or gmon_debug_one_think_step then
1431 begin
1432 gmon_debug_one_think_step := false;
1433 for a := 0 to High(gMonsters) do
1434 begin
1435 if (gMonsters[a] = nil) then continue;
1436 if not gMonsters[a].FRemoved then
1437 begin
1438 if g_Game_IsClient then
1439 gMonsters[a].ClientUpdate()
1440 else
1441 gMonsters[a].Update();
1442 end
1443 else
1444 begin
1445 gMonsters[a].Free();
1446 gMonsters[a] := nil;
1447 end;
1448 end;
1449 end;
1451 gMon := False;
1452 end;
1454 procedure g_Monsters_Draw();
1455 var
1456 a: Integer;
1457 begin
1458 if gMonsters <> nil then
1459 begin
1460 for a := 0 to High(gMonsters) do
1461 begin
1462 if (gMonsters[a] <> nil) then gMonsters[a].Draw();
1463 end;
1464 end;
1465 end;
1467 procedure g_Monsters_DrawHealth();
1468 var
1469 a: Integer;
1470 fW, fH: Byte;
1471 begin
1472 if gMonsters = nil then Exit;
1473 e_TextureFontGetSize(gStdFont, fW, fH);
1475 for a := 0 to High(gMonsters) do
1476 begin
1477 if gMonsters[a] <> nil then
1478 begin
1479 e_TextureFontPrint(gMonsters[a].FObj.X + gMonsters[a].FObj.Rect.X,
1480 gMonsters[a].FObj.Y + gMonsters[a].FObj.Rect.Y + gMonsters[a].FObj.Rect.Height - fH,
1481 IntToStr(gMonsters[a].FHealth), gStdFont);
1482 end;
1483 end;
1484 end;
1486 function g_Monsters_ByUID (UID: Word): TMonster;
1487 begin
1488 result := uidMap[UID];
1489 end;
1491 procedure g_Monsters_SaveState (st: TStream);
1492 var
1493 count, i: Integer;
1494 begin
1495 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ
1496 count := 0;
1497 for i := 0 to High(gMonsters) do
1498 begin
1499 if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then count += 1;
1500 end;
1502 // Ñîõðàíÿåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1503 utils.writeInt(st, LongInt(pt_x));
1504 utils.writeInt(st, LongInt(pt_xs));
1505 utils.writeInt(st, LongInt(pt_y));
1506 utils.writeInt(st, LongInt(pt_ys));
1508 // Êîëè÷åñòâî ìîíñòðîâ
1509 utils.writeInt(st, LongInt(count));
1511 if (count = 0) then exit;
1513 // Ñîõðàíÿåì ìîíñòðîâ
1514 for i := 0 to High(gMonsters) do
1515 begin
1516 if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then
1517 begin
1518 // Òèï ìîíñòðà
1519 utils.writeInt(st, Byte(gMonsters[i].MonsterType));
1520 // Ñîõðàíÿåì äàííûå ìîíñòðà:
1521 gMonsters[i].SaveState(st);
1522 end;
1523 end;
1524 end;
1527 procedure g_Monsters_LoadState (st: TStream);
1528 var
1529 count, a: Integer;
1530 b: Byte;
1531 mon: TMonster;
1532 begin
1533 assert(st <> nil);
1535 g_Monsters_Free(false);
1537 // Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1538 pt_x := utils.readLongInt(st);
1539 pt_xs := utils.readLongInt(st);
1540 pt_y := utils.readLongInt(st);
1541 pt_ys := utils.readLongInt(st);
1543 // Êîëè÷åñòâî ìîíñòðîâ
1544 count := utils.readLongInt(st);
1546 if (count = 0) then exit;
1547 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid monster count');
1549 // Çàãðóæàåì ìîíñòðîâ
1550 for a := 0 to count-1 do
1551 begin
1552 // Òèï ìîíñòðà
1553 b := utils.readByte(st);
1554 // Ñîçäàåì ìîíñòðà
1555 mon := g_Monsters_Create(b, 0, 0, TDirection.D_LEFT);
1556 if (mon = nil) then raise XStreamError.Create('g_Monsters_LoadState: ID = -1 (can''t create)');
1557 // Çàãðóæàåì äàííûå ìîíñòðà
1558 mon.LoadState(st);
1559 end;
1560 end;
1563 // ////////////////////////////////////////////////////////////////////////// //
1564 function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
1565 begin
1566 result := nil;
1567 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1568 begin
1569 result := g_Monsters_Create(monType, x, y, dir);
1570 end;
1571 end;
1574 function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
1575 begin
1576 result := g_Mons_SpawnAt(g_Mons_TypeIdByName(typeName), x, y, dir);
1577 end;
1581 // ////////////////////////////////////////////////////////////////////////// //
1582 function g_Mons_TypeLo (): Integer; inline; begin result := Low(MONSTERTABLE); end;
1583 function g_Mons_TypeHi (): Integer; inline; begin result := High(MONSTERTABLE); end;
1586 function g_Mons_TypeIdByName (const name: String): Integer;
1587 var
1588 i: Integer;
1589 begin
1590 i := MONSTER_DEMON;
1591 while (i <= MONSTER_MAN) do
1592 begin
1593 if (CompareText(name, MONSTERTABLE[i].Name) = 0) then
1594 begin
1595 result := i;
1596 exit;
1597 end;
1598 Inc(i);
1599 end;
1600 result := -1;
1601 // HACK!
1602 if (CompareText(name, 'zombie') = 0) then result := MONSTER_ZOMBY;
1603 end;
1606 function g_Mons_NameByTypeId (monType: Integer): AnsiString;
1607 begin
1608 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1609 result := MONSTERTABLE[monType].Name
1610 else
1611 result := '?';
1612 end;
1615 function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
1616 begin
1617 if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
1618 Result := KilledByMonster[monType]
1619 else
1620 Result := '?';
1621 end;
1624 // ////////////////////////////////////////////////////////////////////////// //
1625 { T M o n s t e r : }
1627 procedure TMonster.setGameX (v: Integer); inline; begin FObj.X := v; positionChanged(); end;
1628 procedure TMonster.setGameY (v: Integer); inline; begin FObj.Y := v; positionChanged(); end;
1630 procedure TMonster.setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline; begin FObj.X := ax; FObj.Y := ay; if callPosChanged then positionChanged(); end;
1632 procedure TMonster.moveBy (dx, dy: Integer); inline;
1633 begin
1634 if (dx <> 0) or (dy <> 0) then
1635 begin
1636 FObj.X += dx;
1637 FObj.Y += dy;
1638 positionChanged();
1639 end;
1640 end;
1642 procedure TMonster.doDamage (v: Integer);
1643 begin
1644 if (v <= 0) then exit;
1645 if (v > 32767) then v := 32767;
1646 Damage(v, 0, 0, 0, mEDamageType);
1647 end;
1649 procedure TMonster.ActionSound();
1650 begin
1651 case FMonsterType of
1652 MONSTER_IMP:
1653 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ACTION', FObj.X, FObj.Y);
1654 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN,
1655 MONSTER_MANCUB:
1656 g_Sound_PlayExAt('SOUND_MONSTER_ACTION', FObj.X, FObj.Y);
1657 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1658 MONSTER_KNIGHT, MONSTER_PAIN, MONSTER_DEMON,
1659 MONSTER_SPIDER:
1660 g_Sound_PlayExAt('SOUND_MONSTER_ACTION2', FObj.X, FObj.Y);
1661 MONSTER_BSP:
1662 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ACTION', FObj.X, FObj.Y);
1663 MONSTER_VILE:
1664 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ACTION', FObj.X, FObj.Y);
1665 MONSTER_SKEL:
1666 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ACTION', FObj.X, FObj.Y);
1667 MONSTER_CYBER:
1669 MONSTER_MAN:
1670 g_Sound_PlayExAt('SOUND_MONSTER_HAHA', FObj.X, FObj.Y);
1671 end;
1672 end;
1674 procedure TMonster.PainSound();
1675 begin
1676 if FPainSound then
1677 Exit;
1679 FPainSound := True;
1680 FPainTicks := 20;
1682 case FMonsterType of
1683 MONSTER_IMP, MONSTER_ZOMBY, MONSTER_SERG,
1684 MONSTER_SKEL, MONSTER_CGUN:
1685 g_Sound_PlayExAt('SOUND_MONSTER_PAIN', FObj.X, FObj.Y);
1686 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1687 MONSTER_KNIGHT, MONSTER_DEMON, MONSTER_SPIDER,
1688 MONSTER_BSP, MONSTER_CYBER:
1689 g_Sound_PlayExAt('SOUND_MONSTER_PAIN2', FObj.X, FObj.Y);
1690 MONSTER_VILE:
1691 g_Sound_PlayExAt('SOUND_MONSTER_VILE_PAIN', FObj.X, FObj.Y);
1692 MONSTER_MANCUB:
1693 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_PAIN', FObj.X, FObj.Y);
1694 MONSTER_PAIN:
1695 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_PAIN', FObj.X, FObj.Y);
1696 MONSTER_MAN:
1697 g_Sound_PlayExAt('SOUND_MONSTER_MAN_PAIN', FObj.X, FObj.Y);
1698 end;
1699 end;
1701 procedure TMonster.DieSound();
1702 begin
1703 case FMonsterType of
1704 MONSTER_IMP:
1705 case Random(2) of
1706 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_1', FObj.X, FObj.Y);
1707 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_2', FObj.X, FObj.Y);
1708 end;
1709 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1710 case Random(3) of
1711 0: g_Sound_PlayExAt('SOUND_MONSTER_DIE_1', FObj.X, FObj.Y);
1712 1: g_Sound_PlayExAt('SOUND_MONSTER_DIE_2', FObj.X, FObj.Y);
1713 2: g_Sound_PlayExAt('SOUND_MONSTER_DIE_3', FObj.X, FObj.Y);
1714 end;
1715 MONSTER_DEMON:
1716 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_DIE', FObj.X, FObj.Y);
1717 MONSTER_BARREL:
1718 g_Sound_PlayExAt('SOUND_MONSTER_BARREL_DIE', FObj.X, FObj.Y);
1719 MONSTER_SOUL:
1720 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_DIE', FObj.X, FObj.Y);
1721 MONSTER_BSP:
1722 g_Sound_PlayExAt('SOUND_MONSTER_BSP_DIE', FObj.X, FObj.Y);
1723 MONSTER_VILE:
1724 g_Sound_PlayExAt('SOUND_MONSTER_VILE_DIE', FObj.X, FObj.Y);
1725 MONSTER_BARON:
1726 g_Sound_PlayExAt('SOUND_MONSTER_BARON_DIE', FObj.X, FObj.Y);
1727 MONSTER_CACO:
1728 g_Sound_PlayExAt('SOUND_MONSTER_CACO_DIE', FObj.X, FObj.Y);
1729 MONSTER_CYBER:
1730 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_DIE', FObj.X, FObj.Y);
1731 MONSTER_KNIGHT:
1732 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_DIE', FObj.X, FObj.Y);
1733 MONSTER_MANCUB:
1734 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_DIE', FObj.X, FObj.Y);
1735 MONSTER_PAIN:
1736 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_DIE', FObj.X, FObj.Y);
1737 MONSTER_SKEL:
1738 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_DIE', FObj.X, FObj.Y);
1739 MONSTER_SPIDER:
1740 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_DIE', FObj.X, FObj.Y);
1741 MONSTER_MAN:
1742 g_Sound_PlayExAt('SOUND_MONSTER_MAN_DIE', FObj.X, FObj.Y);
1743 end;
1744 end;
1746 procedure TMonster.WakeUpSound();
1747 begin
1748 case FMonsterType of
1749 MONSTER_IMP:
1750 case Random(2) of
1751 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_1', FObj.X, FObj.Y);
1752 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_2', FObj.X, FObj.Y);
1753 end;
1754 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1755 case Random(3) of
1756 0: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_1', FObj.X, FObj.Y);
1757 1: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_2', FObj.X, FObj.Y);
1758 2: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_3', FObj.X, FObj.Y);
1759 end;
1760 MONSTER_MAN:
1761 g_Sound_PlayExAt('SOUND_MONSTER_MAN_ALERT', FObj.X, FObj.Y);
1762 MONSTER_BSP:
1763 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ALERT', FObj.X, FObj.Y);
1764 MONSTER_VILE:
1765 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ALERT', FObj.X, FObj.Y);
1766 MONSTER_BARON:
1767 g_Sound_PlayExAt('SOUND_MONSTER_BARON_ALERT', FObj.X, FObj.Y);
1768 MONSTER_CACO:
1769 g_Sound_PlayExAt('SOUND_MONSTER_CACO_ALERT', FObj.X, FObj.Y);
1770 MONSTER_CYBER:
1771 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_ALERT', FObj.X, FObj.Y);
1772 MONSTER_KNIGHT:
1773 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_ALERT', FObj.X, FObj.Y);
1774 MONSTER_MANCUB:
1775 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ALERT', FObj.X, FObj.Y);
1776 MONSTER_PAIN:
1777 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_ALERT', FObj.X, FObj.Y);
1778 MONSTER_DEMON:
1779 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ALERT', FObj.X, FObj.Y);
1780 MONSTER_SKEL:
1781 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ALERT', FObj.X, FObj.Y);
1782 MONSTER_SPIDER:
1783 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_ALERT', FObj.X, FObj.Y);
1784 MONSTER_SOUL:
1786 end;
1787 end;
1789 procedure TMonster.BFGHit();
1790 begin
1791 if FMonsterType = MONSTER_FISH then
1792 Exit;
1794 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1795 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1796 {if g_Game_IsServer and g_Game_IsNet then
1797 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1798 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1799 0, NET_GFX_BFG);}
1800 end;
1802 function TMonster.Collide(X, Y: Integer; Width, Height: Word): Boolean;
1803 begin
1804 Result := g_Collide(FObj.X+FObj.Rect.X,
1805 FObj.Y+FObj.Rect.Y,
1806 FObj.Rect.Width,
1807 FObj.Rect.Height,
1808 X, Y,
1809 Width, Height);
1810 end;
1812 function TMonster.Collide(Panel: TPanel): Boolean;
1813 begin
1814 Result := g_Collide(FObj.X+FObj.Rect.X,
1815 FObj.Y+FObj.Rect.Y,
1816 FObj.Rect.Width,
1817 FObj.Rect.Height,
1818 Panel.X, Panel.Y,
1819 Panel.Width, Panel.Height);
1820 end;
1822 function TMonster.Collide(X, Y: Integer): Boolean;
1823 begin
1824 X := X - FObj.X - FObj.Rect.X;
1825 Y := Y - FObj.Y - FObj.Rect.Y;
1826 Result := (x >= 0) and (x <= FObj.Rect.Width) and
1827 (y >= 0) and (y <= FObj.Rect.Height);
1828 end;
1830 procedure TMonster.Respawn;
1831 begin
1832 FObj.Vel.X := 0;
1833 FObj.Vel.Y := 0;
1834 FObj.Accel.X := 0;
1835 FObj.Accel.Y := 0;
1836 FDirection := FStartDirection;
1837 {GameX}FObj.X := FStartX;
1838 {GameY}FObj.Y := FStartY;
1839 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
1840 FHealth := MONSTERTABLE[FMonsterType].Health;
1841 FAmmo := 0;
1842 FPain := 0;
1843 FTargetUID := 0;
1844 FTargetTime := 0;
1845 FDieTriggers := nil;
1846 FWaitAttackAnim := False;
1847 FChainFire := False;
1848 FShellTimer := -1;
1850 FState := MONSTATE_SLEEP;
1851 FCurAnim := ANIM_SLEEP;
1853 positionChanged(); // this updates spatial accelerators
1855 if g_Game_IsNet and g_Game_IsServer then
1856 begin
1857 MH_SEND_MonsterPos(FUID);
1858 MH_SEND_MonsterState(FUID);
1859 end;
1860 end;
1862 constructor TMonster.Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
1863 var
1864 a: Integer;
1865 FramesID: DWORD = 0;
1866 s: String;
1867 res: Boolean;
1868 begin
1869 if ForcedUID < 0 then
1870 FUID := g_CreateUID(UID_MONSTER)
1871 else
1872 FUID := ForcedUID;
1874 FMonsterType := MonsterType;
1876 g_Obj_Init(@FObj);
1878 FState := MONSTATE_SLEEP;
1879 FCurAnim := ANIM_SLEEP;
1880 FHealth := MONSTERTABLE[MonsterType].Health;
1881 FMaxHealth := FHealth;
1882 FObj.Rect := MONSTERTABLE[MonsterType].Rect;
1883 FDieTriggers := nil;
1884 FSpawnTrigger := -1;
1885 FWaitAttackAnim := False;
1886 FChainFire := False;
1887 FStartID := aID;
1888 FNoRespawn := False;
1889 FShellTimer := -1;
1890 FBehaviour := BH_NORMAL;
1891 FFireTime := 0;
1892 FFirePainTime := 0;
1893 FFireAttacker := 0;
1894 mEDamageType := HIT_SOME;
1896 mProxyId := -1;
1897 mArrIdx := -1;
1898 trapCheckFrameId := 0;
1899 mplatCheckFrameId := 0;
1900 mNeedSend := false;
1902 if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
1903 FBloodKind := BLOOD_SPARKS
1904 else
1905 FBloodKind := BLOOD_NORMAL;
1906 if FMonsterType = MONSTER_CACO then
1907 begin
1908 FBloodRed := 0;
1909 FBloodGreen := 0;
1910 FBloodBlue := 150;
1911 end
1912 else if FMonsterType in [MONSTER_BARON, MONSTER_KNIGHT] then
1913 begin
1914 FBloodRed := 0;
1915 FBloodGreen := 150;
1916 FBloodBlue := 0;
1917 end
1918 else
1919 begin
1920 FBloodRed := 150;
1921 FBloodGreen := 0;
1922 FBloodBlue := 0;
1923 end;
1925 SetLength(FAnim, Length(ANIMTABLE));
1927 for a := 0 to High(FAnim) do
1928 begin
1929 FAnim[a, TDirection.D_LEFT] := nil;
1930 FAnim[a, TDirection.D_RIGHT] := nil;
1931 end;
1933 for a := ANIM_SLEEP to ANIM_PAIN do
1934 if (ANIMTABLE[a].name <> '') and
1935 (MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a] <> 0) then
1936 begin
1937 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1938 '_'+ANIMTABLE[a].name;
1940 res := g_Frames_Exists(s);
1942 if res then
1943 res := g_Frames_Get(FramesID, s);
1945 // Åñëè íåò òàêîé àíèìàöèè, òî ïðîáóåì çàìåíèòü åå íà àíèìàöèþ ñìåðòè:
1946 if (not res) then
1947 begin
1948 // Çàìåíÿåì òîëüêî ANIM_MESS íà ANIM_DIE:
1949 if a <> ANIM_MESS then
1950 Continue;
1952 if g_Frames_Get(FramesID, 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1953 '_'+ANIMTABLE[ANIM_DIE].name) then
1954 begin
1955 FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1956 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1957 FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1958 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1959 Continue;
1960 end;
1961 end;
1963 FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1964 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1966 // Åñëè åñòü îòäåëüíàÿ ëåâàÿ àíèìàöèÿ - çàãðóæàåì:
1967 if MONSTER_ANIMTABLE[MonsterType].LeftAnim then
1968 begin
1969 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1970 '_'+ANIMTABLE[a].name+'_L';
1971 if g_Frames_Exists(s) then
1972 g_Frames_Get(FramesID, s);
1973 end;
1975 FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1976 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1977 end;
1979 // Äëÿ êîëäóíà çàãðóæàåì òàêæå àíèìàöèþ îãíÿ:
1980 if MonsterType = MONSTER_VILE then
1981 begin
1982 g_Frames_Get(FramesID, 'FRAMES_FIRE');
1983 vilefire := TAnimation.Create(FramesID, True, 2);
1984 end
1985 else
1986 vilefire := nil;
1987 end;
1989 function TMonster.Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
1990 var
1991 c, it: Integer;
1992 p: TPlayer;
1993 begin
1994 Result := False;
1996 // Óìèðàåò, óìåð èëè âîñêðåøàåòñÿ => óðîí äåëàòü íåêîìó:
1997 if (FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE) or (FState = MONSTATE_REVIVE) then
1998 Exit;
2000 // Ðûáó â âîäå áüåò òîêîì => ïàíèêà áåç óðîíà:
2001 if (t = HIT_ELECTRO) and (FMonsterType = MONSTER_FISH) and g_Game_IsServer then
2002 begin
2003 FSleep := 20;
2004 if Random(2) = 0 then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
2005 Result := True;
2006 SetState(MONSTATE_RUN);
2007 Exit;
2008 end;
2010 // Àð÷è íå ãîðÿò, ÷åðåïà óæå ãîðÿò
2011 if (t = HIT_FLAME) and (FMonsterType in [MONSTER_VILE, MONSTER_SOUL]) then
2012 begin
2013 // Ïðîñíóòüñÿ âñå-òàêè ñòîèò
2014 if FState = MONSTATE_SLEEP then
2015 SetState(MONSTATE_GO);
2016 Exit;
2017 end;
2019 // Ëîâóøêà óáèâàåò ñðàçó:
2020 if t = HIT_TRAP then
2021 FHealth := -100;
2023 // Ðîáîòó óðîíà íåò:
2024 if FMonsterType = MONSTER_ROBO then
2025 aDamage := 0;
2027 // Íàíîñèì óðîí:
2028 if g_Game_IsServer then Dec(FHealth, aDamage);
2030 // Óñèëèâàåì áîëü ìîíñòðà îò óðîíà:
2031 if FPain = 0 then
2032 FPain := 3;
2033 FPain := FPain+aDamage;
2035 // Åñëè áîëü ñóùåñòâåííàÿ, òî ìåíÿåì ñîñòîÿíèå íà áîëåâîå:
2036 if FState <> MONSTATE_PAIN then
2037 if (FPain >= MONSTERTABLE[FMonsterType].MinPain) and
2038 (FMonsterType <> MONSTER_BARREL) then
2039 SetState(MONSTATE_PAIN);
2041 // Åñëè ðàçðåøåíà êðîâü - ñîçäàåì áðûçãè êðîâè:
2042 if (gBloodCount > 0) then
2043 begin
2044 c := Min(aDamage, 200);
2045 c := c*gBloodCount - (aDamage div 4) + Random(c div 2);
2047 if (VelX = 0) and (VelY = 0) then
2048 MakeBloodSimple(c)
2049 else
2050 case t of
2051 HIT_TRAP, HIT_ACID, HIT_ELECTRO, HIT_FLAME: MakeBloodSimple(c);
2052 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, VelX, VelY);
2053 end;
2054 end;
2056 // Òåïåðü öåëü - óäàðèâøèé, åñëè òîëüêî íå ñàì ñåáÿ:
2057 if (SpawnerUID <> FUID) and (BehaviourDamage(SpawnerUID, FBehaviour, FMonsterType)) then
2058 begin
2059 FTargetUID := SpawnerUID;
2060 FTargetTime := 0;
2061 end;
2063 // Çäîðîâüå çàêîí÷èëîñü:
2064 if FHealth <= 0 then
2065 begin
2066 // Åñëè ýòî íå áî÷êà è óáèë èãðîê, òî åìó +1:
2067 if (FMonsterType <> MONSTER_BARREL) then
2068 begin
2069 if (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2070 begin
2071 p := g_Player_Get(SpawnerUID);
2072 if (p <> nil) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2073 begin
2074 p.MonsterKills := p.MonsterKills+1;
2075 if gGameSettings.GameMode = GM_COOP then
2076 p.Frags := p.Frags + 1;
2077 // Uncomment this if you want to double-kill monsters
2078 //p.FragCombo();
2079 end;
2080 end;
2081 if gLMSRespawn = LMS_RESPAWN_NONE then
2082 begin
2083 Inc(gCoopMonstersKilled);
2084 if g_Game_IsNet then
2085 MH_SEND_GameStats;
2086 end;
2087 end;
2089 // Âûáèðàåì ëóò:
2090 case FMonsterType of
2091 MONSTER_ZOMBY: c := ITEM_AMMO_BULLETS;
2092 MONSTER_SERG: c := ITEM_WEAPON_SHOTGUN1;
2093 MONSTER_CGUN: c := ITEM_WEAPON_CHAINGUN;
2094 MONSTER_MAN: c := ITEM_KEY_RED;
2095 else c := 0;
2096 end;
2098 // Áðîñàåì ëóò:
2099 if c <> 0 then
2100 begin
2101 it := g_Items_Create(FObj.X + (FObj.Rect.Width div 2),
2102 FObj.Y + (FObj.Rect.Height div 2),
2103 c, True, False);
2104 g_Items_SetDrop(it); // mark it as monster drop
2105 g_Obj_Push(g_Items_ObjByIdx(it), (FObj.Vel.X div 2)-3+Random(7),
2106 (FObj.Vel.Y div 2)-Random(4));
2107 //positionChanged(); // this updates spatial accelerators
2108 if g_Game_IsServer and g_Game_IsNet then
2109 MH_SEND_ItemSpawn(True, it);
2110 end;
2112 // Òðóï äàëüøå íå èäåò:
2113 FObj.Vel.X := 0;
2115 // Ó òðóïà ðàçìåðû ìåíüøå:
2116 if (FMonsterType <> MONSTER_FISH) and (FMonsterType <> MONSTER_PAIN) then
2117 begin
2118 FObj.Rect.Y := FObj.Rect.Y + FObj.Rect.Height-12;
2119 FObj.Rect.Height := 12;
2120 positionChanged();
2121 end;
2123 // Óðîí áûë ñèëüíûì => ñëàáûå - â êàøó:
2124 if (FHealth <= -30) and
2125 ((FMonsterType = MONSTER_IMP) or (FMonsterType = MONSTER_ZOMBY) or
2126 (FMonsterType = MONSTER_SERG) or (FMonsterType = MONSTER_CGUN) or
2127 (FMonsterType = MONSTER_MAN)) then
2128 begin
2129 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
2130 SetState(MONSTATE_DIE, ANIM_MESS);
2131 end
2132 else
2133 begin
2134 DieSound();
2135 SetState(MONSTATE_DIE);
2136 end;
2138 // Àêòèâèðîâàòü òðèããåðû, æäóùèå ñìåðòè ýòîãî ìîíñòðà:
2139 if g_Game_IsServer then ActivateTriggers();
2141 FHealth := 0;
2142 end
2143 else
2144 if FState = MONSTATE_SLEEP then
2145 begin // Ñïàë, ðàçáóäèëè íåñìåðòåëüíûì óäàðîì:
2146 FPain := MONSTERTABLE[FMonsterType].Pain;
2147 SetState(MONSTATE_GO);
2148 end;
2150 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
2151 Result := True;
2152 end;
2154 function TMonster.Heal(Value: Word): Boolean;
2155 begin
2156 Result := False;
2157 if g_Game_IsClient then
2158 Exit;
2159 if not alive then
2160 Exit;
2162 if FHealth < FMaxHealth then
2163 begin
2164 IncMax(FHealth, Value, FMaxHealth);
2165 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
2166 Result := True;
2167 end;
2168 end;
2170 destructor TMonster.Destroy();
2171 var
2172 a: Integer;
2173 begin
2174 for a := 0 to High(FAnim) do
2175 begin
2176 FAnim[a, TDirection.D_LEFT].Free();
2177 FAnim[a, TDirection.D_RIGHT].Free();
2178 end;
2180 vilefire.Free();
2182 if (mProxyId <> -1) then
2183 begin
2184 if (monsGrid <> nil) then
2185 begin
2186 monsGrid.removeBody(mProxyId);
2187 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
2188 e_WriteLog(Format('monster #%d:(%u): removed from grid; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
2189 {$ENDIF}
2190 end;
2191 mProxyId := -1;
2192 end;
2194 if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then
2195 begin
2196 freeInds.release(mArrIdx);
2197 gMonsters[mArrIdx] := nil;
2198 end;
2199 mArrIdx := -1;
2201 uidMap[FUID] := nil;
2203 inherited Destroy();
2204 end;
2206 procedure TMonster.Draw();
2207 var
2208 m: TMirrorType;
2209 dx, dy, c: Integer;
2210 o: TObj;
2211 begin
2212 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, 'TYPE: '+IntToStr(FMonsterType));
2213 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y+16, 'STATE: '+IntToStr(FState));
2215 // Åñëè êîëäóí ñòðåëÿåò, òî ðèñóåì îãîíü:
2216 if FMonsterType = MONSTER_VILE then
2217 if FState = MONSTATE_SHOOT then
2218 if GetPos(FTargetUID, @o) then
2219 vilefire.Draw(o.X+o.Rect.X+(o.Rect.Width div 2)-32,
2220 o.Y+o.Rect.Y+o.Rect.Height-128, TMirrorType.None);
2222 // Íå â îáëàñòè ðèñîâàíèÿ íå ðåñóåì:
2223 //FIXME!
2224 if (g_dbg_scale = 1.0) then
2225 begin
2226 if not g_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height,
2227 sX-128, sY-128, sWidth+256, sHeight+256) then
2228 Exit;
2229 end;
2231 // Ýòè ìîíñòðû, óìèðàÿ, íå îñòàâëÿþò òðóïîâ:
2232 if FState = MONSTATE_DEAD then
2233 case FMonsterType of
2234 MONSTER_BARREL, MONSTER_SOUL, MONSTER_PAIN: Exit;
2235 end;
2237 // Åñòü ÷òî ðèñîâàòü ïðè òåêóùåì ïîâåäåíèè:
2238 if FAnim[FCurAnim, FDirection] <> nil then
2239 begin
2240 // Åñëè íåò ëåâîé àíèìàöèè èëè îíà ñîâïàäàåò ñ ïðàâîé => îòðàæàåì ïðàâóþ:
2241 if (FDirection = TDirection.D_LEFT) and
2242 ((not MONSTER_ANIMTABLE[FMonsterType].LeftAnim) or
2243 (FAnim[FCurAnim, TDirection.D_LEFT].FramesID = FAnim[FCurAnim, TDirection.D_RIGHT].FramesID)) and
2244 (FMonsterType <> MONSTER_BARREL) then
2245 m := TMirrorType.Horizontal
2246 else
2247 m := TMirrorType.None;
2249 // Ëåâàÿ àíèìàöèÿ => ìåíÿåì ñìåùåíèå îòíîñèòåëüíî öåíòðà:
2250 if (FDirection = TDirection.D_LEFT) and
2251 (FMonsterType <> MONSTER_BARREL) then
2252 begin
2253 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].X;
2254 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].Y;
2256 if m = TMirrorType.Horizontal then
2257 begin // Íåò îòäåëüíîé ëåâîé àíèìàöèè
2258 // Ðàññòîÿíèå îò êðàÿ òåêñòóðû äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2259 c := (MONSTERTABLE[FMonsterType].Rect.X - dx) + MONSTERTABLE[FMonsterType].Rect.Width;
2260 // Ðàññòîÿíèå îò êðàÿ õèò áîêñà äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2261 dx := FAnim[FCurAnim, FDirection].Width - c - MONSTERTABLE[FMonsterType].Rect.X;
2262 // Ò.ê. äâèãàòü òåêñòóðó íóæíî áóäåò â ïðîòèâîïîëîæíîì íàïðàâëåíèè:
2263 dx := -dx;
2264 // Ýòî çíà÷èò: dX := -frameWidth - animDeltaX + hitX + hitWidth + hitX
2265 end;
2266 end
2267 else // Ïðàâàÿ àíèìàöèÿ
2268 begin
2269 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].X;
2270 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].Y;
2271 end;
2273 // Ðèñóåì:
2274 FAnim[FCurAnim, FDirection].Draw(Obj.X+dx, Obj.Y+dy, m);
2275 end;
2277 if g_debug_Frames then
2278 begin
2279 e_DrawQuad(FObj.X+FObj.Rect.X,
2280 FObj.Y+FObj.Rect.Y,
2281 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2282 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2283 0, 255, 0);
2284 end;
2285 end;
2287 procedure TMonster.MakeBloodSimple(Count: Word);
2288 begin
2289 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)+8,
2290 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2291 Count div 2, 3, -1, 16, (FObj.Rect.Height*2 div 3),
2292 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2293 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-8,
2294 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2295 Count div 2, -3, -1, 16, (FObj.Rect.Height*2) div 3,
2296 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2297 end;
2299 procedure TMonster.MakeBloodVector(Count: Word; VelX, VelY: Integer);
2300 begin
2301 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2302 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2303 Count, VelX, VelY, 16, (FObj.Rect.Height*2) div 3,
2304 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2305 end;
2307 procedure TMonster.Push(vx, vy: Integer);
2308 begin
2309 FObj.Accel.X := FObj.Accel.X + vx;
2310 FObj.Accel.Y := FObj.Accel.Y + vy;
2311 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2312 end;
2314 procedure TMonster.SetState(State: Byte; ForceAnim: Byte = 255);
2315 var
2316 Anim: Byte;
2317 begin
2318 // Åñëè ñîñòîÿíèå = íà÷àëè óìèðàòü, à ýòîò ìîíñòð = Lost_Soul,
2319 // òî ñîáëþäàåì îãðàíè÷åíèå êîëè÷åñòâà Lost_Soul'îâ:
2320 if (State = MONSTATE_DIE) and (MonsterType = MONSTER_SOUL) then
2321 soulcount := soulcount-1;
2323 // Ïðèñìåðòè - íåëüçÿ ñðàçó íà÷èíàòü àòàêîâàòü èëè áåãàòü:
2324 case FState of
2325 MONSTATE_DIE, MONSTATE_DEAD, MONSTATE_REVIVE:
2326 if (State <> MONSTATE_DEAD) and (State <> MONSTATE_REVIVE) and
2327 (State <> MONSTATE_GO) then
2328 Exit;
2329 end;
2331 // Ñìåíà ñîñòîÿíèÿ:
2332 FState := State;
2334 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID, ForceAnim);
2336 // Íîâàÿ àíèìàöèÿ ïðè íîâîì ñîñòîÿíèè:
2337 case FState of
2338 MONSTATE_SLEEP: Anim := ANIM_SLEEP;
2339 MONSTATE_PAIN: Anim := ANIM_PAIN;
2340 MONSTATE_WAIT: Anim := ANIM_SLEEP;
2341 MONSTATE_CLIMB, MONSTATE_RUN, MONSTATE_RUNOUT, MONSTATE_GO: Anim := ANIM_GO;
2342 MONSTATE_SHOOT: Anim := ANIM_ATTACK;
2343 MONSTATE_ATTACK: Anim := ANIM_ATTACK;
2344 MONSTATE_DIE: Anim := ANIM_DIE;
2345 MONSTATE_REVIVE:
2346 begin // íà÷àëè âîñðåøàòüñÿ
2347 Anim := FCurAnim;
2348 FAnim[Anim, FDirection].Revert(True);
2350 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
2351 FHealth := MONSTERTABLE[FMonsterType].Health;
2352 FAmmo := 0;
2353 FPain := 0;
2354 end;
2355 else Exit;
2356 end;
2358 // Íàäî ñìåíèòü àíèìàöèþ íà íåñòàíäàðòíóþ:
2359 if ForceAnim <> 255 then
2360 Anim := ForceAnim;
2362 // Åñëè àíèìàöèÿ íîâàÿ - ïåðåçàïóñêàåì å¸:
2363 if FCurAnim <> Anim then
2364 if FAnim[Anim, FDirection] <> nil then
2365 begin
2366 FAnim[Anim, FDirection].Reset();
2367 FCurAnim := Anim;
2368 end;
2369 end;
2371 function TMonster.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
2372 var
2373 TA: TAnimation;
2374 FramesID: DWORD;
2375 begin
2376 Result := False;
2378 //  òî÷êå íàçíà÷åíèÿ ñòåíà:
2379 if g_CollideLevel(X, Y, FObj.Rect.Width, FObj.Rect.Height) then
2380 begin
2381 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
2382 if g_Game_IsServer and g_Game_IsNet then
2383 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
2384 Exit;
2385 end;
2387 TA := nil;
2389 // Ýôôåêò òåëåïîðòà â ïîçèöèè ìîíñòðà:
2390 if not silent then
2391 begin
2392 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
2393 TA := TAnimation.Create(FramesID, False, 6);
2394 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', Obj.X, Obj.Y);
2395 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2396 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2398 if g_Game_IsServer and g_Game_IsNet then
2399 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2400 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 1,
2401 NET_GFX_TELE);
2402 end;
2404 FObj.X := X - FObj.Rect.X;
2405 FObj.Y := Y - FObj.Rect.Y;
2406 positionChanged();
2408 if dir = 1 then
2409 FDirection := TDirection.D_LEFT
2410 else
2411 if dir = 2 then
2412 FDirection := TDirection.D_RIGHT
2413 else
2414 if dir = 3 then
2415 begin // îáðàòíîå
2416 if FDirection = TDirection.D_RIGHT then
2417 FDirection := TDirection.D_LEFT
2418 else
2419 FDirection := TDirection.D_RIGHT;
2420 end;
2422 // Ýôôåêò òåëåïîðòà â òî÷êå íàçíà÷åíèÿ:
2423 if not silent and (TA <> nil) then
2424 begin
2425 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2426 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2427 TA.Free();
2429 if g_Game_IsServer and g_Game_IsNet then
2430 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2431 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 0,
2432 NET_GFX_TELE);
2433 end;
2435 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2436 Result := True;
2437 end;
2439 procedure TMonster.Update();
2440 var
2441 a, b, sx, sy, wx, wy, oldvelx: Integer;
2442 st: Word;
2443 o, co: TObj;
2444 fall: Boolean;
2445 mon: TMonster;
2446 mit: PMonster;
2447 it: TMonsterGrid.Iter;
2448 label
2449 _end;
2450 begin
2451 fall := True;
2453 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
2454 if FMonsterType = MONSTER_FISH then
2455 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
2456 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2457 fall := False;
2459 // Ëåòàþùèå ìîíòñðû:
2460 if ((FMonsterType = MONSTER_SOUL) or
2461 (FMonsterType = MONSTER_PAIN) or
2462 (FMonsterType = MONSTER_CACO)) and
2463 (FState <> MONSTATE_DIE) and
2464 (FState <> MONSTATE_DEAD) then
2465 fall := False;
2467 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
2468 if gTime mod (GAME_TICK*2) <> 0 then
2469 begin
2470 g_Obj_Move(@FObj, fall, True, True);
2471 positionChanged(); // this updates spatial accelerators
2472 Exit;
2473 end;
2475 if FPainTicks > 0 then
2476 Dec(FPainTicks)
2477 else
2478 FPainSound := False;
2480 // Äâèãàåìñÿ:
2481 st := g_Obj_Move(@FObj, fall, True, True);
2482 positionChanged(); // this updates spatial accelerators
2484 // Åñëè ãîðèì - ïîäæèãàåì äðóãèõ ìîíñòðîâ, íî íå íà 100 òèêîâ êàæäûé ðàç:
2485 if FFireTime > 0 then
2486 begin
2487 it := monsGrid.forEachInAABB(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
2488 for mit in it do
2489 if mit.UID <> FUID then
2490 mit.CatchFire(FFireAttacker, FFireTime);
2491 end;
2493 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
2494 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
2495 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
2496 begin
2497 FRemoved := True;
2498 if alive and (gLMSRespawn = LMS_RESPAWN_NONE) then
2499 begin
2500 Inc(gCoopMonstersKilled);
2501 if g_Game_IsNet then
2502 MH_SEND_GameStats;
2503 end;
2504 ActivateTriggers();
2505 Exit;
2506 end;
2508 oldvelx := FObj.Vel.X;
2510 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
2511 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
2512 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
2514 if FFireTime > 0 then
2515 begin
2516 if WordBool(st and MOVE_INWATER) then
2517 FFireTime := 0
2518 else
2519 begin
2520 OnFireFlame(1);
2521 FFireTime := FFireTime - 1;
2522 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2523 if FFirePainTime = 0 then
2524 begin
2525 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
2526 FFirePainTime := 18;
2527 end
2528 else
2529 FFirePainTime := FFirePainTime - 1;
2530 end;
2531 end;
2533 // Ìåðòâûé íè÷åãî íå äåëàåò:
2534 if (FState = MONSTATE_DEAD) then
2535 goto _end;
2537 // AI ìîíñòðîâ âûêëþ÷åí:
2538 if g_debug_MonsterOff then
2539 begin
2540 FSleep := 1;
2541 if FState <> MONSTATE_SLEEP then
2542 SetState(MONSTATE_SLEEP);
2543 end;
2545 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
2546 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
2547 case FMonsterType of
2548 MONSTER_FISH:
2549 if Random(4) = 0 then
2550 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2551 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2552 MONSTER_ROBO, MONSTER_BARREL:
2553 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2554 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2555 else begin
2556 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
2557 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
2558 if Random(2) = 0 then
2559 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
2560 else
2561 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
2562 end;
2563 end;
2565 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
2566 if FMonsterType = MONSTER_BARREL then
2567 begin
2568 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
2569 (FAnim[FCurAnim, FDirection].Counter = 0) then
2570 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2571 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
2572 60, FUID);
2573 end;
2575 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
2576 if FMonsterType = MONSTER_SOUL then
2577 if WordBool(st and MOVE_HITAIR) then
2578 g_Obj_SetSpeed(@FObj, 16);
2580 if FAmmo < 0 then
2581 FAmmo := FAmmo + 1;
2583 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
2584 if FObj.Vel.Y < 0 then
2585 if WordBool(st and MOVE_INWATER) then
2586 FObj.Vel.Y := -4;
2588 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
2589 FTargetTime := FTargetTime + 1;
2591 // Ãèëüçû
2592 if FShellTimer > -1 then
2593 if FShellTimer = 0 then
2594 begin
2595 if FShellType = SHELL_SHELL then
2596 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2597 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2598 GameVelX, GameVelY-2, SHELL_SHELL)
2599 else if FShellType = SHELL_DBLSHELL then
2600 begin
2601 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2602 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2603 GameVelX-1, GameVelY-2, SHELL_SHELL);
2604 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2605 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2606 GameVelX+1, GameVelY-2, SHELL_SHELL);
2607 end;
2608 FShellTimer := -1;
2609 end else Dec(FShellTimer);
2611 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
2612 if fall then
2613 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
2614 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
2615 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2616 FObj.Rect.Width, FObj.Rect.Height, 50) then
2617 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2618 (FObj.Accel.Y = 0) then
2619 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2621 case FState of
2622 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
2623 begin
2624 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
2625 if FPain >= MONSTERTABLE[FMonsterType].Pain then
2626 begin
2627 FPain := MONSTERTABLE[FMonsterType].Pain;
2628 if gSoundEffectsDF then PainSound();
2629 end;
2630 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
2631 PainSound();
2633 // Ñíèæàåì áîëü ñî âðåìåíåì:
2634 FPain := FPain - 5;
2636 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
2637 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
2638 begin
2639 FPain := 0;
2640 FAmmo := -9;
2641 SetState(MONSTATE_GO);
2642 end;
2643 end;
2645 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
2646 begin
2647 // Ñïèì:
2648 FSleep := FSleep + 1;
2650 // Ïðîñïàëè äîñòàòî÷íî:
2651 if FSleep >= 18 then
2652 FSleep := 0
2653 else // åùå ñïèì
2654 goto _end;
2656 // Íà èãðîêîâ èäóò òîëüêî îáû÷íûå ìîíñòðû, êèëëåðû è ìàíüÿêè
2657 if (FBehaviour = BH_NORMAL) or (FBehaviour = BH_KILLER) or (FBehaviour = BH_MANIAC) then
2658 // Åñëè åñòü èãðîê ðÿäîì, ïðîñûïàåìñÿ è èäåì ê íåìó:
2659 if (gPlayers <> nil) then
2660 for a := 0 to High(gPlayers) do
2661 if (gPlayers[a] <> nil) and (gPlayers[a].alive)
2662 and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
2663 with gPlayers[a] do
2664 if g_Look(@FObj, @Obj, FDirection) then
2665 begin
2666 FTargetUID := gPlayers[a].UID;
2667 FTargetTime := 0;
2668 WakeUpSound();
2669 SetState(MONSTATE_GO);
2670 Break;
2671 end;
2673 // Íà ìîíñòðîâ òÿíåò ìàíüÿêîâ, ïîåõàâøèõ è êàííèáàëîâ
2674 if (FTargetUID = 0) and ((FBehaviour = BH_MANIAC)
2675 or (FBehaviour = BH_INSANE) or (FBehaviour = BH_CANNIBAL)) then
2676 // Åñëè åñòü ïîäõîäÿùèé ìîíñòð ðÿäîì:
2677 if gMonsters <> nil then
2678 for a := 0 to High(gMonsters) do
2679 if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
2680 (gMonsters[a].FUID <> FUID) then
2681 begin
2682 // Ìàíüÿêè íàïàäàþò íà âñåõ ìîíñòðîâ, êðîìå äðóçåé
2683 if (FBehaviour = BH_MANIAC) and
2684 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2685 Continue;
2686 // Ïîåõàâøèå òàêæå, íî ìîãóò îáîçëèòüñÿ íà áî÷êó
2687 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL) and
2688 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2689 Continue;
2690 // Êàííèáàëû íàïàäàþò íà ñåáå ïîäîáíûõ
2691 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
2692 Continue;
2693 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
2694 begin
2695 FTargetUID := gMonsters[a].UID;
2696 FTargetTime := 0;
2697 WakeUpSound();
2698 SetState(MONSTATE_GO);
2699 Break;
2700 end;
2701 end;
2702 end;
2704 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
2705 begin
2706 // Æäåì:
2707 FSleep := FSleep - 1;
2709 // Âûæäàëè äîñòàòî÷íî - èäåì:
2710 if FSleep < 0 then
2711 SetState(MONSTATE_GO);
2712 end;
2714 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
2715 begin
2716 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2717 if WordBool(st and MOVE_BLOCK) then
2718 begin
2719 Turn();
2720 FSleep := 40;
2721 SetState(MONSTATE_RUNOUT);
2723 goto _end;
2724 end;
2726 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
2727 if (FMonsterType = MONSTER_VILE) then
2728 if isCorpse(@FObj, False) <> -1 then
2729 begin
2730 FObj.Vel.X := 0;
2731 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
2733 goto _end;
2734 end;
2736 // Öåëü ïîãèáëà èëè äàâíî æäåì:
2737 if (not GetPos(FTargetUID, @o)) or (FTargetTime > MAX_ATM) then
2738 if not findNewPrey() then
2739 begin // Íîâûõ öåëåé íåò
2740 FTargetUID := 0;
2741 o.X := FObj.X+pt_x;
2742 o.Y := FObj.Y+pt_y;
2743 o.Vel.X := 0;
2744 o.Vel.Y := 0;
2745 o.Accel.X := 0;
2746 o.Accel.Y := 0;
2747 o.Rect := _Rect(0, 0, 0, 1);
2748 end
2749 else // Íîâàÿ öåëü åñòü - áåðåì åå êîîðäèíàòû
2750 GetPos(FTargetUID, @o);
2752 // Öåëü î÷åíü áëèçêî - ïèíàåì:
2753 if g_Obj_Collide(@FObj, @o) and (FTargetUID <> 0) then
2754 begin
2755 FTargetTime := 0;
2756 if (FMonsterType <> MONSTER_CYBER) or (Random(2) = 0) then
2757 begin
2758 if kick(@o) then
2759 goto _end;
2760 end;
2761 end;
2763 // Ðàññòîÿíèå äî öåëè:
2764 sx := o.X+o.Rect.X+(o.Rect.Width div 2)-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
2765 sy := o.Y+o.Rect.Y+(o.Rect.Height div 2)-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
2767 // Ïîâîðà÷èâàåìñÿ â ñòîðîíó öåëè:
2768 if sx > 0 then
2769 FDirection := TDirection.D_RIGHT
2770 else
2771 FDirection := TDirection.D_LEFT;
2773 // Åñëè ìîíñòð óìååò ñòðåëÿòü è åñòü ïî êîìó - ñòðåëÿåì:
2774 if canShoot(FMonsterType) and (FTargetUID <> 0) then
2775 if Abs(sx) > Abs(sy) then // óãîë âûñòðåëà óäîáíûé
2776 if shoot(@o, False) then
2777 goto _end;
2779 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
2780 if Abs(sx) < 40 then
2781 if FMonsterType <> MONSTER_FISH then
2782 begin
2783 FSleep := 15;
2784 SetState(MONSTATE_RUN);
2785 if Random(2) = 0 then
2786 FDirection := TDirection.D_LEFT
2787 else
2788 FDirection := TDirection.D_RIGHT;
2790 goto _end;
2791 end;
2793 // Óïåðëèñü â ñòåíó:
2794 if WordBool(st and MOVE_HITWALL) then
2795 begin
2796 if g_Triggers_PressR(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width,
2797 FObj.Rect.Height, FUID, ACTIVATE_MONSTERPRESS) <> nil then
2798 begin // Ñìîãëè íàæàòü êíîïêó - íåáîëüøîå îæèäàíèå
2799 FSleep := 4;
2800 SetState(MONSTATE_WAIT);
2802 goto _end;
2803 end;
2805 case FMonsterType of
2806 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
2807 else // Íå ëåòàþò:
2808 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2809 (FObj.Accel.Y = 0) then
2810 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
2811 // Ïðûæîê ÷åðåç ñòåíó:
2812 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2813 SetState(MONSTATE_CLIMB);
2814 end;
2815 end;
2817 goto _end;
2818 end;
2820 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
2821 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
2822 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
2823 begin
2824 if FMonsterType = MONSTER_FISH then
2825 begin // Ðûáà
2826 if not WordBool(st and MOVE_INWATER) then
2827 begin // Ðûáà âíå âîäû:
2828 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2829 begin // "Ñòîèò" òâåðäî
2830 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
2831 if FObj.Accel.Y = 0 then FObj.Vel.Y := -6;
2832 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
2833 end;
2835 // Ðûáå áîëüíî:
2836 SetState(MONSTATE_PAIN);
2837 FPain := FPain + 50;
2838 end
2839 else // Ðûáà â âîäå
2840 begin
2841 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2842 if Abs(sy) > 8 then
2843 FObj.Vel.Y := g_basic.Sign(sy)*4
2844 else
2845 FObj.Vel.Y := 0;
2847 // Ðûáà ïëûâåò ââåðõ:
2848 if FObj.Vel.Y < 0 then
2849 if not g_Obj_CollideLiquid(@FObj, 0, -16) then
2850 begin
2851 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
2852 FObj.Vel.Y := 0;
2853 // Ïëàâàåì òóäà-ñþäà:
2854 if Random(2) = 0 then
2855 FDirection := TDirection.D_LEFT
2856 else
2857 FDirection := TDirection.D_RIGHT;
2858 FSleep := 20;
2859 SetState(MONSTATE_RUN);
2860 end;
2861 end;
2862 end
2863 else // Ëåòàþùèå ìîíñòðû
2864 begin
2865 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2866 if Abs(sy) > 8 then
2867 FObj.Vel.Y := g_basic.Sign(sy)*4
2868 else
2869 FObj.Vel.Y := 0;
2870 end;
2871 end
2872 else // "Íàçåìíûå" ìîíñòðû
2873 begin
2874 // Âîçìîæíî, ïèíàåì êóñêè:
2875 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
2876 begin
2877 b := Abs(FObj.Vel.X);
2878 if b > 1 then b := b * (Random(8 div b) + 1);
2879 for a := 0 to High(gGibs) do
2880 begin
2881 if gGibs[a].alive and
2882 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2883 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
2884 begin
2885 // Ïèíàåì êóñêè
2886 if FObj.Vel.X < 0 then
2887 begin
2888 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
2889 end
2890 else
2891 begin
2892 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
2893 end;
2894 end;
2895 end;
2896 end;
2897 // Áîññû ìîãóò ïèíàòü òðóïû:
2898 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
2899 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
2900 begin
2901 b := Abs(FObj.Vel.X);
2902 if b > 1 then b := b * (Random(8 div b) + 1);
2903 for a := 0 to High(gCorpses) do
2904 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
2905 begin
2906 co := gCorpses[a].Obj;
2907 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2908 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
2909 // Ïèíàåì òðóïû
2910 if FObj.Vel.X < 0 then
2911 gCorpses[a].Damage(b*2, -b, Random(7)) // íàëåâî
2912 else
2913 gCorpses[a].Damage(b*2, b, Random(7)); // íàïðàâî
2914 end;
2915 end;
2916 // Åñëè öåëü âûñîêî, òî, âîçìîæíî, ïðûãàåì:
2917 if sy < -40 then
2918 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2919 // ñòîèò òâåðäî
2920 if (Random(4) = 0) and (FObj.Accel.Y = 0) then
2921 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2922 end;
2924 FSleep := FSleep + 1;
2926 // Èíîãäà ðû÷èì:
2927 if FSleep >= 8 then
2928 begin
2929 FSleep := 0;
2930 if Random(8) = 0 then
2931 ActionSound();
2932 end;
2934 // Áåæèì â âûáðàííóþ ñòîðîíó:
2935 if FDirection = TDirection.D_RIGHT then
2936 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2937 else
2938 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2940 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2941 if WordBool(st and MOVE_INWATER) then
2942 FObj.Vel.X := FObj.Vel.X div 2
2943 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2944 if FMonsterType = MONSTER_FISH then
2945 FObj.Vel.X := 0;
2946 end;
2948 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
2949 begin
2950 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2951 if WordBool(st and MOVE_BLOCK) then
2952 begin
2953 Turn();
2954 FSleep := 40;
2955 SetState(MONSTATE_RUNOUT);
2957 goto _end;
2958 end;
2960 FSleep := FSleep - 1;
2962 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
2963 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
2964 begin
2965 FSleep := 0;
2966 SetState(MONSTATE_GO);
2967 // Ñòåíà - èäåì îáðàòíî:
2968 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
2969 Turn();
2970 // Èíîãäà ðû÷èì:
2971 if Random(8) = 0 then
2972 ActionSound();
2973 end;
2975 // Áåæèì â âûáðàííóþ ñòîðîíó:
2976 if FDirection = TDirection.D_RIGHT then
2977 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2978 else
2979 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2981 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2982 if WordBool(st and MOVE_INWATER) then
2983 FObj.Vel.X := FObj.Vel.X div 2
2984 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2985 if FMonsterType = MONSTER_FISH then
2986 FObj.Vel.X := 0;
2987 end;
2989 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
2990 begin
2991 // Âûøëè èç ÁëîêÌîíà:
2992 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
2993 FSleep := 0;
2995 FSleep := FSleep - 1;
2997 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
2998 if FSleep <= -18 then
2999 begin
3000 FSleep := 0;
3001 SetState(MONSTATE_GO);
3002 // Ñòåíà/ÁëîêÌîí - èäåì îáðàòíî:
3003 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3004 Turn();
3005 // Èíîãäà ðû÷èì:
3006 if Random(8) = 0 then
3007 ActionSound();
3008 end;
3010 // Áåæèì â âûáðàííóþ ñòîðîíó:
3011 if FDirection = TDirection.D_RIGHT then
3012 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3013 else
3014 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3016 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3017 if WordBool(st and MOVE_INWATER) then
3018 FObj.Vel.X := FObj.Vel.X div 2
3019 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3020 if FMonsterType = MONSTER_FISH then
3021 FObj.Vel.X := 0;
3022 end;
3024 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
3025 begin
3026 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
3027 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
3028 (not WordBool(st and MOVE_HITWALL)) then
3029 begin
3030 FSleep := 0;
3031 SetState(MONSTATE_GO);
3033 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
3034 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3035 begin
3036 Turn();
3037 FSleep := 15;
3038 SetState(MONSTATE_RUN);
3039 end;
3040 end;
3042 // Áåæèì â âûáðàííóþ ñòîðîíó:
3043 if FDirection = TDirection.D_RIGHT then
3044 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3045 else
3046 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3048 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3049 if WordBool(st and MOVE_INWATER) then
3050 FObj.Vel.X := FObj.Vel.X div 2
3051 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3052 if FMonsterType = MONSTER_FISH then
3053 FObj.Vel.X := 0;
3054 end;
3056 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
3057 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
3058 begin
3059 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
3060 if FMonsterType = MONSTER_SOUL then
3061 begin
3062 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
3063 SetState(MONSTATE_GO);
3065 goto _end;
3066 end;
3068 // Çàìåäëÿåìñÿ ïðè àòàêå:
3069 if FMonsterType <> MONSTER_FISH then
3070 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3072 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
3073 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
3074 begin
3075 // Öåëü ïîãèáëà => èäåì äàëüøå:
3076 if not GetPos(FTargetUID, @o) then
3077 begin
3078 SetState(MONSTATE_GO);
3080 goto _end;
3081 end;
3083 // Öåëü íå âèäíî => èäåì äàëüøå:
3084 if not g_Look(@FObj, @o, FDirection) then
3085 begin
3086 SetState(MONSTATE_GO);
3088 goto _end;
3089 end;
3091 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
3092 if g_Obj_CollideWater(@o, 0, 0) then
3093 begin
3094 SetState(MONSTATE_GO);
3096 goto _end;
3097 end;
3099 // Æàðèì öåëü:
3100 tx := o.X+o.Rect.X+(o.Rect.Width div 2);
3101 ty := o.Y+o.Rect.Y+(o.Rect.Height div 2);
3102 g_Weapon_HitUID(FTargetUID, 2, FUID, HIT_SOME);
3103 end;
3104 end;
3105 end; // case FState of ...
3107 _end:
3109 // Ñîñòîÿíèå - Âîñêðåøåíèå:
3110 if FState = MONSTATE_REVIVE then
3111 if FAnim[FCurAnim, FDirection].Played then
3112 begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
3113 FAnim[FCurAnim, FDirection].Revert(False);
3114 SetState(MONSTATE_GO);
3115 end;
3117 // Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
3118 if vilefire <> nil then
3119 vilefire.Update();
3121 // Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
3122 if (FState = MONSTATE_DIE) and
3123 (FAnim[FCurAnim, FDirection] <> nil) and
3124 (FAnim[FCurAnim, FDirection].Played) then
3125 begin
3126 // Óìåð:
3127 SetState(MONSTATE_DEAD);
3129 // Pain_Elemental ïðè ñìåðòè âûïóñêàåò 3 Lost_Soul'à:
3130 if (FMonsterType = MONSTER_PAIN) then
3131 begin
3132 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-30,
3133 FObj.Y+FObj.Rect.Y+20, TDirection.D_LEFT);
3134 if mon <> nil then
3135 begin
3136 mon.SetState(MONSTATE_GO);
3137 mon.FNoRespawn := True;
3138 Inc(gTotalMonsters);
3139 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3140 end;
3142 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3143 FObj.Y+FObj.Rect.Y+20, TDirection.D_RIGHT);
3144 if mon <> nil then
3145 begin
3146 mon.SetState(MONSTATE_GO);
3147 mon.FNoRespawn := True;
3148 Inc(gTotalMonsters);
3149 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3150 end;
3152 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-15,
3153 FObj.Y+FObj.Rect.Y, TDirection.D_RIGHT);
3154 if mon <> nil then
3155 begin
3156 mon.SetState(MONSTATE_GO);
3157 mon.FNoRespawn := True;
3158 Inc(gTotalMonsters);
3159 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3160 end;
3162 if g_Game_IsNet then MH_SEND_CoopStats();
3163 end;
3165 // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
3166 if (FMonsterType = MONSTER_PAIN) or
3167 (FMonsterType = MONSTER_SOUL) or
3168 (FMonsterType = MONSTER_BARREL) then
3169 FRemoved := True;
3170 end;
3172 // Ñîâåðøåíèå àòàêè è ñòðåëüáû:
3173 if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
3174 if (FAnim[FCurAnim, FDirection] <> nil) then
3175 // Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
3176 if (FAnim[FCurAnim, FDirection].Played) then
3177 begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
3178 if FState = MONSTATE_ATTACK then
3179 begin // Ñîñòîÿíèå - Àòàêà
3180 // Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
3181 if FMonsterType <> MONSTER_SOUL then
3182 SetState(MONSTATE_GO);
3183 end
3184 else // Ñîñòîÿíèå - Ñòðåëüáà
3185 begin
3186 // Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
3187 if not FChainFire then
3188 SetState(MONSTATE_GO)
3189 else
3190 begin // Íàäî ñòðåëÿòü åùå
3191 FChainFire := False;
3192 // Ò.ê. ñîñòîÿíèå íå èçìåíèëîñü, è íóæåí
3193 // íîâûé öèêë îæèäàíèÿ çàâåðøåíèÿ àíèìàöèè:
3194 FAnim[FCurAnim, FDirection].Reset();
3195 end;
3196 end;
3198 FWaitAttackAnim := False;
3199 end
3201 else // Àíèìàöèÿ àòàêè åùå èäåò (èñêëþ÷åíèå - Lost_Soul):
3202 if (FMonsterType = MONSTER_SOUL) or
3203 ( (not FWaitAttackAnim) and
3204 (FAnim[FCurAnim, FDirection].CurrentFrame =
3205 (FAnim[FCurAnim, FDirection].TotalFrames div 2))
3206 ) then
3207 begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
3208 if FState = MONSTATE_ATTACK then
3209 begin // Ñîñòîÿíèå - Àòàêà
3210 // Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
3211 if FMonsterType = MONSTER_SOUL then
3212 FAnim[FCurAnim, FDirection].Reset();
3214 case FMonsterType of
3215 MONSTER_SOUL, MONSTER_IMP, MONSTER_DEMON:
3216 // Ãðûçåì ïåðâîãî ïîïàâøåãîñÿ:
3217 if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
3218 // Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
3219 if FMonsterType = MONSTER_SOUL then
3220 SetState(MONSTATE_GO);
3222 MONSTER_FISH:
3223 // Ðûáà êóñàåò ïåðâîãî ïîïàâøåãîñÿ ñî çâóêîì:
3224 if g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME) <> 0 then
3225 g_Sound_PlayExAt('SOUND_MONSTER_FISH_ATTACK', FObj.X, FObj.Y);
3227 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
3228 // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
3229 if FCurAnim = ANIM_ATTACK2 then
3230 begin
3231 o := FObj;
3232 o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
3233 if g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME) <> 0 then
3234 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_HIT', FObj.X, FObj.Y);
3235 end;
3237 MONSTER_VILE:
3238 // Êîëäóí ïûòàåòñÿ âîñêðåøàòü:
3239 if FCurAnim = ANIM_ATTACK2 then
3240 begin
3241 sx := isCorpse(@FObj, True);
3242 if sx <> -1 then
3243 begin // Íàøëè, êîãî âîñêðåñèòü
3244 gMonsters[sx].SetState(MONSTATE_REVIVE);
3245 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
3246 // Âîñêðåøàòü - ñåáå âðåäèòü:
3247 {g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
3248 end;
3249 end;
3250 end;
3251 end
3253 else // Ñîñòîÿíèå - Ñòðåëüáà
3254 begin
3255 // Âû÷èñëÿåì êîîðäèíàòû, îòêóäà âûëåòèò ïóëÿ:
3256 wx := MONSTER_ANIMTABLE[FMonsterType].wX;
3258 if FDirection = TDirection.D_LEFT then
3259 begin
3260 wx := MONSTER_ANIMTABLE[FMonsterType].wX-(MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2));
3261 wx := MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2)-wx;
3262 end; // Ýòî çíà÷èò: wx := hitX + (hitWidth / 2) - (wx - (hitX + (hitWidth / 2)))
3264 wx := FObj.X + wx;
3265 wy := FObj.Y + MONSTER_ANIMTABLE[FMonsterType].wY;
3267 // Ìîíñòð íå ìîæåò öåëèòüñÿ â îáúåêò çà ñïèíîé, ñòðåëÿÿ âëåâî:
3268 if (FDirection = TDirection.D_LEFT) and (tx > wx) then
3269 begin
3270 tx := wx - 32;
3271 ty := wy + Random(11) - 5;
3272 end;
3273 // È àíàëîãè÷íî, ñòðåëÿÿ âïðàâî:
3274 if (FDirection = TDirection.D_RIGHT) and (tx < wx) then
3275 begin
3276 tx := wx + 32;
3277 ty := wy + Random(11) - 5;
3278 end;
3280 // Äåëàåì âûñòðåë íóæíûì îðóæèåì:
3281 case FMonsterType of
3282 MONSTER_IMP:
3283 g_Weapon_ball1(wx, wy, tx, ty, FUID);
3284 MONSTER_ZOMBY:
3285 begin
3286 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3287 g_Weapon_gun(wx, wy, tx, ty, 1, 3, FUID, True);
3288 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3289 end;
3290 MONSTER_SERG:
3291 begin
3292 g_Weapon_shotgun(wx, wy, tx, ty, FUID);
3293 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3294 FShellTimer := 10;
3295 FShellType := SHELL_SHELL;
3296 end;
3297 MONSTER_MAN:
3298 begin
3299 g_Weapon_dshotgun(wx, wy, tx, ty, FUID);
3300 FShellTimer := 13;
3301 FShellType := SHELL_DBLSHELL;
3302 FAmmo := -36;
3303 end;
3304 MONSTER_CYBER:
3305 begin
3306 g_Weapon_rocket(wx, wy, tx, ty, FUID);
3307 // MH_SEND_MonsterAttack(FUID, wx, wy, tx, ty);
3308 end;
3309 MONSTER_SKEL:
3310 g_Weapon_revf(wx, wy, tx, ty, FUID, FTargetUID);
3311 MONSTER_CGUN:
3312 begin
3313 g_Weapon_mgun(wx, wy, tx, ty, FUID);
3314 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3315 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3316 end;
3317 MONSTER_SPIDER:
3318 begin
3319 g_Weapon_mgun(wx, wy, tx, ty, FUID);
3320 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3321 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
3322 end;
3323 MONSTER_BSP:
3324 g_Weapon_aplasma(wx, wy, tx, ty, FUID);
3325 MONSTER_ROBO:
3326 g_Weapon_plasma(wx, wy, tx, ty, FUID);
3327 MONSTER_MANCUB:
3328 g_Weapon_manfire(wx, wy, tx, ty, FUID);
3329 MONSTER_BARON, MONSTER_KNIGHT:
3330 g_Weapon_ball7(wx, wy, tx, ty, FUID);
3331 MONSTER_CACO:
3332 g_Weapon_ball2(wx, wy, tx, ty, FUID);
3333 MONSTER_PAIN:
3334 begin // Ñîçäàåì Lost_Soul:
3335 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+(FObj.Rect.Width div 2),
3336 FObj.Y+FObj.Rect.Y, FDirection);
3338 if mon <> nil then
3339 begin // Öåëü - öåëü Pain_Elemental'à. Ëåòèì ê íåé:
3340 mon.FTargetUID := FTargetUID;
3341 GetPos(FTargetUID, @o);
3342 mon.FTargetTime := 0;
3343 mon.FNoRespawn := True;
3344 mon.SetState(MONSTATE_GO);
3345 mon.shoot(@o, True);
3346 Inc(gTotalMonsters);
3348 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3349 end;
3350 end;
3351 end;
3353 if FMonsterType <> MONSTER_PAIN then
3354 if g_Game_IsNet then
3355 MH_SEND_MonsterShot(FUID, wx, wy, tx, ty);
3357 // Ñêîðîñòðåëüíûå ìîíñòðû:
3358 if (FMonsterType = MONSTER_CGUN) or
3359 (FMonsterType = MONSTER_SPIDER) or
3360 (FMonsterType = MONSTER_BSP) or
3361 (FMonsterType = MONSTER_MANCUB) or
3362 (FMonsterType = MONSTER_ROBO) then
3363 if not GetPos(FTargetUID, @o) then
3364 // Öåëü ìåðòâà - èùåì íîâóþ:
3365 findNewPrey()
3366 else // Öåëü æèâà - ïðîäîëæàåì ñòðåëÿòü:
3367 if shoot(@o, False) then
3368 FChainFire := True;
3369 end;
3371 // Àòàêà òîëüêî 1 ðàç çà àíèìàöèþ àòàêè:
3372 FWaitAttackAnim := True;
3373 end;
3375 // Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
3376 if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
3377 case FState of
3378 MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
3379 // Çâóêè ïðè ïåðåäâèæåíèè:
3380 case FMonsterType of
3381 MONSTER_CYBER:
3382 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3383 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3384 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_WALK', FObj.X, FObj.Y);
3385 MONSTER_SPIDER:
3386 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3387 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3388 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_WALK', FObj.X, FObj.Y);
3389 MONSTER_BSP:
3390 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3391 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3392 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3393 MONSTER_ROBO:
3394 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3395 (FAnim[FCurAnim, FDirection].CurrentFrame = 5) then
3396 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3397 end;
3398 end;
3400 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
3401 not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
3402 FObj.Vel.X := oldvelx;
3404 // Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
3405 if FAnim[FCurAnim, FDirection] <> nil then
3406 FAnim[FCurAnim, FDirection].Update();
3407 end;
3409 procedure TMonster.SetDeadAnim;
3410 begin
3411 if FAnim <> nil then
3412 FAnim[FCurAnim, FDirection].CurrentFrame := FAnim[FCurAnim, FDirection].TotalFrames - 1;
3413 end;
3415 procedure TMonster.RevertAnim(R: Boolean = True);
3416 begin
3417 if FAnim <> nil then
3418 if FAnim[FCurAnim, FDirection].IsReverse <> R then
3419 FAnim[FCurAnim, FDirection].Revert(R);
3420 end;
3422 function TMonster.AnimIsReverse: Boolean;
3423 begin
3424 if FAnim <> nil then
3425 Result := FAnim[FCurAnim, FDirection].IsReverse
3426 else
3427 Result := False;
3428 end;
3430 procedure TMonster.ClientUpdate();
3431 var
3432 a, b, sx, sy, oldvelx: Integer;
3433 st: Word;
3434 o, co: TObj;
3435 fall: Boolean;
3436 label
3437 _end;
3438 begin
3439 sx := 0; // SHUT UP COMPILER
3440 sy := 0;
3441 fall := True;
3442 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
3443 if FMonsterType = MONSTER_FISH then
3444 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3445 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
3446 fall := False;
3448 // Ëåòàþùèå ìîíòñðû:
3449 if ((FMonsterType = MONSTER_SOUL) or
3450 (FMonsterType = MONSTER_PAIN) or
3451 (FMonsterType = MONSTER_CACO)) and
3452 (FState <> MONSTATE_DIE) and
3453 (FState <> MONSTATE_DEAD) then
3454 fall := False;
3456 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
3457 if gTime mod (GAME_TICK*2) <> 0 then
3458 begin
3459 g_Obj_Move(@FObj, fall, True, True);
3460 positionChanged(); // this updates spatial accelerators
3461 Exit;
3462 end;
3464 if FPainTicks > 0 then
3465 Dec(FPainTicks)
3466 else
3467 FPainSound := False;
3469 // Äâèãàåìñÿ:
3470 st := g_Obj_Move(@FObj, fall, True, True);
3471 positionChanged(); // this updates spatial accelerators
3473 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
3474 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
3475 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
3476 begin
3477 FRemoved := True;
3478 Exit;
3479 end;
3481 oldvelx := FObj.Vel.X;
3483 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
3484 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
3485 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3487 if FFireTime > 0 then
3488 begin
3489 if WordBool(st and MOVE_INWATER) then
3490 FFireTime := 0
3491 else
3492 begin
3493 OnFireFlame(1);
3494 FFireTime := FFireTime - 1;
3495 end;
3496 end;
3498 // Ìåðòâûé íè÷åãî íå äåëàåò:
3499 if (FState = MONSTATE_DEAD) then
3500 goto _end;
3502 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
3503 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
3504 case FMonsterType of
3505 MONSTER_FISH:
3506 if Random(4) = 0 then
3507 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
3508 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
3509 MONSTER_ROBO, MONSTER_BARREL:
3510 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
3511 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
3512 else begin
3513 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
3514 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
3515 if Random(2) = 0 then
3516 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
3517 else
3518 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
3519 end;
3520 end;
3522 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
3523 if FMonsterType = MONSTER_BARREL then
3524 begin
3525 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
3526 (FAnim[FCurAnim, FDirection].Counter = 0) then
3527 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3528 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
3529 60, FUID);
3530 end;
3532 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
3533 if FMonsterType = MONSTER_SOUL then
3534 if WordBool(st and MOVE_HITAIR) then
3535 g_Obj_SetSpeed(@FObj, 16);
3537 if FAmmo < 0 then
3538 FAmmo := FAmmo + 1;
3540 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
3541 if FObj.Vel.Y < 0 then
3542 if WordBool(st and MOVE_INWATER) then
3543 FObj.Vel.Y := -4;
3545 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
3546 FTargetTime := FTargetTime + 1;
3548 if FShellTimer > -1 then
3549 if FShellTimer = 0 then
3550 begin
3551 if FShellType = SHELL_SHELL then
3552 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3553 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3554 GameVelX, GameVelY-2, SHELL_SHELL)
3555 else if FShellType = SHELL_DBLSHELL then
3556 begin
3557 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3558 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3559 GameVelX-1, GameVelY-2, SHELL_SHELL);
3560 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3561 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3562 GameVelX+1, GameVelY-2, SHELL_SHELL);
3563 end;
3564 FShellTimer := -1;
3565 end else Dec(FShellTimer);
3567 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
3568 if fall then
3569 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
3570 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
3571 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3572 FObj.Rect.Width, FObj.Rect.Height, 50) then
3573 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
3574 (FObj.Accel.Y = 0) then
3575 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
3577 case FState of
3578 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
3579 begin
3580 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
3581 if FPain >= MONSTERTABLE[FMonsterType].Pain then
3582 begin
3583 FPain := MONSTERTABLE[FMonsterType].Pain;
3584 if gSoundEffectsDF then PainSound();
3585 end;
3586 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
3587 PainSound();
3589 // Ñíèæàåì áîëü ñî âðåìåíåì:
3590 FPain := FPain - 5;
3592 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
3593 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
3594 begin
3595 SetState(MONSTATE_GO);
3596 FPain := 0;
3597 end;
3598 end;
3600 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
3601 begin
3602 // Ñïèì:
3603 FSleep := FSleep + 1;
3605 // Ïðîñïàëè äîñòàòî÷íî:
3606 if FSleep >= 18 then
3607 FSleep := 0
3608 else // åùå ñïèì
3609 goto _end;
3610 end;
3612 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
3613 begin
3614 // Æäåì:
3615 FSleep := FSleep - 1;
3616 end;
3618 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
3619 begin
3620 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
3621 if WordBool(st and MOVE_BLOCK) then
3622 begin
3623 Turn();
3624 FSleep := 40;
3625 SetState(MONSTATE_RUNOUT);
3627 goto _end;
3628 end;
3630 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
3631 if (FMonsterType = MONSTER_VILE) then
3632 if isCorpse(@FObj, False) <> -1 then
3633 begin
3634 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
3635 FObj.Vel.X := 0;
3637 goto _end;
3638 end;
3640 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
3641 if Abs(sx) < 40 then
3642 if FMonsterType <> MONSTER_FISH then
3643 begin
3644 SetState(MONSTATE_RUN);
3645 FSleep := 15;
3647 goto _end;
3648 end;
3650 // Óïåðëèñü â ñòåíó:
3651 if WordBool(st and MOVE_HITWALL) then
3652 begin
3653 case FMonsterType of
3654 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
3655 else // Íå ëåòàþò:
3656 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
3657 (FObj.Accel.Y = 0) then
3658 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
3659 // Ïðûæîê ÷åðåç ñòåíó:
3660 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
3661 SetState(MONSTATE_CLIMB);
3662 end;
3663 end;
3665 goto _end;
3666 end;
3668 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
3669 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
3670 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
3671 begin
3672 if FMonsterType = MONSTER_FISH then
3673 begin // Ðûáà
3674 if not WordBool(st and MOVE_INWATER) then
3675 begin // Ðûáà âíå âîäû:
3676 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
3677 begin // "Ñòîèò" òâåðäî
3678 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
3679 if FObj.Accel.Y = 0 then
3680 FObj.Vel.Y := -6;
3681 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
3682 end;
3684 // Ðûáå áîëüíî:
3685 SetState(MONSTATE_PAIN);
3686 FPain := FPain + 50;
3687 end
3688 else // Ðûáà â âîäå
3689 begin
3690 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
3691 if Abs(sy) > 8 then
3692 FObj.Vel.Y := g_basic.Sign(sy)*4
3693 else
3694 FObj.Vel.Y := 0;
3696 // Ðûáà ïëûâåò ââåðõ:
3697 if FObj.Vel.Y < 0 then
3698 if not g_Obj_CollideLiquid(@FObj, 0, -16) then
3699 begin
3700 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
3701 FObj.Vel.Y := 0;
3702 // Ïëàâàåì òóäà-ñþäà:
3703 SetState(MONSTATE_RUN);
3704 FSleep := 20;
3705 end;
3706 end;
3707 end
3708 else // Ëåòàþùèå ìîíñòðû
3709 begin
3710 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
3711 if Abs(sy) > 8 then
3712 FObj.Vel.Y := g_basic.Sign(sy)*4
3713 else
3714 FObj.Vel.Y := 0;
3715 end;
3716 end
3717 else // "Íàçåìíûå" ìîíñòðû
3718 begin
3719 // Âîçìîæíî, ïèíàåì êóñêè:
3720 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
3721 begin
3722 b := Abs(FObj.Vel.X);
3723 if b > 1 then b := b * (Random(8 div b) + 1);
3724 for a := 0 to High(gGibs) do
3725 begin
3726 if gGibs[a].alive and
3727 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
3728 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
3729 begin
3730 // Ïèíàåì êóñêè
3731 if FObj.Vel.X < 0 then
3732 begin
3733 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
3734 end
3735 else
3736 begin
3737 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
3738 end;
3739 positionChanged(); // this updates spatial accelerators
3740 end;
3741 end;
3742 end;
3743 // Áîññû ìîãóò ïèíàòü òðóïû:
3744 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
3745 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
3746 begin
3747 b := Abs(FObj.Vel.X);
3748 if b > 1 then b := b * (Random(8 div b) + 1);
3749 for a := 0 to High(gCorpses) do
3750 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
3751 begin
3752 co := gCorpses[a].Obj;
3753 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
3754 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
3755 // Ïèíàåì òðóïû
3756 if FObj.Vel.X < 0 then
3757 gCorpses[a].Damage(b*2, -b, Random(7)) // íàëåâî
3758 else
3759 gCorpses[a].Damage(b*2, b, Random(7)); // íàïðàâî
3760 end;
3761 end;
3762 end;
3764 FSleep := FSleep + 1;
3766 // Èíîãäà ðû÷èì:
3767 if FSleep >= 8 then
3768 begin
3769 FSleep := 0;
3770 if Random(8) = 0 then
3771 ActionSound();
3772 end;
3774 // Áåæèì â âûáðàííóþ ñòîðîíó:
3775 if FDirection = TDirection.D_RIGHT then
3776 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3777 else
3778 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3780 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3781 if WordBool(st and MOVE_INWATER) then
3782 FObj.Vel.X := FObj.Vel.X div 2
3783 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3784 if FMonsterType = MONSTER_FISH then
3785 FObj.Vel.X := 0;
3786 end;
3788 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
3789 begin
3790 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
3791 if WordBool(st and MOVE_BLOCK) then
3792 begin
3793 SetState(MONSTATE_RUNOUT);
3794 FSleep := 40;
3796 goto _end;
3797 end;
3799 FSleep := FSleep - 1;
3801 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
3802 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
3803 begin
3804 SetState(MONSTATE_GO);
3805 FSleep := 0;
3807 // Èíîãäà ðû÷èì:
3808 if Random(8) = 0 then
3809 ActionSound();
3810 end;
3812 // Áåæèì â âûáðàííóþ ñòîðîíó:
3813 if FDirection = TDirection.D_RIGHT then
3814 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3815 else
3816 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3818 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3819 if WordBool(st and MOVE_INWATER) then
3820 FObj.Vel.X := FObj.Vel.X div 2
3821 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3822 if FMonsterType = MONSTER_FISH then
3823 FObj.Vel.X := 0;
3824 end;
3826 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
3827 begin
3828 // Âûøëè èç ÁëîêÌîíà:
3829 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
3830 FSleep := 0;
3832 FSleep := FSleep - 1;
3834 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
3835 if FSleep <= -18 then
3836 begin
3837 SetState(MONSTATE_GO);
3838 FSleep := 0;
3840 // Èíîãäà ðû÷èì:
3841 if Random(8) = 0 then
3842 ActionSound();
3843 end;
3845 // Áåæèì â âûáðàííóþ ñòîðîíó:
3846 if FDirection = TDirection.D_RIGHT then
3847 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3848 else
3849 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3851 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3852 if WordBool(st and MOVE_INWATER) then
3853 FObj.Vel.X := FObj.Vel.X div 2
3854 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3855 if FMonsterType = MONSTER_FISH then
3856 FObj.Vel.X := 0;
3857 end;
3859 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
3860 begin
3861 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
3862 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
3863 (not WordBool(st and MOVE_HITWALL)) then
3864 begin
3865 SetState(MONSTATE_GO);
3866 FSleep := 0;
3868 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
3869 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3870 begin
3871 SetState(MONSTATE_RUN);
3872 FSleep := 15;
3873 end;
3874 end;
3876 // Áåæèì â âûáðàííóþ ñòîðîíó:
3877 if FDirection = TDirection.D_RIGHT then
3878 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3879 else
3880 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3882 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3883 if WordBool(st and MOVE_INWATER) then
3884 FObj.Vel.X := FObj.Vel.X div 2
3885 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3886 if FMonsterType = MONSTER_FISH then
3887 FObj.Vel.X := 0;
3888 end;
3890 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
3891 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
3892 begin
3893 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
3894 if FMonsterType = MONSTER_SOUL then
3895 begin
3896 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
3897 SetState(MONSTATE_GO);
3899 goto _end;
3900 end;
3902 // Çàìåäëÿåìñÿ ïðè àòàêå:
3903 if FMonsterType <> MONSTER_FISH then
3904 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3906 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
3907 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
3908 begin
3909 // Öåëü ïîãèáëà => èäåì äàëüøå:
3910 if not GetPos(FTargetUID, @o) then
3911 begin
3912 SetState(MONSTATE_GO);
3914 goto _end;
3915 end;
3917 // Öåëü íå âèäíî => èäåì äàëüøå:
3918 if not g_Look(@FObj, @o, FDirection) then
3919 begin
3920 SetState(MONSTATE_GO);
3922 goto _end;
3923 end;
3925 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
3926 if g_Obj_CollideWater(@o, 0, 0) then
3927 begin
3928 SetState(MONSTATE_GO);
3930 goto _end;
3931 end;
3932 end;
3933 end;
3934 end; // case FState of ...
3936 _end:
3938 // Ñîñòîÿíèå - Âîñêðåøåíèå:
3939 if FState = MONSTATE_REVIVE then
3940 if FAnim[FCurAnim, FDirection].Played then
3941 begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
3942 FAnim[FCurAnim, FDirection].Revert(False);
3943 SetState(MONSTATE_GO);
3944 end;
3946 // Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
3947 if vilefire <> nil then
3948 vilefire.Update();
3950 // Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
3951 if (FState = MONSTATE_DIE) and
3952 (FAnim[FCurAnim, FDirection] <> nil) and
3953 (FAnim[FCurAnim, FDirection].Played) then
3954 begin
3955 // Óìåð:
3956 SetState(MONSTATE_DEAD);
3958 // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
3959 if (FMonsterType = MONSTER_PAIN) or
3960 (FMonsterType = MONSTER_SOUL) or
3961 (FMonsterType = MONSTER_BARREL) then
3962 FRemoved := True
3963 else
3964 FAnim[FCurAnim, FDirection].CurrentFrame := FAnim[FCurAnim, FDirection].TotalFrames - 1;
3965 end;
3967 // Ñîâåðøåíèå àòàêè è ñòðåëüáû:
3968 if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
3969 if (FAnim[FCurAnim, FDirection] <> nil) then
3970 // Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
3971 if (FAnim[FCurAnim, FDirection].Played) then
3972 begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
3973 if FState = MONSTATE_ATTACK then
3974 begin // Ñîñòîÿíèå - Àòàêà
3975 // Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
3976 if FMonsterType <> MONSTER_SOUL then
3977 SetState(MONSTATE_GO);
3978 end
3979 else // Ñîñòîÿíèå - Ñòðåëüáà
3980 begin
3981 // Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
3982 if not FChainFire then
3983 SetState(MONSTATE_GO)
3984 else
3985 begin // Íàäî ñòðåëÿòü åùå
3986 FChainFire := False;
3987 // Ò.ê. ñîñòîÿíèå íå èçìåíèëîñü, è íóæåí
3988 // íîâûé öèêë îæèäàíèÿ çàâåðøåíèÿ àíèìàöèè:
3989 FAnim[FCurAnim, FDirection].Reset();
3990 end;
3991 end;
3993 FWaitAttackAnim := False;
3994 end
3996 else // Àíèìàöèÿ àòàêè åùå èäåò (èñêëþ÷åíèå - Lost_Soul):
3997 if (FMonsterType = MONSTER_SOUL) or
3998 ( (not FWaitAttackAnim) and
3999 (FAnim[FCurAnim, FDirection].CurrentFrame =
4000 (FAnim[FCurAnim, FDirection].TotalFrames div 2))
4001 ) then
4002 begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
4003 if FState = MONSTATE_ATTACK then
4004 begin // Ñîñòîÿíèå - Àòàêà
4005 // Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
4006 if FMonsterType = MONSTER_SOUL then
4007 FAnim[FCurAnim, FDirection].Reset();
4009 case FMonsterType of
4010 MONSTER_SOUL, MONSTER_IMP, MONSTER_DEMON:
4011 // Ãðûçåì ïåðâîãî ïîïàâøåãîñÿ:
4012 if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
4013 // Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
4014 if FMonsterType = MONSTER_SOUL then
4015 SetState(MONSTATE_GO);
4017 MONSTER_FISH:
4018 g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME);
4020 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
4021 // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
4022 if FCurAnim = ANIM_ATTACK2 then
4023 begin
4024 o := FObj;
4025 o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
4026 g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME);
4027 end;
4029 MONSTER_VILE:
4030 // Êîëäóí ïûòàåòñÿ âîñêðåøàòü:
4031 if FCurAnim = ANIM_ATTACK2 then
4032 begin
4033 sx := isCorpse(@FObj, True);
4034 if sx <> -1 then
4035 begin // Íàøëè, êîãî âîñêðåñèòü
4036 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
4037 // Âîñêðåøàòü - ñåáå âðåäèòü:
4038 {g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
4039 end;
4040 end;
4041 end;
4042 end
4044 else // Ñîñòîÿíèå - Ñòðåëüáà
4045 begin
4046 // Ñêîðîñòðåëüíûå ìîíñòðû:
4047 if (FMonsterType = MONSTER_CGUN) or
4048 (FMonsterType = MONSTER_SPIDER) or
4049 (FMonsterType = MONSTER_BSP) or
4050 (FMonsterType = MONSTER_MANCUB) or
4051 (FMonsterType = MONSTER_ROBO) then
4052 if not GetPos(FTargetUID, @o) then
4053 // Öåëü ìåðòâà - èùåì íîâóþ:
4054 findNewPrey()
4055 else // Öåëü æèâà - ïðîäîëæàåì ñòðåëÿòü:
4056 if shoot(@o, False) then
4057 FChainFire := True;
4058 end;
4060 // Àòàêà òîëüêî 1 ðàç çà àíèìàöèþ àòàêè:
4061 FWaitAttackAnim := True;
4062 end;
4064 // Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
4065 if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
4066 case FState of
4067 MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
4068 // Çâóêè ïðè ïåðåäâèæåíèè:
4069 case FMonsterType of
4070 MONSTER_CYBER:
4071 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4072 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4073 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_WALK', FObj.X, FObj.Y);
4074 MONSTER_SPIDER:
4075 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4076 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4077 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_WALK', FObj.X, FObj.Y);
4078 MONSTER_BSP:
4079 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4080 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
4081 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
4082 MONSTER_ROBO:
4083 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
4084 (FAnim[FCurAnim, FDirection].CurrentFrame = 5) then
4085 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
4086 end;
4087 end;
4089 // Êîñòûëü äëÿ ïîòîêîâ
4090 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
4091 not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
4092 FObj.Vel.X := oldvelx;
4094 // Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
4095 if FAnim[FCurAnim, FDirection] <> nil then
4096 FAnim[FCurAnim, FDirection].Update();
4097 end;
4099 procedure TMonster.ClientAttack(wx, wy, atx, aty: Integer);
4100 begin
4101 case FMonsterType of
4102 MONSTER_ZOMBY:
4103 begin
4104 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
4105 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
4106 end;
4107 MONSTER_SERG:
4108 begin
4109 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
4110 FShellTimer := 10;
4111 FShellType := SHELL_SHELL;
4112 end;
4113 MONSTER_MAN:
4114 begin
4115 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', wx, wy);
4116 FShellTimer := 13;
4117 FShellType := SHELL_DBLSHELL;
4118 end;
4119 MONSTER_CGUN, MONSTER_SPIDER:
4120 begin
4121 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
4122 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
4123 end;
4124 MONSTER_IMP:
4125 g_Weapon_ball1(wx, wy, atx, aty, FUID);
4126 MONSTER_CYBER:
4127 g_Weapon_rocket(wx, wy, atx, aty, FUID);
4128 MONSTER_SKEL:
4129 g_Weapon_revf(wx, wy, atx, aty, FUID, FTargetUID);
4130 MONSTER_BSP:
4131 g_Weapon_aplasma(wx, wy, atx, aty, FUID);
4132 MONSTER_ROBO:
4133 g_Weapon_plasma(wx, wy, atx, aty, FUID);
4134 MONSTER_MANCUB:
4135 g_Weapon_manfire(wx, wy, atx, aty, FUID);
4136 MONSTER_BARON, MONSTER_KNIGHT:
4137 g_Weapon_ball7(wx, wy, atx, aty, FUID);
4138 MONSTER_CACO:
4139 g_Weapon_ball2(wx, wy, atx, aty, FUID);
4140 end;
4141 end;
4143 procedure TMonster.Turn();
4144 begin
4145 // Ðàçâîðà÷èâàåìñÿ:
4146 if FDirection = TDirection.D_LEFT then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
4148 // Áåæèì â âûáðàííóþ ñòîðîíó:
4149 if FDirection = TDirection.D_RIGHT then
4150 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
4151 else
4152 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
4153 end;
4155 function TMonster.findNewPrey(): Boolean;
4156 var
4157 a: DWORD;
4158 l, l2: Integer;
4159 PlayersSee, MonstersSee: Array of DWORD;
4160 PlayerNear, MonsterNear: Integer;
4161 begin
4162 Result := False;
4163 SetLength(MonstersSee, 0);
4164 SetLength(PlayersSee, 0);
4166 FTargetUID := 0;
4167 l := 32000;
4168 PlayerNear := -1;
4169 MonsterNear := -1;
4171 // Ïîåõàâøèå, êàííèáàëû, è äîáðûå èãðîêîâ íå òðîãàþò
4172 if (gPlayers <> nil) and (FBehaviour <> BH_INSANE) and
4173 (FBehaviour <> BH_CANNIBAL) and (FBehaviour <> BH_GOOD) then
4174 for a := 0 to High(gPlayers) do
4175 if (gPlayers[a] <> nil) and (gPlayers[a].alive)
4176 and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
4177 begin
4178 if g_Look(@FObj, @gPlayers[a].Obj, FDirection) then
4179 begin
4180 SetLength(PlayersSee, Length(PlayersSee) + 1);
4181 PlayersSee[High(PlayersSee)] := a;
4182 end;
4183 l2 := Abs(gPlayers[a].GameX-FObj.X)+
4184 Abs(gPlayers[a].GameY-FObj.Y);
4185 if l2 < l then
4186 begin
4187 l := l2;
4188 PlayerNear := Integer(a);
4189 end;
4190 end;
4192 // Êèëëåðû è äîáðûå íå òðîãàþò ìîíñòðîâ
4193 if (gMonsters <> nil) and (FBehaviour <> BH_KILLER) and (FBehaviour <> BH_GOOD) then
4194 for a := 0 to High(gMonsters) do
4195 if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
4196 (gMonsters[a].FUID <> FUID) then
4197 begin
4198 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
4199 Continue; // Êàííèáàëû àòàêóþò òîëüêî ñîðîäè÷åé
4200 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL)
4201 and (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
4202 Continue; // Ïîåõàâøèå íå òðîãàþò äðóçåé, íî èì íå íðàâÿòñÿ áî÷êè
4203 if ((FBehaviour = BH_NORMAL) or (FBehaviour = BH_MANIAC))
4204 and (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
4205 Continue; // Îñòàâøèåñÿ òèïû, êðîìå êàííèáàëîâ, íå òðîãàþò ñâîèõ äðóçåé
4207 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
4208 begin
4209 SetLength(MonstersSee, Length(MonstersSee) + 1);
4210 MonstersSee[High(MonstersSee)] := a;
4211 end;
4212 l2 := Abs(gMonsters[a].FObj.X-FObj.X)+
4213 Abs(gMonsters[a].FObj.Y-FObj.Y);
4214 if l2 < l then
4215 begin
4216 l := l2;
4217 MonsterNear := Integer(a);
4218 end;
4219 end;
4221 case FBehaviour of
4222 BH_NORMAL, BH_KILLER:
4223 begin
4224 // Îáû÷íûé è êèëëåð ñíà÷àëà èùóò èãðîêîâ â ïîëå çðåíèÿ
4225 if (FTargetUID = 0) and (Length(PlayersSee) > 0) then
4226 begin
4227 a := PlayersSee[Random(Length(PlayersSee))];
4228 FTargetUID := gPlayers[a].UID;
4229 end;
4230 // Çàòåì ïîáëèçîñòè
4231 if (FTargetUID = 0) and (PlayerNear > -1) then
4232 begin
4233 a := PlayerNear;
4234 FTargetUID := gPlayers[a].UID;
4235 end;
4236 // Ïîòîì îáû÷íûå èùóò ìîíñòðîâ â ïîëå çðåíèÿ
4237 if (FTargetUID = 0) and (Length(MonstersSee) > 0) then
4238 begin
4239 a := MonstersSee[Random(Length(MonstersSee))];
4240 FTargetUID := gMonsters[a].UID;
4241 end;
4242 // Çàòåì ïîáëèçîñòè
4243 if (FTargetUID = 0) and (MonsterNear > -1) then
4244 begin
4245 a := MonsterNear;
4246 FTargetUID := gMonsters[a].UID;
4247 end;
4248 end;
4249 BH_MANIAC, BH_INSANE, BH_CANNIBAL:
4250 begin
4251 // Ìàíüÿêè, ïîåõàâøèå è êàííèáàëû ñíà÷àëà èñòðåáëÿþò âñ¸ â ïîëå çðåíèÿ
4252 if (FTargetUID = 0) and (Length(PlayersSee) > 0) then
4253 begin
4254 a := PlayersSee[Random(Length(PlayersSee))];
4255 FTargetUID := gPlayers[a].UID;
4256 end;
4257 if (FTargetUID = 0) and (Length(MonstersSee) > 0) then
4258 begin
4259 a := MonstersSee[Random(Length(MonstersSee))];
4260 FTargetUID := gMonsters[a].UID;
4261 end;
4262 // Çàòåì èùóò êîãî-òî ïîáëèçîñòè
4263 if (FTargetUID = 0) and (PlayerNear > -1) then
4264 begin
4265 a := PlayerNear;
4266 FTargetUID := gPlayers[a].UID;
4267 end;
4268 if (FTargetUID = 0) and (MonsterNear > -1) then
4269 begin
4270 a := MonsterNear;
4271 FTargetUID := gMonsters[a].UID;
4272 end;
4273 end;
4274 end;
4276 // Åñëè è ìîíñòðîâ íåò - íà÷èíàåì æäàòü öåëü:
4277 if FTargetUID = 0 then
4278 begin
4279 // Ïîåõàâøèé ïûòàåòñÿ ñàìîóáèòüñÿ
4280 if FBehaviour = BH_INSANE then
4281 FTargetUID := FUID
4282 else
4283 FTargetTime := MAX_ATM;
4284 end
4285 else
4286 begin // Öåëü íàøëè
4287 FTargetTime := 0;
4288 Result := True;
4289 end;
4290 end;
4292 function TMonster.kick(o: PObj): Boolean;
4293 begin
4294 Result := False;
4296 case FMonsterType of
4297 MONSTER_FISH:
4298 begin
4299 SetState(MONSTATE_ATTACK);
4300 Result := True;
4301 end;
4302 MONSTER_DEMON:
4303 begin
4304 SetState(MONSTATE_ATTACK);
4305 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ATTACK', FObj.X, FObj.Y);
4306 Result := True;
4307 end;
4308 MONSTER_IMP:
4309 begin
4310 SetState(MONSTATE_ATTACK);
4311 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ATTACK', FObj.X, FObj.Y);
4312 Result := True;
4313 end;
4314 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
4315 begin
4316 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
4317 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ATTACK', FObj.X, FObj.Y);
4318 Result := True;
4319 end;
4320 MONSTER_BARON, MONSTER_KNIGHT,
4321 MONSTER_CACO, MONSTER_MANCUB:
4322 // Ýòè ìîíñòðû íå ïèíàþò - îíè ñòðåëÿþò â óïîð:
4323 if not g_Game_IsClient then Result := shoot(o, True);
4324 end;
4325 end;
4327 function TMonster.shoot(o: PObj; immediately: Boolean): Boolean;
4328 var
4329 xd, yd, m: Integer;
4330 begin
4331 Result := False;
4333 // Ñòðåëÿòü ðàíî:
4334 if FAmmo < 0 then
4335 Exit;
4337 // Æäàòü âðåìåíè ãîòîâíîñòè ê âûñòðåëó:
4338 if not immediately then
4339 case FMonsterType of
4340 MONSTER_FISH, MONSTER_BARREL, MONSTER_DEMON:
4341 Exit; // íå ñòðåëÿþò
4342 MONSTER_CGUN, MONSTER_BSP, MONSTER_ROBO:
4343 begin
4344 FAmmo := FAmmo + 1;
4345 // Âðåìÿ âûñòðåëà óïóùåíî:
4346 if FAmmo >= 50 then
4347 FAmmo := IfThen(FMonsterType = MONSTER_ROBO, -200, -50);
4348 end;
4349 MONSTER_MAN: ;
4350 MONSTER_MANCUB:
4351 begin
4352 FAmmo := FAmmo + 1;
4353 // Âðåìÿ âûñòðåëà óïóùåíî:
4354 if FAmmo >= 5 then
4355 FAmmo := -50;
4356 end;
4357 MONSTER_SPIDER:
4358 begin
4359 FAmmo := FAmmo + 1;
4360 // Âðåìÿ âûñòðåëà óïóùåíî:
4361 if FAmmo >= 100 then
4362 FAmmo := -50;
4363 end;
4364 MONSTER_CYBER:
4365 begin
4366 // Ñòðåëÿåò íå âñåãäà:
4367 if Random(2) = 0 then
4368 Exit;
4369 FAmmo := FAmmo + 1;
4370 // Âðåìÿ âûñòðåëà óïóùåíî:
4371 if FAmmo >= 10 then
4372 FAmmo := -50;
4373 end;
4374 MONSTER_BARON, MONSTER_KNIGHT: if Random(8) <> 0 then Exit;
4375 MONSTER_SKEL: if Random(32) <> 0 then Exit;
4376 MONSTER_VILE: if Random(8) <> 0 then Exit;
4377 MONSTER_PAIN: if Random(8) <> 0 then Exit;
4378 else if Random(16) <> 0 then Exit;
4379 end;
4381 // Öåëè íå âèäíî:
4382 if not g_Look(@FObj, o, FDirection) then
4383 Exit;
4385 FTargetTime := 0;
4387 tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2)+((o^.Vel.X{+o^.Accel.X})*12);
4388 ty := o^.Y+o^.Rect.Y+(o^.Rect.Height div 2)+((o^.Vel.Y{+o^.Accel.Y})*12);
4390 // Ðàçíèöà ïî âûñîòå áîëüøå ðàçíèöû ïî ãîðèçîíòàëè
4391 // (íå ìîæåò ñòðåëÿòü ïîä òàêèì áîëüøèì óãëîì):
4392 if Abs(tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2))) <
4393 Abs(ty-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2))) then
4394 Exit;
4396 case FMonsterType of
4397 MONSTER_IMP, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO:
4398 begin
4399 SetState(MONSTATE_SHOOT);
4400 {nn}
4401 end;
4402 MONSTER_SKEL:
4403 begin
4404 SetState(MONSTATE_SHOOT);
4405 {nn}
4406 end;
4407 MONSTER_VILE:
4408 begin // Çàæèãàåì îãîíü
4409 tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2);
4410 ty := o^.Y+o^.Rect.Y;
4411 SetState(MONSTATE_SHOOT);
4413 vilefire.Reset();
4415 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ATTACK', FObj.X, FObj.Y);
4416 g_Sound_PlayExAt('SOUND_FIRE', o^.X, o^.Y);
4417 end;
4418 MONSTER_SOUL:
4419 begin // Ëåòèò â ñòîðîíó öåëè:
4420 SetState(MONSTATE_ATTACK);
4421 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_ATTACK', FObj.X, FObj.Y);
4423 xd := tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
4424 yd := ty-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
4425 m := Max(Abs(xd), Abs(yd));
4426 if m = 0 then
4427 m := 1;
4429 FObj.Vel.X := (xd*16) div m;
4430 FObj.Vel.Y := (yd*16) div m;
4431 end;
4432 MONSTER_MANCUB, MONSTER_ZOMBY, MONSTER_SERG, MONSTER_BSP, MONSTER_ROBO,
4433 MONSTER_CYBER, MONSTER_CGUN, MONSTER_SPIDER, MONSTER_PAIN, MONSTER_MAN:
4434 begin
4435 // Ìàíêóáóñ ðÿâêàåò ïåðåä ïåðâîé àòàêîé:
4436 if FMonsterType = MONSTER_MANCUB then
4437 if FAmmo = 1 then
4438 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ATTACK', FObj.X, FObj.Y);
4440 SetState(MONSTATE_SHOOT);
4441 end;
4442 else Exit;
4443 end;
4445 Result := True;
4446 end;
4448 function TMonster.alive(): Boolean;
4449 begin
4450 Result := (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) and (FHealth > 0);
4451 end;
4453 procedure TMonster.SetHealth(aH: Integer);
4454 begin
4455 if (aH > 0) and (aH < 1000000) then
4456 begin
4457 FHealth := aH;
4458 if FHealth > FMaxHealth then
4459 FMaxHealth := FHealth;
4460 end;
4461 end;
4463 procedure TMonster.WakeUp();
4464 begin
4465 if g_Game_IsClient then Exit;
4466 SetState(MONSTATE_GO);
4467 FTargetTime := MAX_ATM;
4468 WakeUpSound();
4469 end;
4471 procedure TMonster.SaveState (st: TStream);
4472 var
4473 i: Integer;
4474 b: Byte;
4475 anim: Boolean;
4476 begin
4477 assert(st <> nil);
4479 // Ñèãíàòóðà ìîíñòðà:
4480 utils.writeSign(st, 'MONS');
4481 utils.writeInt(st, Byte(0)); // version
4482 // UID ìîíñòðà:
4483 utils.writeInt(st, Word(FUID));
4484 // Íàïðàâëåíèå
4485 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
4486 utils.writeInt(st, Byte(b));
4487 // Íàäî ëè óäàëèòü åãî
4488 utils.writeBool(st, FRemoved);
4489 // Îñòàëîñü çäîðîâüÿ
4490 utils.writeInt(st, LongInt(FHealth));
4491 // Ñîñòîÿíèå
4492 utils.writeInt(st, Byte(FState));
4493 // Òåêóùàÿ àíèìàöèÿ
4494 utils.writeInt(st, Byte(FCurAnim));
4495 // UID öåëè
4496 utils.writeInt(st, Word(FTargetUID));
4497 // Âðåìÿ ïîñëå ïîòåðè öåëè
4498 utils.writeInt(st, LongInt(FTargetTime));
4499 // Ïîâåäåíèå ìîíñòðà
4500 utils.writeInt(st, Byte(FBehaviour));
4501 // Ãîòîâíîñòü ê âûñòðåëó
4502 utils.writeInt(st, LongInt(FAmmo));
4503 // Áîëü
4504 utils.writeInt(st, LongInt(FPain));
4505 // Âðåìÿ îæèäàíèÿ
4506 utils.writeInt(st, LongInt(FSleep));
4507 // Îçâó÷èâàòü ëè áîëü
4508 utils.writeBool(st, FPainSound);
4509 // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè
4510 utils.writeBool(st, FWaitAttackAnim);
4511 // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå
4512 utils.writeBool(st, FChainFire);
4513 // Ïîäëåæèò ëè ðåñïàâíó
4514 utils.writeBool(st, FNoRespawn);
4515 // Êîîðäèíàòû öåëè
4516 utils.writeInt(st, LongInt(tx));
4517 utils.writeInt(st, LongInt(ty));
4518 // ID ìîíñòðà ïðè ñòàðòå êàðòû
4519 utils.writeInt(st, LongInt(FStartID));
4520 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà
4521 utils.writeInt(st, LongInt(FSpawnTrigger));
4522 // Îáúåêò ìîíñòðà
4523 Obj_SaveState(st, @FObj);
4524 // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà
4525 anim := (vilefire <> nil);
4526 utils.writeBool(st, anim);
4527 // Åñëè åñòü - ñîõðàíÿåì:
4528 if anim then vilefire.SaveState(st);
4529 // Àíèìàöèè
4530 for i := ANIM_SLEEP to ANIM_PAIN do
4531 begin
4532 // Åñòü ëè ëåâàÿ àíèìàöèÿ
4533 anim := (FAnim[i, TDirection.D_LEFT] <> nil);
4534 utils.writeBool(st, anim);
4535 // Åñëè åñòü - ñîõðàíÿåì
4536 if anim then FAnim[i, TDirection.D_LEFT].SaveState(st);
4537 // Åñòü ëè ïðàâàÿ àíèìàöèÿ
4538 anim := (FAnim[i, TDirection.D_RIGHT] <> nil);
4539 utils.writeBool(st, anim);
4540 // Åñëè åñòü - ñîõðàíÿåì
4541 if anim then FAnim[i, TDirection.D_RIGHT].SaveState(st);
4542 end;
4543 end;
4546 procedure TMonster.LoadState (st: TStream);
4547 var
4548 i: Integer;
4549 b: Byte;
4550 anim: Boolean;
4551 begin
4552 assert(st <> nil);
4554 // Ñèãíàòóðà ìîíñòðà:
4555 if not utils.checkSign(st, 'MONS') then raise XStreamError.Create('invalid monster signature');
4556 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid monster version');
4557 if (uidMap[FUID] <> nil) and (uidMap[FUID] <> self) then raise Exception.Create('internal error in monster loader (0)');
4558 uidMap[FUID] := nil;
4559 // UID ìîíñòðà:
4560 FUID := utils.readWord(st);
4561 //if (arrIdx = -1) then raise Exception.Create('internal error in monster loader');
4562 if (uidMap[FUID] <> nil) then raise Exception.Create('internal error in monster loader (1)');
4563 uidMap[FUID] := self;
4564 // Íàïðàâëåíèå
4565 b := utils.readByte(st);
4566 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
4567 // Íàäî ëè óäàëèòü åãî
4568 FRemoved := utils.readBool(st);
4569 // Îñòàëîñü çäîðîâüÿ
4570 FHealth := utils.readLongInt(st);
4571 // Ñîñòîÿíèå
4572 FState := utils.readByte(st);
4573 // Òåêóùàÿ àíèìàöèÿ
4574 FCurAnim := utils.readByte(st);
4575 // UID öåëè
4576 FTargetUID := utils.readWord(st);
4577 // Âðåìÿ ïîñëå ïîòåðè öåëè
4578 FTargetTime := utils.readLongInt(st);
4579 // Ïîâåäåíèå ìîíñòðà
4580 FBehaviour := utils.readByte(st);
4581 // Ãîòîâíîñòü ê âûñòðåëó
4582 FAmmo := utils.readLongInt(st);
4583 // Áîëü
4584 FPain := utils.readLongInt(st);
4585 // Âðåìÿ îæèäàíèÿ
4586 FSleep := utils.readLongInt(st);
4587 // Îçâó÷èâàòü ëè áîëü
4588 FPainSound := utils.readBool(st);
4589 // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè
4590 FWaitAttackAnim := utils.readBool(st);
4591 // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå
4592 FChainFire := utils.readBool(st);
4593 // Ïîäëåæèò ëè ðåñïàâíó
4594 FNoRespawn := utils.readBool(st);
4595 // Êîîðäèíàòû öåëè
4596 tx := utils.readLongInt(st);
4597 ty := utils.readLongInt(st);
4598 // ID ìîíñòðà ïðè ñòàðòå êàðòû
4599 FStartID := utils.readLongInt(st);
4600 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà
4601 FSpawnTrigger := utils.readLongInt(st);
4602 // Îáúåêò ìîíñòðà
4603 Obj_LoadState(@FObj, st);
4604 // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà
4605 anim := utils.readBool(st);
4606 // Åñëè åñòü - çàãðóæàåì:
4607 if anim then
4608 begin
4609 Assert(vilefire <> nil, 'TMonster.LoadState: no vilefire anim');
4610 vilefire.LoadState(st);
4611 end;
4612 // Àíèìàöèè
4613 for i := ANIM_SLEEP to ANIM_PAIN do
4614 begin
4615 // Åñòü ëè ëåâàÿ àíèìàöèÿ
4616 anim := utils.readBool(st);
4617 // Åñëè åñòü - çàãðóæàåì
4618 if anim then
4619 begin
4620 Assert(FAnim[i, TDirection.D_LEFT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_left anim');
4621 FAnim[i, TDirection.D_LEFT].LoadState(st);
4622 end;
4623 // Åñòü ëè ïðàâàÿ àíèìàöèÿ
4624 anim := utils.readBool(st);
4625 // Åñëè åñòü - çàãðóæàåì
4626 if anim then
4627 begin
4628 Assert(FAnim[i, TDirection.D_RIGHT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_right anim');
4629 FAnim[i, TDirection.D_RIGHT].LoadState(st);
4630 end;
4631 end;
4632 end;
4635 procedure TMonster.ActivateTriggers();
4636 var
4637 a: Integer;
4638 begin
4639 if FDieTriggers <> nil then
4640 for a := 0 to High(FDieTriggers) do
4641 g_Triggers_Press(FDieTriggers[a], ACTIVATE_MONSTERPRESS);
4642 if FSpawnTrigger > -1 then
4643 begin
4644 g_Triggers_DecreaseSpawner(FSpawnTrigger);
4645 FSpawnTrigger := -1;
4646 end;
4647 end;
4649 procedure TMonster.AddTrigger(t: Integer);
4650 begin
4651 SetLength(FDieTriggers, Length(FDieTriggers)+1);
4652 FDieTriggers[High(FDieTriggers)] := t;
4653 end;
4655 procedure TMonster.ClearTriggers();
4656 begin
4657 SetLength(FDieTriggers, 0);
4658 end;
4660 procedure TMonster.CatchFire(Attacker: Word; Timeout: Integer = MON_BURN_TIME);
4661 begin
4662 if FMonsterType in [MONSTER_SOUL, MONSTER_VILE] then
4663 exit; // àð÷è íå ãîðÿò, ÷åðåïà óæå ãîðÿò
4664 if Timeout <= 0 then exit;
4665 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
4666 exit; // íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
4667 if FFireTime <= 0 then
4668 g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
4669 FFireTime := Timeout;
4670 FFireAttacker := Attacker;
4671 if g_Game_IsNet and g_Game_IsServer then MH_SEND_MonsterState(FUID);
4672 end;
4674 procedure TMonster.OnFireFlame(Times: DWORD = 1);
4675 var
4676 id, i: DWORD;
4677 Anim: TAnimation;
4678 begin
4679 if (Random(10) = 1) and (Times = 1) then
4680 Exit;
4682 if g_Frames_Get(id, 'FRAMES_FLAME') then
4683 begin
4684 for i := 1 to Times do
4685 begin
4686 Anim := TAnimation.Create(id, False, 3);
4687 Anim.Alpha := 0;
4688 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
4689 Obj.Y+8+Random(8+Times*2)+IfThen(FState = MONSTATE_DEAD, 16, 0), Anim, ONCEANIM_SMOKE);
4690 Anim.Free();
4691 end;
4692 end;
4693 end;
4696 // ////////////////////////////////////////////////////////////////////////// //
4697 // throws on invalid uid
4698 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
4699 begin
4700 result := g_Mons_ByIdx_NC(uid);
4701 if (result = nil) then raise Exception.Create('g_Mons_ByIdx: invalid monster id');
4702 end;
4704 // can return null
4705 function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
4706 begin
4707 if (uid < 0) or (uid > High(gMonsters)) then begin result := nil; exit; end;
4708 result := gMonsters[uid];
4709 end;
4711 function g_Mons_TotalCount (): Integer; inline;
4712 begin
4713 result := Length(gMonsters);
4714 end;
4717 function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
4718 var
4719 idx: Integer;
4720 mon: TMonster;
4721 begin
4722 result := false;
4723 if (gMonsters = nil) or not assigned(cb) then exit;
4724 for idx := 0 to High(gMonsters) do
4725 begin
4726 mon := gMonsters[idx];
4727 if (mon <> nil) then
4728 begin
4729 result := cb(mon);
4730 if result then exit;
4731 end;
4732 end;
4733 end;
4736 function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
4737 var
4738 idx: Integer;
4739 mon: TMonster;
4740 begin
4741 result := false;
4742 if (gMonsters = nil) or not assigned(cb) then exit;
4743 for idx := 0 to High(gMonsters) do
4744 begin
4745 mon := gMonsters[idx];
4746 if (mon <> nil) and mon.alive then
4747 begin
4748 result := cb(mon);
4749 if result then exit;
4750 end;
4751 end;
4752 end;
4755 function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
4756 (*
4757 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4758 begin
4759 result := mon.alive;// and g_Obj_Collide(x, y, width, height, @mon.Obj));
4760 end;
4761 *)
4762 var
4763 idx: Integer;
4764 mon: TMonster;
4765 mit: PMonster;
4766 it: TMonsterGrid.Iter;
4767 begin
4768 result := false;
4769 if (width < 1) or (height < 1) then exit;
4770 if gmon_debug_use_sqaccel then
4771 begin
4772 //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4773 it := monsGrid.forEachInAABB(x, y, width, height);
4774 for mit in it do if (mit.alive) then begin result := true; break; end;
4775 it.release();
4776 end
4777 else
4778 begin
4779 for idx := 0 to High(gMonsters) do
4780 begin
4781 mon := gMonsters[idx];
4782 if (mon <> nil) and mon.alive then
4783 begin
4784 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4785 begin
4786 result := true;
4787 exit;
4788 end;
4789 end;
4790 end;
4791 end;
4792 end;
4795 function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
4796 (*
4797 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4798 begin
4799 result := cb(mon);
4800 end;
4801 *)
4802 var
4803 idx: Integer;
4804 mon: TMonster;
4805 mit: PMonster;
4806 it: TMonsterGrid.Iter;
4807 begin
4808 result := false;
4809 if (width < 1) or (height < 1) then exit;
4810 if gmon_debug_use_sqaccel then
4811 begin
4812 //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4813 it := monsGrid.forEachInAABB(x, y, width, height);
4814 for mit in it do if (cb(mit^)) then begin result := true; break; end;
4815 it.release();
4816 end
4817 else
4818 begin
4819 for idx := 0 to High(gMonsters) do
4820 begin
4821 mon := gMonsters[idx];
4822 if (mon <> nil) and mon.alive then
4823 begin
4824 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4825 begin
4826 result := cb(mon);
4827 if result then exit;
4828 end;
4829 end;
4830 end;
4831 end;
4832 end;
4835 function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
4836 (*
4837 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4838 begin
4839 //result := false;
4840 //if mon.alive and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
4841 if mon.alive then result := cb(mon) else result := false;
4842 end;
4843 *)
4844 var
4845 idx: Integer;
4846 mon: TMonster;
4847 mit: PMonster;
4848 it: TMonsterGrid.Iter;
4849 begin
4850 result := false;
4851 if (width < 1) or (height < 1) then exit;
4852 if gmon_debug_use_sqaccel then
4853 begin
4855 if (width = 1) and (height = 1) then
4856 begin
4857 result := (monsGrid.forEachAtPoint(x, y, monsCollCheck) <> nil);
4858 end
4859 else
4860 begin
4861 result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4862 end;
4864 it := monsGrid.forEachInAABB(x, y, width, height);
4865 for mit in it do
4866 begin
4867 if (mit^.alive) then
4868 begin
4869 if (cb(mit^)) then begin result := true; break; end;
4870 end;
4871 end;
4872 it.release();
4873 end
4874 else
4875 begin
4876 for idx := 0 to High(gMonsters) do
4877 begin
4878 mon := gMonsters[idx];
4879 if (mon <> nil) and mon.alive then
4880 begin
4881 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4882 begin
4883 result := cb(mon);
4884 if result then exit;
4885 end;
4886 end;
4887 end;
4888 end;
4889 end;
4892 end.