DEADSOFTWARE

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