DEADSOFTWARE

typo in mapcvt: microseconds -> milliseconds
[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 {.$DEFINE D2F_DEBUG_MONS_MOVE}
18 unit g_monsters;
20 interface
22 uses
23 g_basic, e_graphics, g_phys, g_textures, g_grid,
24 g_saveload, BinEditor, g_panel, xprofiler;
26 const
27 MONSTATE_SLEEP = 0;
28 MONSTATE_GO = 1;
29 MONSTATE_RUN = 2;
30 MONSTATE_CLIMB = 3;
31 MONSTATE_DIE = 4;
32 MONSTATE_DEAD = 5;
33 MONSTATE_ATTACK = 6;
34 MONSTATE_SHOOT = 7;
35 MONSTATE_PAIN = 8;
36 MONSTATE_WAIT = 9;
37 MONSTATE_REVIVE = 10;
38 MONSTATE_RUNOUT = 11;
40 BH_NORMAL = 0;
41 BH_KILLER = 1;
42 BH_MANIAC = 2;
43 BH_INSANE = 3;
44 BH_CANNIBAL = 4;
45 BH_GOOD = 5;
47 type
48 TMonster = Class (TObject)
49 private
50 FMonsterType: Byte;
51 FUID: Word;
52 FDirection: TDirection;
53 FStartDirection: TDirection;
54 FStartX, FStartY: Integer;
55 FRemoved: Boolean;
56 FHealth: Integer;
57 FMaxHealth: Integer;
58 FState: Byte;
59 FCurAnim: Byte;
60 FAnim: Array of Array [D_LEFT..D_RIGHT] of TAnimation;
61 FTargetUID: Word;
62 FTargetTime: Integer;
63 FBehaviour: Byte;
64 FAmmo: Integer;
65 FPain: Integer;
66 FSleep: Integer;
67 FPainSound: Boolean;
68 FPainTicks: Integer;
69 FWaitAttackAnim: Boolean;
70 FChainFire: Boolean;
71 tx, ty: Integer;
72 FStartID: Integer;
73 FObj: TObj;
74 FBloodRed: Byte;
75 FBloodGreen: Byte;
76 FBloodBlue: Byte;
77 FBloodKind: Byte;
78 FShellTimer: Integer;
79 FShellType: Byte;
80 FFirePainTime: Integer;
81 FFireAttacker: Word;
82 vilefire: TAnimation;
83 mProxyId: Integer; // node in dyntree or -1
84 mArrIdx: Integer; // in gMonsters
86 FDieTriggers: Array of Integer;
87 FSpawnTrigger: Integer;
89 procedure Turn();
90 function findNewPrey(): Boolean;
91 procedure ActivateTriggers();
93 public
94 FNoRespawn: Boolean;
95 FFireTime: Integer;
96 trapCheckFrameId: DWord; // for `g_weapons.CheckTrap()`
98 constructor Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
99 destructor Destroy(); override;
100 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
101 function Collide(Panel: TPanel): Boolean; overload;
102 function Collide(X, Y: Integer): Boolean; overload;
103 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
104 function Live(): Boolean;
105 procedure SetHealth(aH: Integer);
106 procedure Push(vx, vy: Integer);
107 function Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
108 function Heal(Value: Word): Boolean;
109 procedure BFGHit();
110 procedure Update();
111 procedure ClientUpdate();
112 procedure ClientAttack(wx, wy, atx, aty: Integer);
113 procedure SetDeadAnim;
114 procedure Draw();
115 procedure WakeUp();
116 procedure WakeUpSound();
117 procedure DieSound();
118 procedure PainSound();
119 procedure ActionSound();
120 procedure AddTrigger(t: Integer);
121 procedure ClearTriggers();
122 procedure Respawn();
123 procedure SaveState(var Mem: TBinMemoryWriter);
124 procedure LoadState(var Mem: TBinMemoryReader);
125 procedure SetState(State: Byte; ForceAnim: Byte = 255);
126 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
127 procedure MakeBloodSimple(Count: Word);
128 procedure RevertAnim(R: Boolean = True);
129 function AnimIsReverse: Boolean;
130 function shoot(o: PObj; immediately: Boolean): Boolean;
131 function kick(o: PObj): Boolean;
132 procedure CatchFire(Attacker: Word);
133 procedure OnFireFlame(Times: DWORD = 1);
135 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
137 procedure getMapBox (out x, y, w, h: Integer); inline;
139 property MonsterType: Byte read FMonsterType;
140 property MonsterHealth: Integer read FHealth write FHealth;
141 property MonsterAmmo: Integer read FAmmo write FAmmo;
142 property MonsterTargetUID: Word read FTargetUID write FTargetUID;
143 property MonsterTargetTime: Integer read FTargetTime write FTargetTime;
144 property MonsterBehaviour: Byte read FBehaviour write FBehaviour;
145 property MonsterSleep: Integer read FSleep write FSleep;
146 property MonsterState: Byte read FState write FState;
147 property MonsterRemoved: Boolean read FRemoved write FRemoved;
148 property MonsterPain: Integer read FPain write FPain;
149 property MonsterAnim: Byte read FCurAnim write FCurAnim;
151 property Obj: TObj read FObj;
152 property UID: Word read FUID write FUID;
153 property SpawnTrigger: Integer read FSpawnTrigger write FSpawnTrigger;
155 property GameX: Integer read FObj.X write FObj.X;
156 property GameY: Integer read FObj.Y write FObj.Y;
157 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
158 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
159 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
160 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
161 property GameDirection: TDirection read FDirection write FDirection;
163 property StartID: Integer read FStartID;
165 property proxyId: Integer read mProxyId;
166 property arrIdx: Integer read mArrIdx;
167 end;
170 // will be called from map loader
171 procedure g_Mons_InitTree (x, y, w, h: Integer);
173 procedure g_Monsters_LoadData ();
174 procedure g_Monsters_FreeData ();
175 procedure g_Monsters_Init ();
176 procedure g_Monsters_Free (clearGrid: Boolean=true);
177 function g_Monsters_Create (MonsterType: Byte; X, Y: Integer; Direction: TDirection;
178 AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
179 procedure g_Monsters_Update ();
180 procedure g_Monsters_Draw ();
181 procedure g_Monsters_DrawHealth ();
182 function g_Monsters_ByUID (UID: Word): TMonster;
183 procedure g_Monsters_killedp ();
184 procedure g_Monsters_SaveState (var Mem: TBinMemoryWriter);
185 procedure g_Monsters_LoadState (var Mem: TBinMemoryReader);
186 function g_Monsters_GetIDByName (name: String): Integer;
187 function g_Monsters_GetNameByID (MonsterType: Byte): String;
188 function g_Monsters_GetKilledBy (MonsterType: Byte): String;
191 type
192 TEachMonsterCB = function (mon: TMonster): Boolean is nested; // return `true` to stop
194 // throws on invalid uid
195 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
197 // can return null
198 function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
200 function g_Mons_TotalCount (): Integer; inline;
202 function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
204 function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
205 function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
207 function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
208 function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
210 function g_Mons_getNewTrapFrameId (): DWord;
213 type
214 TMonsAlongLineCB = function (mon: TMonster; tag: Integer): Boolean is nested;
216 function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
219 var
220 gmon_debug_use_sqaccel: Boolean = true;
223 //HACK!
224 procedure g_Mons_ProfilersBegin ();
225 procedure g_Mons_ProfilersEnd ();
227 procedure g_Mons_LOS_Start (); inline;
228 procedure g_Mons_LOS_End (); inline;
230 var
231 profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
234 type
235 TMonsterGrid = specialize TBodyGridBase<TMonster>;
237 var
238 monsGrid: TMonsterGrid = nil; // DO NOT USE! public for debugging only!
241 var
242 gmon_debug_think: Boolean = true;
243 gmon_debug_one_think_step: Boolean = false;
246 implementation
248 uses
249 e_log, g_main, g_sound, g_gfx, g_player, g_game,
250 g_weapons, g_triggers, MAPDEF, g_items, g_options,
251 g_console, g_map, Math, SysUtils, g_menu, wadreader,
252 g_language, g_netmsg, idpool;
255 // ////////////////////////////////////////////////////////////////////////// //
256 procedure g_Mons_ProfilersBegin ();
257 begin
258 if (profMonsLOS = nil) then profMonsLOS := TProfiler.Create('LOS CALC', g_profile_history_size);
259 profMonsLOS.mainBegin(g_profile_los);
260 if g_profile_los then
261 begin
262 profMonsLOS.sectionBegin('loscalc');
263 profMonsLOS.sectionEnd();
264 end;
265 end;
267 procedure g_Mons_ProfilersEnd ();
268 begin
269 if (profMonsLOS <> nil) and (g_profile_los) then profMapCollision.mainEnd();
270 end;
272 procedure g_Mons_LOS_Start (); inline;
273 begin
274 profMonsLOS.sectionBeginAccum('loscalc');
275 end;
277 procedure g_Mons_LOS_End (); inline;
278 begin
279 profMonsLOS.sectionEnd();
280 end;
283 // ////////////////////////////////////////////////////////////////////////// //
284 var
285 monCheckTrapLastFrameId: DWord;
288 procedure TMonster.getMapBox (out x, y, w, h: Integer); inline;
289 begin
290 x := FObj.X+FObj.Rect.X;
291 y := FObj.Y+FObj.Rect.Y;
292 w := FObj.Rect.Width;
293 h := FObj.Rect.Height;
294 end;
297 // ////////////////////////////////////////////////////////////////////////// //
298 function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
299 begin
300 if not assigned(cb) then begin result := nil; exit; end;
301 result := monsGrid.forEachAlongLine(x0, y0, x1, y1, cb, -1, log);
302 end;
305 //WARNING! call this after monster position was changed, or coldet will not work right!
306 procedure TMonster.positionChanged ();
307 var
308 x, y, w, h: Integer;
309 nx, ny, nw, nh: Integer;
310 begin
311 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
312 //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);
313 {$ENDIF}
314 if (mProxyId = -1) then
315 begin
316 mProxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
317 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
318 monsGrid.getBodyXY(mProxyId, x, y);
319 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);
320 {$ENDIF}
321 end
322 else
323 begin
324 monsGrid.getBodyDims(mProxyId, x, y, w, h);
325 getMapBox(nx, ny, nw, nh);
327 if (w <> nw) or (h <> nh) then
328 begin
329 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
330 e_WriteLog(Format('monster #%d:(%u): resized; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
331 {$ENDIF}
332 monsGrid.moveResizeBody(mProxyId, nx, ny, nw, nh);
333 end
334 else if (x <> nx) or (y <> ny) then
335 begin
336 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
337 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);
338 {$ENDIF}
339 monsGrid.moveBody(mProxyId, nx, ny);
340 end
341 else
342 begin
343 exit; // nothing to do
344 end;
345 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
346 monsGrid.getBodyXY(mProxyId, x, y);
347 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);
348 {$ENDIF}
349 end;
350 end;
353 // ////////////////////////////////////////////////////////////////////////// //
354 const
355 ANIM_SLEEP = 0;
356 ANIM_GO = 1;
357 ANIM_DIE = 2;
358 ANIM_MESS = 3;
359 ANIM_ATTACK = 4;
360 ANIM_ATTACK2 = 5;
361 ANIM_PAIN = 6;
363 MONSTER_SIGNATURE = $534E4F4D; // 'MONS'
365 // Òàáëèöà òèïîâ àíèìàöèè ìîíñòðîâ:
366 ANIMTABLE: Array [ANIM_SLEEP..ANIM_PAIN] of
367 record
368 name: String;
369 loop: Boolean;
370 end = ((name: 'SLEEP'; loop: True),
371 (name: 'GO'; loop: True),
372 (name: 'DIE'; loop: False),
373 (name: 'MESS'; loop: False),
374 (name: 'ATTACK'; loop: False),
375 (name: 'ATTACK2'; loop: False),
376 (name: 'PAIN'; loop: False));
378 // Òàáëèöà õàðàêòåðèñòèê ìîíñòðîâ:
379 MONSTERTABLE: Array [MONSTER_DEMON..MONSTER_MAN] of
380 record
381 Name: String;
382 Rect: TRectWH;
383 Health: Word;
384 RunVel: Byte;
385 MinPain: Byte;
386 Pain: Byte;
387 Jump: Byte;
388 end =
389 ((Name:'DEMON'; Rect:(X:7; Y:8; Width:50; Height:52); Health:60;
390 RunVel: 7; MinPain: 10; Pain: 20; Jump: 10),
392 (Name:'IMP'; Rect:(X:15; Y:10; Width:34; Height:50); Health:25;
393 RunVel: 3; MinPain: 0; Pain: 15; Jump: 10),
395 (Name:'ZOMBY'; Rect:(X:15; Y:8; Width:34; Height:52); Health:15;
396 RunVel: 3; MinPain: 0; Pain: 10; Jump: 10),
398 (Name:'SERG'; Rect:(X:15; Y:8; Width:34; Height:52); Health:20;
399 RunVel: 3; MinPain: 0; Pain: 10; Jump: 10),
401 (Name:'CYBER'; Rect:(X:24; Y:9; Width:80; Height:110); Health:500;
402 RunVel: 5; MinPain: 50; Pain: 70; Jump: 10),
404 (Name:'CGUN'; Rect:(X:15; Y:4; Width:34; Height:56); Health:60;
405 RunVel: 3; MinPain: 10; Pain: 20; Jump: 10),
407 (Name:'BARON'; Rect:(X:39; Y:32; Width:50; Height:64); Health:150;
408 RunVel: 3; MinPain: 30; Pain: 40; Jump: 10),
410 (Name:'KNIGHT'; Rect:(X:39; Y:32; Width:50; Height:64); Health:75;
411 RunVel: 3; MinPain: 30; Pain: 40; Jump: 10),
413 (Name:'CACO'; Rect:(X:34; Y:36; Width:60; Height:56); Health:100;
414 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
416 (Name:'SOUL'; Rect:(X:16; Y:14; Width:32; Height:36); Health:60;
417 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
419 (Name:'PAIN'; Rect:(X:34; Y:36; Width:60; Height:56); Health:100;
420 RunVel: 4; MinPain: 0; Pain: 10; Jump: 4),
422 (Name:'SPIDER'; Rect:(X:23; Y:14; Width:210; Height:100); Health:500;
423 RunVel: 4; MinPain: 50; Pain: 70; Jump: 10),
425 (Name:'BSP'; Rect:(X:14; Y:17; Width:100; Height:42); Health:150;
426 RunVel: 4; MinPain: 0; Pain: 20; Jump: 10),
428 (Name:'MANCUB'; Rect:(X:28; Y:34; Width:72; Height:60); Health:200;
429 RunVel: 3; MinPain: 20; Pain: 40; Jump: 7),
431 (Name:'SKEL'; Rect:(X:30; Y:28; Width:68; Height:72); Health:200;
432 RunVel: 6; MinPain: 20; Pain: 40; Jump: 11),
434 (Name:'VILE'; Rect:(X:30; Y:28; Width:68; Height:72); Health:150;
435 RunVel: 7; MinPain: 10; Pain: 30; Jump: 12),
437 (Name:'FISH'; Rect:(X:6; Y:11; Width:20; Height:10); Health:35;
438 RunVel: 14; MinPain: 10; Pain: 20; Jump: 6),
440 (Name:'BARREL'; Rect:(X:20; Y:13; Width:24; Height:36); Health:20;
441 RunVel: 0; MinPain: 0; Pain: 0; Jump: 0),
443 (Name:'ROBO'; Rect:(X:30; Y:26; Width:68; Height:76); Health:20;
444 RunVel: 3; MinPain: 20; Pain: 40; Jump: 6),
446 (Name:'MAN'; Rect:(X:15; Y:6; Width:34; Height:52); Health:400;
447 RunVel: 8; MinPain: 50; Pain: 70; Jump: 10));
449 // Òàáëèöà ïàðàìåòðîâ àíèìàöèè ìîíñòðîâ:
450 MONSTER_ANIMTABLE: Array [MONSTER_DEMON..MONSTER_MAN] of
451 record
452 LeftAnim: Boolean;
453 wX, wY: Integer; // Îòêóäà âûëåòèò ïóëÿ
454 AnimSpeed: Array [ANIM_SLEEP..ANIM_PAIN] of Byte;
455 AnimDeltaRight: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
456 AnimDeltaLeft: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
457 end = // SLEEP GO DIE MESS ATTACK ATTACK2 PAIN
458 ((LeftAnim: False; wX: 54; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //DEMON
459 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));
460 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))),
462 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //IMP
463 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));
464 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))),
466 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //ZOMBY
467 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));
468 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))),
470 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //SERG
471 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));
472 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))),
474 (LeftAnim: True; wX: 70; wY: 73; AnimSpeed:(3, 3, 3, 3, 3, 4, 3); //CYBER
475 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));
476 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))),
478 (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 1, 0, 4); //CGUN
479 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));
480 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))),
482 (LeftAnim: True; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //BARON
483 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));
484 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))),
486 (LeftAnim: True; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //KNIGHT
487 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));
488 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))),
490 (LeftAnim: False; wX: 88; wY: 69; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //CACO
491 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));
492 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))),
494 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 4, 1, 0, 4); //SOUL
495 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));
496 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))),
498 (LeftAnim: False; wX: 64; wY: 64; AnimSpeed:(3, 2, 3, 4, 2, 0, 4); //PAIN
499 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));
500 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))),
502 (LeftAnim: True; wX: 128; wY: 64; AnimSpeed:(3, 2, 4, 4, 1, 0, 4); //SPIDER
503 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));
504 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))),
506 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 2, 3, 4, 1, 0, 4); //BSP
507 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));
508 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))),
510 (LeftAnim: False; wX: 64; wY: 64; AnimSpeed:(3, 2, 2, 4, 2, 0, 4); //MANCUB
511 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));
512 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))),
514 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 3, 3, 3, 3, 3, 3); //SKEL
515 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));
516 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))),
518 (LeftAnim: True; wX: 64; wY: 32; AnimSpeed:(3, 3, 3, 3, 3, 3, 3); //VILE
519 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));
520 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))),
522 (LeftAnim: False; wX: 8; wY: 8; AnimSpeed:(2, 2, 2, 2, 3, 0, 1); //FISH
523 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));
524 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 ))),
526 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 0, 3, 0, 0, 0, 5); //BARREL
527 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));
528 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))),
530 (LeftAnim: False; wX: 95; wY: 57; AnimSpeed:(1, 2, 1, 0, 1, 1, 0); //ROBO
531 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));
532 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))),
534 (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 2, 0, 5); //MAN
535 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));
536 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))) );
538 MAX_ATM = 89; // Âðåìÿ îæèäàíèÿ ïîñëå ïîòåðè öåëè
539 MAX_SOUL = 512; // Îãðàíè÷åíèå Lost_Soul'îâ
542 var
543 gMonsters: array of TMonster;
544 uidMap: array [0..65535] of TMonster; // monster knows it's index
545 freeInds: TIdPool = nil;
548 procedure clearUidMap ();
549 var
550 idx: Integer;
551 begin
552 for idx := 0 to High(uidMap) do uidMap[idx] := nil;
553 freeInds.clear();
554 end;
557 function g_Mons_getNewTrapFrameId (): DWord;
558 var
559 f: Integer;
560 begin
561 Inc(monCheckTrapLastFrameId);
562 if monCheckTrapLastFrameId = 0 then
563 begin
564 // wraparound
565 monCheckTrapLastFrameId := 1;
566 for f := 0 to High(gMonsters) do
567 begin
568 if (gMonsters[f] <> nil) then gMonsters[f].trapCheckFrameId := 0;
569 end;
570 end;
571 result := monCheckTrapLastFrameId;
572 end;
575 var
576 pt_x: Integer = 0;
577 pt_xs: Integer = 1;
578 pt_y: Integer = 0;
579 pt_ys: Integer = 1;
580 soulcount: Integer = 0;
583 function allocMonster (): DWORD;
584 var
585 f, olen: Integer;
586 begin
587 result := freeInds.alloc();
588 if (result > High(gMonsters)) then
589 begin
590 olen := Length(gMonsters);
591 SetLength(gMonsters, result+64);
592 for f := olen to High(gMonsters) do gMonsters[f] := nil;
593 end;
594 end;
597 function IsFriend(a, b: Byte): Boolean;
598 begin
599 Result := True;
601 // Áî÷êà - âñåì äðóã:
602 if (a = MONSTER_BARREL) or (b = MONSTER_BARREL) then
603 Exit;
605 // Ìîíñòðû îäíîãî âèäà:
606 if a = b then
607 case a of
608 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
609 MONSTER_SOUL, MONSTER_PAIN, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
610 Exit; // Ýòè íå áüþò ñâîèõ
611 end;
613 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
614 if (a = MONSTER_SOUL) and (b = MONSTER_PAIN) then
615 Exit;
616 // Pain_Elemental íå ìîæåò ðàíèòü Lost_Soul'à:
617 if (b = MONSTER_SOUL) and (a = MONSTER_PAIN) then
618 Exit;
620 //  îñòàëüíûõ ñëó÷àÿõ - áóäóò áèòü äðóã äðóãà:
621 Result := False;
622 end;
625 function BehaviourDamage(SpawnerUID: Word; BH, SelfType: Byte): Boolean;
626 var
627 m: TMonster;
628 UIDType, MonsterType: Byte;
629 begin
630 Result := False;
631 MonsterType := 0;
633 UIDType := g_GetUIDType(SpawnerUID);
634 if UIDType = UID_MONSTER then
635 begin
636 m := g_Monsters_ByUID(SpawnerUID);
637 if m = nil then Exit;
638 MonsterType := m.FMonsterType;
639 end;
641 case BH of
642 BH_NORMAL: Result := (UIDType = UID_PLAYER) or
643 ((UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType)));
645 BH_KILLER: Result := UIDType = UID_PLAYER;
646 BH_MANIAC: Result := (UIDType = UID_PLAYER) or
647 ((UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType)));
649 BH_INSANE: Result := (UIDType = UID_MONSTER) and (not IsFriend(MonsterType, SelfType));
650 BH_CANNIBAL: Result := (UIDType = UID_MONSTER) and (MonsterType = SelfType);
651 end;
652 end;
655 function canShoot(m: Byte): Boolean;
656 begin
657 Result := False;
659 case m of
660 MONSTER_DEMON, MONSTER_FISH, MONSTER_BARREL:
661 Exit;
662 else
663 Result := True;
664 end;
665 end;
668 function isCorpse (o: PObj; immediately: Boolean): Integer;
670 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
671 begin
672 atag := atag; // shut up, fpc!
673 result := false; // don't stop
674 if (mon.FState = MONSTATE_DEAD) and g_Obj_Collide(o, @mon.FObj) then
675 begin
676 case mon.FMonsterType of // Íå âîñêðåñèòü:
677 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
678 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: exit;
679 end;
680 // Îñòàëüíûõ ìîæíî âîñêðåñèòü
681 result := true;
682 end;
683 end;
685 var
686 a: Integer;
687 mon: TMonster;
688 begin
689 result := -1;
691 // Åñëè íóæíà âåðîÿòíîñòü
692 if not immediately and (Random(8) <> 0) then exit;
694 // Èùåì ìåðòâûõ ìîíñòðîâ ïîáëèçîñòè
695 if gmon_debug_use_sqaccel then
696 begin
697 mon := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height, monsCollCheck);
698 if (mon <> nil) then result := mon.mArrIdx;
699 end
700 else
701 begin
702 for a := 0 to High(gMonsters) do
703 begin
704 if (gMonsters[a] <> nil) and (gMonsters[a].FState = MONSTATE_DEAD) and g_Obj_Collide(o, @gMonsters[a].FObj) then
705 begin
706 case gMonsters[a].FMonsterType of // Íå âîñêðåñèòü:
707 MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
708 MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: Continue;
709 else // Îñòàëüíûõ ìîæíî âîñêðåñèòü
710 begin
711 Result := a;
712 Exit;
713 end;
714 end;
715 end;
716 end;
717 end;
718 end;
720 procedure g_Monsters_LoadData();
721 begin
722 e_WriteLog('Loading monsters data...', MSG_NOTIFY);
724 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 0%', 0, False);
725 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_SLEEP', GameWAD+':MTEXTURES\BARREL_SLEEP', 64, 64, 3);
726 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_DIE', GameWAD+':MTEXTURES\BARREL_DIE', 64, 64, 4);
727 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_PAIN', GameWAD+':MTEXTURES\BARREL_PAIN', 64, 64, 1);
728 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_SLEEP', GameWAD+':MTEXTURES\ZOMBY_SLEEP', 64, 64, 2);
729 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_GO', GameWAD+':MTEXTURES\ZOMBY_GO', 64, 64, 4);
730 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_DIE', GameWAD+':MTEXTURES\ZOMBY_DIE', 64, 64, 6);
731 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 5%', 0, True);
732 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_MESS', GameWAD+':MTEXTURES\ZOMBY_MESS', 64, 64, 9);
733 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK', GameWAD+':MTEXTURES\ZOMBY_ATTACK', 64, 64, 2);
734 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_PAIN', GameWAD+':MTEXTURES\ZOMBY_PAIN', 64, 64, 1);
735 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_SLEEP', GameWAD+':MTEXTURES\SERG_SLEEP', 64, 64, 2);
736 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_GO', GameWAD+':MTEXTURES\SERG_GO', 64, 64, 4);
737 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_DIE', GameWAD+':MTEXTURES\SERG_DIE', 64, 64, 5);
738 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 10%', 0, True);
739 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_MESS', GameWAD+':MTEXTURES\SERG_MESS', 64, 64, 9);
740 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK', GameWAD+':MTEXTURES\SERG_ATTACK', 64, 64, 2);
741 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_PAIN', GameWAD+':MTEXTURES\SERG_PAIN', 64, 64, 1);
742 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_SLEEP', GameWAD+':MTEXTURES\MAN_SLEEP', 64, 64, 2);
743 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_GO', GameWAD+':MTEXTURES\MAN_GO', 64, 64, 4);
744 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_DIE', GameWAD+':MTEXTURES\MAN_DIE', 64, 64, 7);
745 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 15%', 0, True);
746 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_MESS', GameWAD+':MTEXTURES\MAN_MESS', 64, 64, 9);
747 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_ATTACK', GameWAD+':MTEXTURES\MAN_ATTACK', 64, 64, 2);
748 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_PAIN', GameWAD+':MTEXTURES\MAN_PAIN', 64, 64, 1);
749 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP', GameWAD+':MTEXTURES\CGUN_SLEEP', 64, 64, 2);
750 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP_L', GameWAD+':MTEXTURES\CGUN_SLEEP_L', 64, 64, 2);
751 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO', GameWAD+':MTEXTURES\CGUN_GO', 64, 64, 4);
752 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 20%', 0, True);
753 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO_L', GameWAD+':MTEXTURES\CGUN_GO_L', 64, 64, 4);
754 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_DIE', GameWAD+':MTEXTURES\CGUN_DIE', 64, 64, 7);
755 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_MESS', GameWAD+':MTEXTURES\CGUN_MESS', 64, 64, 6);
756 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK', GameWAD+':MTEXTURES\CGUN_ATTACK', 64, 64, 2);
757 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK_L', GameWAD+':MTEXTURES\CGUN_ATTACK_L', 64, 64, 2);
758 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN', GameWAD+':MTEXTURES\CGUN_PAIN', 64, 64, 1);
759 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 25%', 0, True);
760 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN_L', GameWAD+':MTEXTURES\CGUN_PAIN_L', 64, 64, 1);
761 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_SLEEP', GameWAD+':MTEXTURES\IMP_SLEEP', 64, 64, 2);
762 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_GO', GameWAD+':MTEXTURES\IMP_GO', 64, 64, 4);
763 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_DIE', GameWAD+':MTEXTURES\IMP_DIE', 64, 64, 5);
764 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_MESS', GameWAD+':MTEXTURES\IMP_MESS', 64, 64, 8);
765 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_ATTACK', GameWAD+':MTEXTURES\IMP_ATTACK', 64, 64, 3);
766 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 30%', 0, True);
767 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_PAIN', GameWAD+':MTEXTURES\IMP_PAIN', 64, 64, 1);
768 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_SLEEP', GameWAD+':MTEXTURES\DEMON_SLEEP', 64, 64, 2);
769 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_GO', GameWAD+':MTEXTURES\DEMON_GO', 64, 64, 4);
770 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_DIE', GameWAD+':MTEXTURES\DEMON_DIE', 64, 64, 6);
771 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_ATTACK', GameWAD+':MTEXTURES\DEMON_ATTACK', 64, 64, 3);
772 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_PAIN', GameWAD+':MTEXTURES\DEMON_PAIN', 64, 64, 1);
773 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 35%', 0, True);
774 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_SLEEP', GameWAD+':MTEXTURES\SOUL_SLEEP', 64, 64, 2);
775 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_GO', GameWAD+':MTEXTURES\SOUL_GO', 64, 64, 2);
776 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_PAIN', GameWAD+':MTEXTURES\SOUL_PAIN', 64, 64, 1);
777 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_ATTACK', GameWAD+':MTEXTURES\SOUL_ATTACK', 64, 64, 2);
778 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_DIE', GameWAD+':MTEXTURES\SOUL_DIE', 128, 128, 7);
779 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_SLEEP', GameWAD+':MTEXTURES\FISH_SLEEP', 32, 32, 2);
780 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 40%', 0, True);
781 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_GO', GameWAD+':MTEXTURES\FISH_GO', 32, 32, 4);
782 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_PAIN', GameWAD+':MTEXTURES\FISH_PAIN', 32, 32, 3);
783 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_ATTACK', GameWAD+':MTEXTURES\FISH_ATTACK', 32, 32, 2);
784 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_DIE', GameWAD+':MTEXTURES\FISH_DIE', 32, 32, 1);
785 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_SLEEP', GameWAD+':MTEXTURES\SPIDER_SLEEP', 256, 128, 2);
786 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_GO', GameWAD+':MTEXTURES\SPIDER_GO', 256, 128, 6);
787 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 45%', 0, True);
788 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN', GameWAD+':MTEXTURES\SPIDER_PAIN', 256, 128, 1);
789 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN_L', GameWAD+':MTEXTURES\SPIDER_PAIN_L', 256, 128, 1);
790 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_ATTACK', GameWAD+':MTEXTURES\SPIDER_ATTACK', 256, 128, 2);
791 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_DIE', GameWAD+':MTEXTURES\SPIDER_DIE', 256, 128, 10);
792 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_SLEEP', GameWAD+':MTEXTURES\BSP_SLEEP', 128, 64, 2);
793 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_GO', GameWAD+':MTEXTURES\BSP_GO', 128, 64, 6);
794 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 50%', 0, True);
795 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN', GameWAD+':MTEXTURES\BSP_PAIN', 128, 64, 1);
796 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN_L', GameWAD+':MTEXTURES\BSP_PAIN_L', 128, 64, 1);
797 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_ATTACK', GameWAD+':MTEXTURES\BSP_ATTACK', 128, 64, 2);
798 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_DIE', GameWAD+':MTEXTURES\BSP_DIE', 128, 64, 7);
799 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_SLEEP', GameWAD+':MTEXTURES\CACO_SLEEP', 128, 128, 1);
800 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_GO', GameWAD+':MTEXTURES\CACO_GO', 128, 128, 1);
801 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 55%', 0, True);
802 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_PAIN', GameWAD+':MTEXTURES\CACO_PAIN', 128, 128, 1);
803 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_ATTACK', GameWAD+':MTEXTURES\CACO_ATTACK', 128, 128, 6);
804 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_DIE', GameWAD+':MTEXTURES\CACO_DIE', 128, 128, 7);
805 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_SLEEP', GameWAD+':MTEXTURES\PAIN_SLEEP', 128, 128, 4);
806 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_GO', GameWAD+':MTEXTURES\PAIN_GO', 128, 128, 4);
807 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_PAIN', GameWAD+':MTEXTURES\PAIN_PAIN', 128, 128, 1);
808 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 60%', 0, True);
809 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_ATTACK', GameWAD+':MTEXTURES\PAIN_ATTACK', 128, 128, 4);
810 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_DIE', GameWAD+':MTEXTURES\PAIN_DIE', 128, 128, 7);
811 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP', GameWAD+':MTEXTURES\BARON_SLEEP', 128, 128, 2);
812 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP_L', GameWAD+':MTEXTURES\BARON_SLEEP_L', 128, 128, 2);
813 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_GO', GameWAD+':MTEXTURES\BARON_GO', 128, 128, 4);
814 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN', GameWAD+':MTEXTURES\BARON_PAIN', 128, 128, 1);
815 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 65%', 0, True);
816 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN_L', GameWAD+':MTEXTURES\BARON_PAIN_L', 128, 128, 1);
817 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK', GameWAD+':MTEXTURES\BARON_ATTACK', 128, 128, 3);
818 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK_L', GameWAD+':MTEXTURES\BARON_ATTACK_L', 128, 128, 3);
819 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_DIE', GameWAD+':MTEXTURES\BARON_DIE', 128, 128, 7);
820 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP', GameWAD+':MTEXTURES\KNIGHT_SLEEP', 128, 128, 2);
821 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP_L', GameWAD+':MTEXTURES\KNIGHT_SLEEP_L', 128, 128, 2);
822 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 70%', 0, True);
823 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_GO', GameWAD+':MTEXTURES\KNIGHT_GO', 128, 128, 4);
824 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN', GameWAD+':MTEXTURES\KNIGHT_PAIN', 128, 128, 1);
825 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN_L', GameWAD+':MTEXTURES\KNIGHT_PAIN_L', 128, 128, 1);
826 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK', GameWAD+':MTEXTURES\KNIGHT_ATTACK', 128, 128, 3);
827 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK_L', GameWAD+':MTEXTURES\KNIGHT_ATTACK_L', 128, 128, 3);
828 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_DIE', GameWAD+':MTEXTURES\KNIGHT_DIE', 128, 128, 7);
829 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 75%', 0, True);
830 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_SLEEP', GameWAD+':MTEXTURES\MANCUB_SLEEP', 128, 128, 2);
831 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_GO', GameWAD+':MTEXTURES\MANCUB_GO', 128, 128, 6);
832 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_PAIN', GameWAD+':MTEXTURES\MANCUB_PAIN', 128, 128, 1);
833 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_ATTACK', GameWAD+':MTEXTURES\MANCUB_ATTACK', 128, 128, 3);
834 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_DIE', GameWAD+':MTEXTURES\MANCUB_DIE', 128, 128, 10);
835 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP', GameWAD+':MTEXTURES\SKEL_SLEEP', 128, 128, 2);
836 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 80%', 0, True);
837 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP_L', GameWAD+':MTEXTURES\SKEL_SLEEP_L', 128, 128, 2);
838 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_GO', GameWAD+':MTEXTURES\SKEL_GO', 128, 128, 6);
839 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN', GameWAD+':MTEXTURES\SKEL_PAIN', 128, 128, 1);
840 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN_L', GameWAD+':MTEXTURES\SKEL_PAIN_L', 128, 128, 1);
841 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK', GameWAD+':MTEXTURES\SKEL_ATTACK', 128, 128, 2);
842 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK_L', GameWAD+':MTEXTURES\SKEL_ATTACK_L', 128, 128, 2);
843 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 85%', 0, True);
844 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2', GameWAD+':MTEXTURES\SKEL_ATTACK2', 128, 128, 2);
845 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2_L', GameWAD+':MTEXTURES\SKEL_ATTACK2_L', 128, 128, 2);
846 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_DIE', GameWAD+':MTEXTURES\SKEL_DIE', 128, 128, 5);
847 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP', GameWAD+':MTEXTURES\VILE_SLEEP', 128, 128, 2);
848 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP_L', GameWAD+':MTEXTURES\VILE_SLEEP_L', 128, 128, 2);
849 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_GO', GameWAD+':MTEXTURES\VILE_GO', 128, 128, 6);
850 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 90%', 0, True);
851 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN', GameWAD+':MTEXTURES\VILE_PAIN', 128, 128, 1);
852 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN_L', GameWAD+':MTEXTURES\VILE_PAIN_L', 128, 128, 1);
853 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK', GameWAD+':MTEXTURES\VILE_ATTACK', 128, 128, 10);
854 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK_L', GameWAD+':MTEXTURES\VILE_ATTACK_L', 128, 128, 10);
855 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2', GameWAD+':MTEXTURES\VILE_ATTACK2', 128, 128, 3);
856 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2_L', GameWAD+':MTEXTURES\VILE_ATTACK2_L', 128, 128, 3);
857 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 95%', 0, True);
858 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_DIE', GameWAD+':MTEXTURES\VILE_DIE', 128, 128, 9);
859 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_SLEEP', GameWAD+':MTEXTURES\ROBO_SLEEP', 128, 128, 1);
860 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_GO', GameWAD+':MTEXTURES\ROBO_GO', 128, 128, 12);
861 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK', GameWAD+':MTEXTURES\ROBO_ATTACK', 128, 128, 2);
862 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK2', GameWAD+':MTEXTURES\ROBO_ATTACK2', 128, 128, 4);
863 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_DIE', GameWAD+':MTEXTURES\ROBO_DIE', 128, 128, 1);
864 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 100%', 0, True);
865 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP', GameWAD+':MTEXTURES\CYBER_SLEEP', 128, 128, 2);
866 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP_L', GameWAD+':MTEXTURES\CYBER_SLEEP_L', 128, 128, 2);
867 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO', GameWAD+':MTEXTURES\CYBER_GO', 128, 128, 4);
868 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO_L', GameWAD+':MTEXTURES\CYBER_GO_L', 128, 128, 4);
869 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN', GameWAD+':MTEXTURES\CYBER_PAIN', 128, 128, 1);
870 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN_L', GameWAD+':MTEXTURES\CYBER_PAIN_L', 128, 128, 1);
871 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK', GameWAD+':MTEXTURES\CYBER_ATTACK', 128, 128, 2);
872 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK_L', GameWAD+':MTEXTURES\CYBER_ATTACK_L', 128, 128, 2);
873 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2', GameWAD+':MTEXTURES\CYBER_ATTACK2', 128, 128, 2);
874 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2_L', GameWAD+':MTEXTURES\CYBER_ATTACK2_L', 128, 128, 2);
875 g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_DIE', GameWAD+':MTEXTURES\CYBER_DIE', 128, 128, 9);
877 g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_SOUNDS], 0, False);
879 g_Sound_CreateWADEx('SOUND_MONSTER_BARREL_DIE', GameWAD+':MSOUNDS\BARREL_DIE');
881 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN', GameWAD+':MSOUNDS\PAIN');
882 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN2', GameWAD+':MSOUNDS\PAIN2');
883 g_Sound_CreateWADEx('SOUND_MONSTER_ACTION', GameWAD+':MSOUNDS\ACTION');
884 g_Sound_CreateWADEx('SOUND_MONSTER_ACTION2', GameWAD+':MSOUNDS\ACTION2');
885 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_1', GameWAD+':MSOUNDS\ALERT_1');
886 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_2', GameWAD+':MSOUNDS\ALERT_2');
887 g_Sound_CreateWADEx('SOUND_MONSTER_ALERT_3', GameWAD+':MSOUNDS\ALERT_3');
888 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_1', GameWAD+':MSOUNDS\DIE_1');
889 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_2', GameWAD+':MSOUNDS\DIE_2');
890 g_Sound_CreateWADEx('SOUND_MONSTER_DIE_3', GameWAD+':MSOUNDS\DIE_3');
891 g_Sound_CreateWADEx('SOUND_MONSTER_SLOP', GameWAD+':MSOUNDS\SLOP');
893 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_ATTACK', GameWAD+':MSOUNDS\DEMON_ATTACK');
894 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_ALERT', GameWAD+':MSOUNDS\DEMON_ALERT');
895 g_Sound_CreateWADEx('SOUND_MONSTER_DEMON_DIE', GameWAD+':MSOUNDS\DEMON_DIE');
897 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ALERT_1', GameWAD+':MSOUNDS\IMP_ALERT_1');
898 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ALERT_2', GameWAD+':MSOUNDS\IMP_ALERT_2');
899 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_DIE_1', GameWAD+':MSOUNDS\IMP_DIE_1');
900 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_DIE_2', GameWAD+':MSOUNDS\IMP_DIE_2');
901 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ACTION', GameWAD+':MSOUNDS\IMP_ACTION');
902 g_Sound_CreateWADEx('SOUND_MONSTER_IMP_ATTACK', GameWAD+':MSOUNDS\IMP_ATTACK');
904 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_PAIN', GameWAD+':MSOUNDS\MAN_PAIN');
905 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_ALERT', GameWAD+':MSOUNDS\MAN_ALERT');
906 g_Sound_CreateWADEx('SOUND_MONSTER_MAN_DIE', GameWAD+':MSOUNDS\MAN_DIE');
907 g_Sound_CreateWADEx('SOUND_MONSTER_HAHA', GameWAD+':MSOUNDS\HAHA');
908 g_Sound_CreateWADEx('SOUND_MONSTER_TRUP', GameWAD+':MSOUNDS\TRUP');
910 g_Sound_CreateWADEx('SOUND_MONSTER_SOUL_ATTACK', GameWAD+':MSOUNDS\SOUL_ATTACK');
911 g_Sound_CreateWADEx('SOUND_MONSTER_SOUL_DIE', GameWAD+':MSOUNDS\SOUL_DIE');
913 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_ACTION', GameWAD+':MSOUNDS\BSP_ACTION');
914 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_DIE', GameWAD+':MSOUNDS\BSP_DIE');
915 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_ALERT', GameWAD+':MSOUNDS\BSP_ALERT');
916 g_Sound_CreateWADEx('SOUND_MONSTER_BSP_WALK', GameWAD+':MSOUNDS\BSP_WALK');
918 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ACTION', GameWAD+':MSOUNDS\VILE_ACTION');
919 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_PAIN', GameWAD+':MSOUNDS\VILE_PAIN');
920 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_DIE', GameWAD+':MSOUNDS\VILE_DIE');
921 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ALERT', GameWAD+':MSOUNDS\VILE_ALERT');
922 g_Sound_CreateWADEx('SOUND_MONSTER_VILE_ATTACK', GameWAD+':MSOUNDS\VILE_ATTACK');
924 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ACTION', GameWAD+':MSOUNDS\SKEL_ACTION');
925 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_DIE', GameWAD+':MSOUNDS\SKEL_DIE');
926 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ALERT', GameWAD+':MSOUNDS\SKEL_ALERT');
927 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_ATTACK', GameWAD+':MSOUNDS\SKEL_ATTACK');
928 g_Sound_CreateWADEx('SOUND_MONSTER_SKEL_HIT', GameWAD+':MSOUNDS\SKEL_HIT');
930 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_PAIN', GameWAD+':MSOUNDS\MANCUB_PAIN');
931 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_DIE', GameWAD+':MSOUNDS\MANCUB_DIE');
932 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_ALERT', GameWAD+':MSOUNDS\MANCUB_ALERT');
933 g_Sound_CreateWADEx('SOUND_MONSTER_MANCUB_ATTACK', GameWAD+':MSOUNDS\MANCUB_ATTACK');
935 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_PAIN', GameWAD+':MSOUNDS\PAIN_PAIN');
936 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_DIE', GameWAD+':MSOUNDS\PAIN_DIE');
937 g_Sound_CreateWADEx('SOUND_MONSTER_PAIN_ALERT', GameWAD+':MSOUNDS\PAIN_ALERT');
939 g_Sound_CreateWADEx('SOUND_MONSTER_BARON_DIE', GameWAD+':MSOUNDS\BARON_DIE');
940 g_Sound_CreateWADEx('SOUND_MONSTER_BARON_ALERT', GameWAD+':MSOUNDS\BARON_ALERT');
942 g_Sound_CreateWADEx('SOUND_MONSTER_CACO_DIE', GameWAD+':MSOUNDS\CACO_DIE');
943 g_Sound_CreateWADEx('SOUND_MONSTER_CACO_ALERT', GameWAD+':MSOUNDS\CACO_ALERT');
945 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_DIE', GameWAD+':MSOUNDS\CYBER_DIE');
946 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_ALERT', GameWAD+':MSOUNDS\CYBER_ALERT');
947 g_Sound_CreateWADEx('SOUND_MONSTER_CYBER_WALK', GameWAD+':MSOUNDS\CYBER_WALK');
949 g_Sound_CreateWADEx('SOUND_MONSTER_KNIGHT_DIE', GameWAD+':MSOUNDS\KNIGHT_DIE');
950 g_Sound_CreateWADEx('SOUND_MONSTER_KNIGHT_ALERT', GameWAD+':MSOUNDS\KNIGHT_ALERT');
952 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_DIE', GameWAD+':MSOUNDS\SPIDER_DIE');
953 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_ALERT', GameWAD+':MSOUNDS\SPIDER_ALERT');
954 g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_WALK', GameWAD+':MSOUNDS\SPIDER_WALK');
956 g_Sound_CreateWADEx('SOUND_MONSTER_FISH_ATTACK', GameWAD+':MSOUNDS\FISH_ATTACK');
958 freeInds := TIdPool.Create();
959 clearUidMap();
960 monCheckTrapLastFrameId := 0;
961 end;
963 procedure g_Monsters_FreeData();
964 begin
965 e_WriteLog('Releasing monsters data...', MSG_NOTIFY);
967 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_SLEEP');
968 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_PAIN');
969 g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_DIE');
970 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_SLEEP');
971 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_GO');
972 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_DIE');
973 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_MESS');
974 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK');
975 g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_PAIN');
976 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_SLEEP');
977 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_GO');
978 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_DIE');
979 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_MESS');
980 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK');
981 g_Frames_DeleteByName('FRAMES_MONSTER_SERG_PAIN');
982 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_SLEEP');
983 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_GO');
984 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_DIE');
985 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_MESS');
986 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_ATTACK');
987 g_Frames_DeleteByName('FRAMES_MONSTER_MAN_PAIN');
988 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_SLEEP');
989 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_SLEEP_L');
990 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_GO');
991 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_GO_L');
992 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_DIE');
993 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_MESS');
994 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_ATTACK');
995 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_ATTACK_L');
996 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_PAIN');
997 g_Frames_DeleteByName('FRAMES_MONSTER_CGUN_PAIN_L');
998 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_SLEEP');
999 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_GO');
1000 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_DIE');
1001 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_MESS');
1002 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_ATTACK');
1003 g_Frames_DeleteByName('FRAMES_MONSTER_IMP_PAIN');
1004 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_SLEEP');
1005 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_GO');
1006 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_DIE');
1007 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_ATTACK');
1008 g_Frames_DeleteByName('FRAMES_MONSTER_DEMON_PAIN');
1009 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_SLEEP');
1010 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_GO');
1011 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_PAIN');
1012 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_ATTACK');
1013 g_Frames_DeleteByName('FRAMES_MONSTER_SOUL_DIE');
1014 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_SLEEP');
1015 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_GO');
1016 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_PAIN');
1017 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_ATTACK');
1018 g_Frames_DeleteByName('FRAMES_MONSTER_FISH_DIE');
1019 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_SLEEP');
1020 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_GO');
1021 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_PAIN');
1022 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_PAIN_L');
1023 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_ATTACK');
1024 g_Frames_DeleteByName('FRAMES_MONSTER_SPIDER_DIE');
1025 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_SLEEP');
1026 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_GO');
1027 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_PAIN');
1028 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_PAIN_L');
1029 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_ATTACK');
1030 g_Frames_DeleteByName('FRAMES_MONSTER_BSP_DIE');
1031 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_SLEEP');
1032 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_GO');
1033 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_PAIN');
1034 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_ATTACK');
1035 g_Frames_DeleteByName('FRAMES_MONSTER_CACO_DIE');
1036 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_SLEEP');
1037 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_GO');
1038 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_PAIN');
1039 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_ATTACK');
1040 g_Frames_DeleteByName('FRAMES_MONSTER_PAIN_DIE');
1041 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_SLEEP');
1042 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_SLEEP_L');
1043 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_GO');
1044 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_PAIN');
1045 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_PAIN_L');
1046 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_ATTACK');
1047 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_ATTACK_L');
1048 g_Frames_DeleteByName('FRAMES_MONSTER_BARON_DIE');
1049 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_SLEEP');
1050 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_SLEEP_L');
1051 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_GO');
1052 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_PAIN');
1053 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_PAIN_L');
1054 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_ATTACK');
1055 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_ATTACK_L');
1056 g_Frames_DeleteByName('FRAMES_MONSTER_KNIGHT_DIE');
1057 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_SLEEP');
1058 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_GO');
1059 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_PAIN');
1060 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_ATTACK');
1061 g_Frames_DeleteByName('FRAMES_MONSTER_MANCUB_DIE');
1062 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_SLEEP');
1063 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_SLEEP_L');
1064 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_GO');
1065 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_PAIN');
1066 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_PAIN_L');
1067 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK');
1068 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK_L');
1069 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK2');
1070 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_ATTACK2_L');
1071 g_Frames_DeleteByName('FRAMES_MONSTER_SKEL_DIE');
1072 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_SLEEP');
1073 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_SLEEP_L');
1074 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_GO');
1075 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_PAIN');
1076 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_PAIN_L');
1077 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK');
1078 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK_L');
1079 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK2');
1080 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_ATTACK2_L');
1081 g_Frames_DeleteByName('FRAMES_MONSTER_VILE_DIE');
1082 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_SLEEP');
1083 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_GO');
1084 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_ATTACK');
1085 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_ATTACK2');
1086 g_Frames_DeleteByName('FRAMES_MONSTER_ROBO_DIE');
1087 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_SLEEP');
1088 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_SLEEP_L');
1089 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_GO');
1090 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_GO_L');
1091 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN');
1092 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN_L');
1093 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK');
1094 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK_L');
1095 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2');
1096 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2_L');
1097 g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_DIE');
1099 g_Sound_Delete('SOUND_MONSTER_BARREL_DIE');
1101 g_Sound_Delete('SOUND_MONSTER_PAIN');
1102 g_Sound_Delete('SOUND_MONSTER_PAIN2');
1103 g_Sound_Delete('SOUND_MONSTER_ACTION');
1104 g_Sound_Delete('SOUND_MONSTER_ACTION2');
1105 g_Sound_Delete('SOUND_MONSTER_ALERT_1');
1106 g_Sound_Delete('SOUND_MONSTER_ALERT_2');
1107 g_Sound_Delete('SOUND_MONSTER_ALERT_3');
1108 g_Sound_Delete('SOUND_MONSTER_DIE_1');
1109 g_Sound_Delete('SOUND_MONSTER_DIE_2');
1110 g_Sound_Delete('SOUND_MONSTER_DIE_3');
1111 g_Sound_Delete('SOUND_MONSTER_SLOP');
1113 g_Sound_Delete('SOUND_MONSTER_DEMON_ATTACK');
1114 g_Sound_Delete('SOUND_MONSTER_DEMON_ALERT');
1115 g_Sound_Delete('SOUND_MONSTER_DEMON_DIE');
1117 g_Sound_Delete('SOUND_MONSTER_IMP_ALERT_1');
1118 g_Sound_Delete('SOUND_MONSTER_IMP_ALERT_2');
1119 g_Sound_Delete('SOUND_MONSTER_IMP_DIE_1');
1120 g_Sound_Delete('SOUND_MONSTER_IMP_DIE_2');
1121 g_Sound_Delete('SOUND_MONSTER_IMP_ACTION');
1122 g_Sound_Delete('SOUND_MONSTER_IMP_ATTACK');
1124 g_Sound_Delete('SOUND_MONSTER_MAN_PAIN');
1125 g_Sound_Delete('SOUND_MONSTER_MAN_ALERT');
1126 g_Sound_Delete('SOUND_MONSTER_MAN_DIE');
1127 g_Sound_Delete('SOUND_MONSTER_HAHA');
1128 g_Sound_Delete('SOUND_MONSTER_TRUP');
1130 g_Sound_Delete('SOUND_MONSTER_SOUL_ATTACK');
1131 g_Sound_Delete('SOUND_MONSTER_SOUL_DIE');
1133 g_Sound_Delete('SOUND_MONSTER_BSP_ACTION');
1134 g_Sound_Delete('SOUND_MONSTER_BSP_DIE');
1135 g_Sound_Delete('SOUND_MONSTER_BSP_ALERT');
1136 g_Sound_Delete('SOUND_MONSTER_BSP_WALK');
1138 g_Sound_Delete('SOUND_MONSTER_VILE_ACTION');
1139 g_Sound_Delete('SOUND_MONSTER_VILE_PAIN');
1140 g_Sound_Delete('SOUND_MONSTER_VILE_DIE');
1141 g_Sound_Delete('SOUND_MONSTER_VILE_ALERT');
1142 g_Sound_Delete('SOUND_MONSTER_VILE_ATTACK');
1144 g_Sound_Delete('SOUND_MONSTER_SKEL_ACTION');
1145 g_Sound_Delete('SOUND_MONSTER_SKEL_DIE');
1146 g_Sound_Delete('SOUND_MONSTER_SKEL_ALERT');
1147 g_Sound_Delete('SOUND_MONSTER_SKEL_ATTACK');
1148 g_Sound_Delete('SOUND_MONSTER_SKEL_HIT');
1150 g_Sound_Delete('SOUND_MONSTER_MANCUB_PAIN');
1151 g_Sound_Delete('SOUND_MONSTER_MANCUB_DIE');
1152 g_Sound_Delete('SOUND_MONSTER_MANCUB_ALERT');
1153 g_Sound_Delete('SOUND_MONSTER_MANCUB_ATTACK');
1155 g_Sound_Delete('SOUND_MONSTER_PAIN_PAIN');
1156 g_Sound_Delete('SOUND_MONSTER_PAIN_DIE');
1157 g_Sound_Delete('SOUND_MONSTER_PAIN_ALERT');
1159 g_Sound_Delete('SOUND_MONSTER_BARON_DIE');
1160 g_Sound_Delete('SOUND_MONSTER_BARON_ALERT');
1162 g_Sound_Delete('SOUND_MONSTER_CACO_DIE');
1163 g_Sound_Delete('SOUND_MONSTER_CACO_ALERT');
1165 g_Sound_Delete('SOUND_MONSTER_CYBER_DIE');
1166 g_Sound_Delete('SOUND_MONSTER_CYBER_ALERT');
1167 g_Sound_Delete('SOUND_MONSTER_CYBER_WALK');
1169 g_Sound_Delete('SOUND_MONSTER_KNIGHT_DIE');
1170 g_Sound_Delete('SOUND_MONSTER_KNIGHT_ALERT');
1172 g_Sound_Delete('SOUND_MONSTER_SPIDER_DIE');
1173 g_Sound_Delete('SOUND_MONSTER_SPIDER_ALERT');
1174 g_Sound_Delete('SOUND_MONSTER_SPIDER_WALK');
1176 g_Sound_Delete('SOUND_MONSTER_FISH_ATTACK');
1178 freeInds.Free();
1179 freeInds := nil;
1180 end;
1182 procedure g_Monsters_Init();
1183 begin
1184 soulcount := 0;
1185 end;
1187 procedure g_Monsters_Free (clearGrid: Boolean=true);
1188 var
1189 a: Integer;
1190 begin
1191 e_LogWritefln('Cleared monster data (clearGrid=%s)', [clearGrid]);
1192 if (clearGrid) then
1193 begin
1194 monsGrid.Free();
1195 monsGrid := nil;
1196 end;
1197 for a := 0 to High(gMonsters) do gMonsters[a].Free();
1198 gMonsters := nil;
1199 clearUidMap();
1200 monCheckTrapLastFrameId := 0;
1201 end;
1204 // will be called from map loader
1205 procedure g_Mons_InitTree (x, y, w, h: Integer);
1206 begin
1207 monsGrid.Free();
1208 monsGrid := TMonsterGrid.Create(x, y, w, h);
1209 //clearUidMap(); // why not?
1210 e_LogWritefln('%s', ['Recreated monster tree']);
1211 end;
1214 function g_Monsters_Create(MonsterType: Byte; X, Y: Integer;
1215 Direction: TDirection; AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
1216 var
1217 find_id: DWORD;
1218 mon: TMonster;
1219 begin
1220 result := nil;
1222 // Íåò òàêîãî ìîíñòðà
1223 if (MonsterType > MONSTER_MAN) or (MonsterType = 0) then exit;
1225 // Ñîáëþäàåì îãðàíè÷åíèå Lost_Soul'îâ
1226 if MonsterType = MONSTER_SOUL then
1227 begin
1228 if soulcount > MAX_SOUL then exit;
1229 soulcount := soulcount + 1;
1230 end;
1232 find_id := allocMonster();
1234 mon := TMonster.Create(MonsterType, find_id, ForcedUID);
1235 gMonsters[find_id] := mon;
1236 mon.mArrIdx := find_id;
1237 mon.mProxyId := -1;
1239 uidMap[mon.FUID] := mon;
1241 // Íàñòðàèâàåì ïîëîæåíèå
1242 with mon do
1243 begin
1244 if AdjCoord then
1245 begin
1246 FObj.X := X-FObj.Rect.X - (FObj.Rect.Width div 2);
1247 FObj.Y := Y-FObj.Rect.Y - FObj.Rect.Height;
1248 end
1249 else
1250 begin
1251 FObj.X := X-FObj.Rect.X;
1252 FObj.Y := Y-FObj.Rect.Y;
1253 end;
1255 FDirection := Direction;
1256 FStartDirection := Direction;
1257 FStartX := GameX;
1258 FStartY := GameY;
1259 end;
1261 mon.positionChanged();
1263 result := mon;
1264 end;
1266 procedure g_Monsters_killedp();
1267 var
1268 a, h: Integer;
1269 begin
1270 if gMonsters = nil then
1271 Exit;
1273 // Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
1274 h := High(gMonsters);
1275 for a := 0 to h do
1276 begin
1277 if (gMonsters[a] <> nil) then
1278 begin
1279 with gMonsters[a] do
1280 begin
1281 if (FMonsterType = MONSTER_MAN) and
1282 (FState <> MONSTATE_DEAD) and
1283 (FState <> MONSTATE_SLEEP) and
1284 (FState <> MONSTATE_DIE) then
1285 begin
1286 g_Sound_PlayExAt('SOUND_MONSTER_TRUP', FObj.X, FObj.Y);
1287 Exit;
1288 end;
1289 end;
1290 end;
1291 end;
1292 end;
1294 procedure g_Monsters_Update();
1295 var
1296 a: Integer;
1297 begin
1298 // Öåëåóêàçàòåëü
1299 if gTime mod (GAME_TICK*2) = 0 then
1300 begin
1301 pt_x := pt_x+pt_xs;
1302 pt_y := pt_y+pt_ys;
1303 if abs(pt_x) > 246 then pt_xs := -pt_xs;
1304 if abs(pt_y) > 100 then pt_ys := -pt_ys;
1305 end;
1307 gMon := True; // Äëÿ ðàáîòû BlockMon'à
1309 if gmon_debug_think or gmon_debug_one_think_step then
1310 begin
1311 gmon_debug_one_think_step := false;
1312 for a := 0 to High(gMonsters) do
1313 begin
1314 if (gMonsters[a] = nil) then continue;
1315 if not gMonsters[a].FRemoved then
1316 begin
1317 if g_Game_IsClient then
1318 gMonsters[a].ClientUpdate()
1319 else
1320 gMonsters[a].Update();
1321 end
1322 else
1323 begin
1324 gMonsters[a].Free();
1325 gMonsters[a] := nil;
1326 end;
1327 end;
1328 end;
1330 gMon := False;
1331 end;
1333 procedure g_Monsters_Draw();
1334 var
1335 a: Integer;
1336 begin
1337 if gMonsters <> nil then
1338 begin
1339 for a := 0 to High(gMonsters) do
1340 begin
1341 if (gMonsters[a] <> nil) then gMonsters[a].Draw();
1342 end;
1343 end;
1344 end;
1346 procedure g_Monsters_DrawHealth();
1347 var
1348 a: Integer;
1349 fW, fH: Byte;
1350 begin
1351 if gMonsters = nil then Exit;
1352 e_TextureFontGetSize(gStdFont, fW, fH);
1354 for a := 0 to High(gMonsters) do
1355 begin
1356 if gMonsters[a] <> nil then
1357 begin
1358 e_TextureFontPrint(gMonsters[a].FObj.X + gMonsters[a].FObj.Rect.X,
1359 gMonsters[a].FObj.Y + gMonsters[a].FObj.Rect.Y + gMonsters[a].FObj.Rect.Height - fH,
1360 IntToStr(gMonsters[a].FHealth), gStdFont);
1361 end;
1362 end;
1363 end;
1365 function g_Monsters_ByUID (UID: Word): TMonster;
1366 begin
1367 result := uidMap[UID];
1368 end;
1370 procedure g_Monsters_SaveState(var Mem: TBinMemoryWriter);
1371 var
1372 count, i: Integer;
1373 b: Byte;
1374 begin
1375 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ:
1376 count := 0;
1377 if (gMonsters <> nil) then
1378 begin
1379 for i := 0 to High(gMonsters) do
1380 begin
1381 if (gMonsters[i] <> nil) then
1382 begin
1383 if (gMonsters[i].FMonsterType <> MONSTER_NONE) then count += 1;
1384 end;
1385 end;
1386 end;
1388 Mem := TBinMemoryWriter.Create((count+1) * 350);
1390 // Ñîõðàíÿåì èíôîðìàöèþ öåëåóêàçàòåëÿ:
1391 Mem.WriteInt(pt_x);
1392 Mem.WriteInt(pt_xs);
1393 Mem.WriteInt(pt_y);
1394 Mem.WriteInt(pt_ys);
1396 // Êîëè÷åñòâî ìîíñòðîâ:
1397 Mem.WriteInt(count);
1399 if count = 0 then
1400 Exit;
1402 // Ñîõðàíÿåì ìîíñòðîâ:
1403 for i := 0 to High(gMonsters) do
1404 begin
1405 if (gMonsters[i] <> nil) then
1406 begin
1407 if (gMonsters[i].FMonsterType <> MONSTER_NONE) then
1408 begin
1409 // Òèï ìîíñòðà:
1410 b := gMonsters[i].MonsterType;
1411 Mem.WriteByte(b);
1412 // Ñîõðàíÿåì äàííûå ìîíñòðà:
1413 gMonsters[i].SaveState(Mem);
1414 end;
1415 end;
1416 end;
1417 end;
1419 procedure g_Monsters_LoadState(var Mem: TBinMemoryReader);
1420 var
1421 count, a: Integer;
1422 b: Byte;
1423 mon: TMonster;
1424 begin
1425 if Mem = nil then exit;
1427 g_Monsters_Free(false);
1429 // Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ
1430 Mem.ReadInt(pt_x);
1431 Mem.ReadInt(pt_xs);
1432 Mem.ReadInt(pt_y);
1433 Mem.ReadInt(pt_ys);
1435 // Êîëè÷åñòâî ìîíñòðîâ
1436 Mem.ReadInt(count);
1438 if count = 0 then exit;
1440 // Çàãðóæàåì ìîíñòðîâ
1441 for a := 0 to count-1 do
1442 begin
1443 // Òèï ìîíñòðà
1444 Mem.ReadByte(b);
1445 // Ñîçäàåì ìîíñòðà
1446 mon := g_Monsters_Create(b, 0, 0, D_LEFT);
1447 if mon = nil then raise EBinSizeError.Create('g_Monsters_LoadState: ID = -1 (Can''t create)');
1448 // Çàãðóæàåì äàííûå ìîíñòðà
1449 mon.LoadState(Mem);
1450 end;
1451 end;
1453 function g_Monsters_GetIDByName(name: String): Integer;
1454 var
1455 i: Integer;
1456 begin
1457 name := UpperCase(name);
1458 i := MONSTER_DEMON;
1459 while (i <= MONSTER_MAN) do
1460 begin
1461 if name = MONSTERTABLE[i].Name then
1462 begin
1463 Result := i;
1464 Exit;
1465 end;
1466 Inc(i);
1467 end;
1469 Result := -1;
1470 end;
1472 function g_Monsters_GetNameByID(MonsterType: Byte): String;
1473 begin
1474 if MonsterType in [MONSTER_DEMON..MONSTER_MAN] then
1475 Result := MONSTERTABLE[MonsterType].Name
1476 else
1477 Result := '?';
1478 end;
1480 function g_Monsters_GetKilledBy(MonsterType: Byte): String;
1481 begin
1482 if MonsterType in [MONSTER_DEMON..MONSTER_MAN] then
1483 Result := KilledByMonster[MonsterType]
1484 else
1485 Result := '?';
1486 end;
1488 { T M o n s t e r : }
1490 procedure TMonster.ActionSound();
1491 begin
1492 case FMonsterType of
1493 MONSTER_IMP:
1494 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ACTION', FObj.X, FObj.Y);
1495 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN,
1496 MONSTER_MANCUB:
1497 g_Sound_PlayExAt('SOUND_MONSTER_ACTION', FObj.X, FObj.Y);
1498 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1499 MONSTER_KNIGHT, MONSTER_PAIN, MONSTER_DEMON,
1500 MONSTER_SPIDER:
1501 g_Sound_PlayExAt('SOUND_MONSTER_ACTION2', FObj.X, FObj.Y);
1502 MONSTER_BSP:
1503 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ACTION', FObj.X, FObj.Y);
1504 MONSTER_VILE:
1505 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ACTION', FObj.X, FObj.Y);
1506 MONSTER_SKEL:
1507 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ACTION', FObj.X, FObj.Y);
1508 MONSTER_CYBER:
1510 MONSTER_MAN:
1511 g_Sound_PlayExAt('SOUND_MONSTER_HAHA', FObj.X, FObj.Y);
1512 end;
1513 end;
1515 procedure TMonster.PainSound();
1516 begin
1517 if FPainSound then
1518 Exit;
1520 FPainSound := True;
1521 FPainTicks := 20;
1523 case FMonsterType of
1524 MONSTER_IMP, MONSTER_ZOMBY, MONSTER_SERG,
1525 MONSTER_SKEL, MONSTER_CGUN:
1526 g_Sound_PlayExAt('SOUND_MONSTER_PAIN', FObj.X, FObj.Y);
1527 MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
1528 MONSTER_KNIGHT, MONSTER_DEMON, MONSTER_SPIDER,
1529 MONSTER_BSP, MONSTER_CYBER:
1530 g_Sound_PlayExAt('SOUND_MONSTER_PAIN2', FObj.X, FObj.Y);
1531 MONSTER_VILE:
1532 g_Sound_PlayExAt('SOUND_MONSTER_VILE_PAIN', FObj.X, FObj.Y);
1533 MONSTER_MANCUB:
1534 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_PAIN', FObj.X, FObj.Y);
1535 MONSTER_PAIN:
1536 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_PAIN', FObj.X, FObj.Y);
1537 MONSTER_MAN:
1538 g_Sound_PlayExAt('SOUND_MONSTER_MAN_PAIN', FObj.X, FObj.Y);
1539 end;
1540 end;
1542 procedure TMonster.DieSound();
1543 begin
1544 case FMonsterType of
1545 MONSTER_IMP:
1546 case Random(2) of
1547 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_1', FObj.X, FObj.Y);
1548 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_DIE_2', FObj.X, FObj.Y);
1549 end;
1550 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1551 case Random(3) of
1552 0: g_Sound_PlayExAt('SOUND_MONSTER_DIE_1', FObj.X, FObj.Y);
1553 1: g_Sound_PlayExAt('SOUND_MONSTER_DIE_2', FObj.X, FObj.Y);
1554 2: g_Sound_PlayExAt('SOUND_MONSTER_DIE_3', FObj.X, FObj.Y);
1555 end;
1556 MONSTER_DEMON:
1557 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_DIE', FObj.X, FObj.Y);
1558 MONSTER_BARREL:
1559 g_Sound_PlayExAt('SOUND_MONSTER_BARREL_DIE', FObj.X, FObj.Y);
1560 MONSTER_SOUL:
1561 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_DIE', FObj.X, FObj.Y);
1562 MONSTER_BSP:
1563 g_Sound_PlayExAt('SOUND_MONSTER_BSP_DIE', FObj.X, FObj.Y);
1564 MONSTER_VILE:
1565 g_Sound_PlayExAt('SOUND_MONSTER_VILE_DIE', FObj.X, FObj.Y);
1566 MONSTER_BARON:
1567 g_Sound_PlayExAt('SOUND_MONSTER_BARON_DIE', FObj.X, FObj.Y);
1568 MONSTER_CACO:
1569 g_Sound_PlayExAt('SOUND_MONSTER_CACO_DIE', FObj.X, FObj.Y);
1570 MONSTER_CYBER:
1571 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_DIE', FObj.X, FObj.Y);
1572 MONSTER_KNIGHT:
1573 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_DIE', FObj.X, FObj.Y);
1574 MONSTER_MANCUB:
1575 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_DIE', FObj.X, FObj.Y);
1576 MONSTER_PAIN:
1577 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_DIE', FObj.X, FObj.Y);
1578 MONSTER_SKEL:
1579 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_DIE', FObj.X, FObj.Y);
1580 MONSTER_SPIDER:
1581 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_DIE', FObj.X, FObj.Y);
1582 MONSTER_MAN:
1583 g_Sound_PlayExAt('SOUND_MONSTER_MAN_DIE', FObj.X, FObj.Y);
1584 end;
1585 end;
1587 procedure TMonster.WakeUpSound();
1588 begin
1589 case FMonsterType of
1590 MONSTER_IMP:
1591 case Random(2) of
1592 0: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_1', FObj.X, FObj.Y);
1593 1: g_Sound_PlayExAt('SOUND_MONSTER_IMP_ALERT_2', FObj.X, FObj.Y);
1594 end;
1595 MONSTER_ZOMBY, MONSTER_SERG, MONSTER_CGUN:
1596 case Random(3) of
1597 0: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_1', FObj.X, FObj.Y);
1598 1: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_2', FObj.X, FObj.Y);
1599 2: g_Sound_PlayExAt('SOUND_MONSTER_ALERT_3', FObj.X, FObj.Y);
1600 end;
1601 MONSTER_MAN:
1602 g_Sound_PlayExAt('SOUND_MONSTER_MAN_ALERT', FObj.X, FObj.Y);
1603 MONSTER_BSP:
1604 g_Sound_PlayExAt('SOUND_MONSTER_BSP_ALERT', FObj.X, FObj.Y);
1605 MONSTER_VILE:
1606 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ALERT', FObj.X, FObj.Y);
1607 MONSTER_BARON:
1608 g_Sound_PlayExAt('SOUND_MONSTER_BARON_ALERT', FObj.X, FObj.Y);
1609 MONSTER_CACO:
1610 g_Sound_PlayExAt('SOUND_MONSTER_CACO_ALERT', FObj.X, FObj.Y);
1611 MONSTER_CYBER:
1612 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_ALERT', FObj.X, FObj.Y);
1613 MONSTER_KNIGHT:
1614 g_Sound_PlayExAt('SOUND_MONSTER_KNIGHT_ALERT', FObj.X, FObj.Y);
1615 MONSTER_MANCUB:
1616 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ALERT', FObj.X, FObj.Y);
1617 MONSTER_PAIN:
1618 g_Sound_PlayExAt('SOUND_MONSTER_PAIN_ALERT', FObj.X, FObj.Y);
1619 MONSTER_DEMON:
1620 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ALERT', FObj.X, FObj.Y);
1621 MONSTER_SKEL:
1622 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ALERT', FObj.X, FObj.Y);
1623 MONSTER_SPIDER:
1624 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_ALERT', FObj.X, FObj.Y);
1625 MONSTER_SOUL:
1627 end;
1628 end;
1630 procedure TMonster.BFGHit();
1631 begin
1632 if FMonsterType = MONSTER_FISH then
1633 Exit;
1635 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1636 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1637 {if g_Game_IsServer and g_Game_IsNet then
1638 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1639 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1640 0, NET_GFX_BFG);}
1641 end;
1643 function TMonster.Collide(X, Y: Integer; Width, Height: Word): Boolean;
1644 begin
1645 Result := g_Collide(FObj.X+FObj.Rect.X,
1646 FObj.Y+FObj.Rect.Y,
1647 FObj.Rect.Width,
1648 FObj.Rect.Height,
1649 X, Y,
1650 Width, Height);
1651 end;
1653 function TMonster.Collide(Panel: TPanel): Boolean;
1654 begin
1655 Result := g_Collide(FObj.X+FObj.Rect.X,
1656 FObj.Y+FObj.Rect.Y,
1657 FObj.Rect.Width,
1658 FObj.Rect.Height,
1659 Panel.X, Panel.Y,
1660 Panel.Width, Panel.Height);
1661 end;
1663 function TMonster.Collide(X, Y: Integer): Boolean;
1664 begin
1665 X := X - FObj.X - FObj.Rect.X;
1666 Y := Y - FObj.Y - FObj.Rect.Y;
1667 Result := (x >= 0) and (x <= FObj.Rect.Width) and
1668 (y >= 0) and (y <= FObj.Rect.Height);
1669 end;
1671 procedure TMonster.Respawn;
1672 begin
1673 FObj.Vel.X := 0;
1674 FObj.Vel.Y := 0;
1675 FObj.Accel.X := 0;
1676 FObj.Accel.Y := 0;
1677 FDirection := FStartDirection;
1678 GameX := FStartX;
1679 GameY := FStartY;
1680 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
1681 FHealth := MONSTERTABLE[FMonsterType].Health;
1682 FAmmo := 0;
1683 FPain := 0;
1684 FTargetUID := 0;
1685 FTargetTime := 0;
1686 FDieTriggers := nil;
1687 FWaitAttackAnim := False;
1688 FChainFire := False;
1689 FShellTimer := -1;
1691 FState := MONSTATE_SLEEP;
1692 FCurAnim := ANIM_SLEEP;
1694 positionChanged(); // this updates spatial accelerators
1696 if g_Game_IsNet and g_Game_IsServer then
1697 begin
1698 MH_SEND_MonsterPos(FUID);
1699 MH_SEND_MonsterState(FUID);
1700 end;
1701 end;
1703 constructor TMonster.Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
1704 var
1705 a: Integer;
1706 FramesID: DWORD = 0;
1707 s: String;
1708 res: Boolean;
1709 begin
1710 if ForcedUID < 0 then
1711 FUID := g_CreateUID(UID_MONSTER)
1712 else
1713 FUID := ForcedUID;
1715 FMonsterType := MonsterType;
1717 g_Obj_Init(@FObj);
1719 FState := MONSTATE_SLEEP;
1720 FCurAnim := ANIM_SLEEP;
1721 FHealth := MONSTERTABLE[MonsterType].Health;
1722 FMaxHealth := FHealth;
1723 FObj.Rect := MONSTERTABLE[MonsterType].Rect;
1724 FDieTriggers := nil;
1725 FSpawnTrigger := -1;
1726 FWaitAttackAnim := False;
1727 FChainFire := False;
1728 FStartID := aID;
1729 FNoRespawn := False;
1730 FShellTimer := -1;
1731 FBehaviour := BH_NORMAL;
1732 FFireTime := 0;
1733 FFirePainTime := 0;
1734 FFireAttacker := 0;
1736 mProxyId := -1;
1737 mArrIdx := -1;
1738 trapCheckFrameId := 0;
1740 if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
1741 FBloodKind := BLOOD_SPARKS
1742 else
1743 FBloodKind := BLOOD_NORMAL;
1744 if FMonsterType = MONSTER_CACO then
1745 begin
1746 FBloodRed := 0;
1747 FBloodGreen := 0;
1748 FBloodBlue := 150;
1749 end
1750 else if FMonsterType in [MONSTER_BARON, MONSTER_KNIGHT] then
1751 begin
1752 FBloodRed := 0;
1753 FBloodGreen := 150;
1754 FBloodBlue := 0;
1755 end
1756 else
1757 begin
1758 FBloodRed := 150;
1759 FBloodGreen := 0;
1760 FBloodBlue := 0;
1761 end;
1763 SetLength(FAnim, Length(ANIMTABLE));
1765 for a := 0 to High(FAnim) do
1766 begin
1767 FAnim[a, D_LEFT] := nil;
1768 FAnim[a, D_RIGHT] := nil;
1769 end;
1771 for a := ANIM_SLEEP to ANIM_PAIN do
1772 if (ANIMTABLE[a].name <> '') and
1773 (MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a] <> 0) then
1774 begin
1775 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1776 '_'+ANIMTABLE[a].name;
1778 res := g_Frames_Exists(s);
1780 if res then
1781 res := g_Frames_Get(FramesID, s);
1783 // Åñëè íåò òàêîé àíèìàöèè, òî ïðîáóåì çàìåíèòü åå íà àíèìàöèþ ñìåðòè:
1784 if (not res) then
1785 begin
1786 // Çàìåíÿåì òîëüêî ANIM_MESS íà ANIM_DIE:
1787 if a <> ANIM_MESS then
1788 Continue;
1790 if g_Frames_Get(FramesID, 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1791 '_'+ANIMTABLE[ANIM_DIE].name) then
1792 begin
1793 FAnim[a, D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1794 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1795 FAnim[a, D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
1796 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
1797 Continue;
1798 end;
1799 end;
1801 FAnim[a, D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1802 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1804 // Åñëè åñòü îòäåëüíàÿ ëåâàÿ àíèìàöèÿ - çàãðóæàåì:
1805 if MONSTER_ANIMTABLE[MonsterType].LeftAnim then
1806 begin
1807 s := 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
1808 '_'+ANIMTABLE[a].name+'_L';
1809 if g_Frames_Exists(s) then
1810 g_Frames_Get(FramesID, s);
1811 end;
1813 FAnim[a, D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
1814 MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
1815 end;
1817 // Äëÿ êîëäóíà çàãðóæàåì òàêæå àíèìàöèþ îãíÿ:
1818 if MonsterType = MONSTER_VILE then
1819 begin
1820 g_Frames_Get(FramesID, 'FRAMES_FIRE');
1821 vilefire := TAnimation.Create(FramesID, True, 2);
1822 end
1823 else
1824 vilefire := nil;
1825 end;
1827 function TMonster.Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
1828 var
1829 c, it: Integer;
1830 p: TPlayer;
1831 begin
1832 Result := False;
1834 // Óìèðàåò, óìåð èëè âîñêðåøàåòñÿ => óðîí äåëàòü íåêîìó:
1835 if (FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE) or (FState = MONSTATE_REVIVE) then
1836 Exit;
1838 // Ðûáó â âîäå áüåò òîêîì => ïàíèêà áåç óðîíà:
1839 if (t = HIT_ELECTRO) and (FMonsterType = MONSTER_FISH) and g_Game_IsServer then
1840 begin
1841 FSleep := 20;
1842 if Random(2) = 0 then
1843 FDirection := D_RIGHT
1844 else
1845 FDirection := D_LEFT;
1846 Result := True;
1847 SetState(MONSTATE_RUN);
1848 Exit;
1849 end;
1851 // Ëîâóøêà óáèâàåò ñðàçó:
1852 if t = HIT_TRAP then
1853 FHealth := -100;
1855 // Ðîáîòó óðîíà íåò:
1856 if FMonsterType = MONSTER_ROBO then
1857 aDamage := 0;
1859 // Íàíîñèì óðîí:
1860 if g_Game_IsServer then Dec(FHealth, aDamage);
1862 // Óñèëèâàåì áîëü ìîíñòðà îò óðîíà:
1863 if FPain = 0 then
1864 FPain := 3;
1865 FPain := FPain+aDamage;
1867 // Åñëè áîëü ñóùåñòâåííàÿ, òî ìåíÿåì ñîñòîÿíèå íà áîëåâîå:
1868 if FState <> MONSTATE_PAIN then
1869 if (FPain >= MONSTERTABLE[FMonsterType].MinPain) and
1870 (FMonsterType <> MONSTER_BARREL) then
1871 SetState(MONSTATE_PAIN);
1873 // Åñëè ðàçðåøåíà êðîâü - ñîçäàåì áðûçãè êðîâè:
1874 if (gBloodCount > 0) then
1875 begin
1876 c := Min(aDamage, 200);
1877 c := c*gBloodCount - (aDamage div 4) + Random(c div 2);
1879 if (VelX = 0) and (VelY = 0) then
1880 MakeBloodSimple(c)
1881 else
1882 case t of
1883 HIT_TRAP, HIT_ACID, HIT_ELECTRO, HIT_FLAME: MakeBloodSimple(c);
1884 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, VelX, VelY);
1885 end;
1886 end;
1888 // Òåïåðü öåëü - óäàðèâøèé, åñëè òîëüêî íå ñàì ñåáÿ:
1889 if (SpawnerUID <> FUID) and (BehaviourDamage(SpawnerUID, FBehaviour, FMonsterType)) then
1890 begin
1891 FTargetUID := SpawnerUID;
1892 FTargetTime := 0;
1893 end;
1895 // Çäîðîâüå çàêîí÷èëîñü:
1896 if FHealth <= 0 then
1897 begin
1898 // Åñëè ýòî íå áî÷êà è óáèë èãðîê, òî åìó +1:
1899 if (FMonsterType <> MONSTER_BARREL) then
1900 begin
1901 if (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1902 begin
1903 p := g_Player_Get(SpawnerUID);
1904 if (p <> nil) and (gLMSRespawn = LMS_RESPAWN_NONE) then
1905 begin
1906 p.MonsterKills := p.MonsterKills+1;
1907 if gGameSettings.GameMode = GM_COOP then
1908 p.Frags := p.Frags + 1;
1909 // Uncomment this if you want to double-kill monsters
1910 //p.FragCombo();
1911 end;
1912 end;
1913 if gLMSRespawn = LMS_RESPAWN_NONE then
1914 begin
1915 Inc(gCoopMonstersKilled);
1916 if g_Game_IsNet then
1917 MH_SEND_GameStats;
1918 end;
1919 end;
1921 // Âûáèðàåì ëóò:
1922 case FMonsterType of
1923 MONSTER_ZOMBY: c := ITEM_AMMO_BULLETS;
1924 MONSTER_SERG: c := ITEM_WEAPON_SHOTGUN1;
1925 MONSTER_CGUN: c := ITEM_WEAPON_CHAINGUN;
1926 MONSTER_MAN: c := ITEM_KEY_RED;
1927 else c := 0;
1928 end;
1930 // Áðîñàåì ëóò:
1931 if c <> 0 then
1932 begin
1933 it := g_Items_Create(FObj.X + (FObj.Rect.Width div 2),
1934 FObj.Y + (FObj.Rect.Height div 2),
1935 c, True, False);
1936 g_Obj_Push(g_Items_ObjByIdx(it), (FObj.Vel.X div 2)-3+Random(7),
1937 (FObj.Vel.Y div 2)-Random(4));
1938 positionChanged(); // this updates spatial accelerators
1939 if g_Game_IsServer and g_Game_IsNet then
1940 MH_SEND_ItemSpawn(True, it);
1941 end;
1943 // Òðóï äàëüøå íå èäåò:
1944 FObj.Vel.X := 0;
1946 // Ó òðóïà ðàçìåðû ìåíüøå:
1947 if (FMonsterType <> MONSTER_FISH) and (FMonsterType <> MONSTER_PAIN) then
1948 begin
1949 FObj.Rect.Y := FObj.Rect.Y + FObj.Rect.Height-12;
1950 FObj.Rect.Height := 12;
1951 positionChanged();
1952 end;
1954 // Óðîí áûë ñèëüíûì => ñëàáûå - â êàøó:
1955 if (FHealth <= -30) and
1956 ((FMonsterType = MONSTER_IMP) or (FMonsterType = MONSTER_ZOMBY) or
1957 (FMonsterType = MONSTER_SERG) or (FMonsterType = MONSTER_CGUN) or
1958 (FMonsterType = MONSTER_MAN)) then
1959 begin
1960 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
1961 SetState(MONSTATE_DIE, ANIM_MESS);
1962 end
1963 else
1964 begin
1965 DieSound();
1966 SetState(MONSTATE_DIE);
1967 end;
1969 // Àêòèâèðîâàòü òðèããåðû, æäóùèå ñìåðòè ýòîãî ìîíñòðà:
1970 if g_Game_IsServer then ActivateTriggers();
1972 FHealth := 0;
1973 end
1974 else
1975 if FState = MONSTATE_SLEEP then
1976 begin // Ñïàë, ðàçáóäèëè íåñìåðòåëüíûì óäàðîì:
1977 FPain := MONSTERTABLE[FMonsterType].Pain;
1978 SetState(MONSTATE_GO);
1979 end;
1981 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
1982 Result := True;
1983 end;
1985 function TMonster.Heal(Value: Word): Boolean;
1986 begin
1987 Result := False;
1988 if g_Game_IsClient then
1989 Exit;
1990 if not Live then
1991 Exit;
1993 if FHealth < FMaxHealth then
1994 begin
1995 IncMax(FHealth, Value, FMaxHealth);
1996 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
1997 Result := True;
1998 end;
1999 end;
2001 destructor TMonster.Destroy();
2002 var
2003 a: Integer;
2004 begin
2005 for a := 0 to High(FAnim) do
2006 begin
2007 FAnim[a, D_LEFT].Free();
2008 FAnim[a, D_RIGHT].Free();
2009 end;
2011 vilefire.Free();
2013 if (mProxyId <> -1) then
2014 begin
2015 if (monsGrid <> nil) then
2016 begin
2017 monsGrid.removeBody(mProxyId);
2018 {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
2019 e_WriteLog(Format('monster #%d:(%u): removed from grid; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
2020 {$ENDIF}
2021 end;
2022 mProxyId := -1;
2023 end;
2025 if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then
2026 begin
2027 freeInds.release(mArrIdx);
2028 gMonsters[mArrIdx] := nil;
2029 end;
2030 mArrIdx := -1;
2032 uidMap[FUID] := nil;
2034 inherited Destroy();
2035 end;
2037 procedure TMonster.Draw();
2038 var
2039 m: TMirrorType;
2040 dx, dy, c: Integer;
2041 o: TObj;
2042 begin
2043 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, 'TYPE: '+IntToStr(FMonsterType));
2044 //e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y+16, 'STATE: '+IntToStr(FState));
2046 // Åñëè êîëäóí ñòðåëÿåò, òî ðèñóåì îãîíü:
2047 if FMonsterType = MONSTER_VILE then
2048 if FState = MONSTATE_SHOOT then
2049 if GetPos(FTargetUID, @o) then
2050 vilefire.Draw(o.X+o.Rect.X+(o.Rect.Width div 2)-32,
2051 o.Y+o.Rect.Y+o.Rect.Height-128, M_NONE);
2053 // Íå â îáëàñòè ðèñîâàíèÿ íå ðåñóåì:
2054 if not g_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height,
2055 sX-128, sY-128, sWidth+256, sHeight+256) then
2056 Exit;
2058 // Ýòè ìîíñòðû, óìèðàÿ, íå îñòàâëÿþò òðóïîâ:
2059 if FState = MONSTATE_DEAD then
2060 case FMonsterType of
2061 MONSTER_BARREL, MONSTER_SOUL, MONSTER_PAIN: Exit;
2062 end;
2064 // Åñòü ÷òî ðèñîâàòü ïðè òåêóùåì ïîâåäåíèè:
2065 if FAnim[FCurAnim, FDirection] <> nil then
2066 begin
2067 // Åñëè íåò ëåâîé àíèìàöèè èëè îíà ñîâïàäàåò ñ ïðàâîé => îòðàæàåì ïðàâóþ:
2068 if (FDirection = D_LEFT) and
2069 ((not MONSTER_ANIMTABLE[FMonsterType].LeftAnim) or
2070 (FAnim[FCurAnim, D_LEFT].FramesID = FAnim[FCurAnim, D_RIGHT].FramesID)) and
2071 (FMonsterType <> MONSTER_BARREL) then
2072 m := M_HORIZONTAL
2073 else
2074 m := M_NONE;
2076 // Ëåâàÿ àíèìàöèÿ => ìåíÿåì ñìåùåíèå îòíîñèòåëüíî öåíòðà:
2077 if (FDirection = D_LEFT) and
2078 (FMonsterType <> MONSTER_BARREL) then
2079 begin
2080 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].X;
2081 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].Y;
2083 if m = M_HORIZONTAL then
2084 begin // Íåò îòäåëüíîé ëåâîé àíèìàöèè
2085 // Ðàññòîÿíèå îò êðàÿ òåêñòóðû äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2086 c := (MONSTERTABLE[FMonsterType].Rect.X - dx) + MONSTERTABLE[FMonsterType].Rect.Width;
2087 // Ðàññòîÿíèå îò êðàÿ õèò áîêñà äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
2088 dx := FAnim[FCurAnim, FDirection].Width - c - MONSTERTABLE[FMonsterType].Rect.X;
2089 // Ò.ê. äâèãàòü òåêñòóðó íóæíî áóäåò â ïðîòèâîïîëîæíîì íàïðàâëåíèè:
2090 dx := -dx;
2091 // Ýòî çíà÷èò: dX := -frameWidth - animDeltaX + hitX + hitWidth + hitX
2092 end;
2093 end
2094 else // Ïðàâàÿ àíèìàöèÿ
2095 begin
2096 dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].X;
2097 dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaRight[FCurAnim].Y;
2098 end;
2100 // Ðèñóåì:
2101 FAnim[FCurAnim, FDirection].Draw(Obj.X+dx, Obj.Y+dy, m);
2102 end;
2104 if g_debug_Frames then
2105 begin
2106 e_DrawQuad(FObj.X+FObj.Rect.X,
2107 FObj.Y+FObj.Rect.Y,
2108 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2109 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2110 0, 255, 0);
2111 end;
2112 end;
2114 procedure TMonster.MakeBloodSimple(Count: Word);
2115 begin
2116 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)+8,
2117 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2118 Count div 2, 3, -1, 16, (FObj.Rect.Height*2 div 3),
2119 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2120 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-8,
2121 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2122 Count div 2, -3, -1, 16, (FObj.Rect.Height*2) div 3,
2123 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2124 end;
2126 procedure TMonster.MakeBloodVector(Count: Word; VelX, VelY: Integer);
2127 begin
2128 g_GFX_Blood(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2129 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2130 Count, VelX, VelY, 16, (FObj.Rect.Height*2) div 3,
2131 FBloodRed, FBloodGreen, FBloodBlue, FBloodKind);
2132 end;
2134 procedure TMonster.Push(vx, vy: Integer);
2135 begin
2136 FObj.Accel.X := FObj.Accel.X + vx;
2137 FObj.Accel.Y := FObj.Accel.Y + vy;
2138 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2139 end;
2141 procedure TMonster.SetState(State: Byte; ForceAnim: Byte = 255);
2142 var
2143 Anim: Byte;
2144 begin
2145 // Åñëè ñîñòîÿíèå = íà÷àëè óìèðàòü, à ýòîò ìîíñòð = Lost_Soul,
2146 // òî ñîáëþäàåì îãðàíè÷åíèå êîëè÷åñòâà Lost_Soul'îâ:
2147 if (State = MONSTATE_DIE) and (MonsterType = MONSTER_SOUL) then
2148 soulcount := soulcount-1;
2150 // Ïðèñìåðòè - íåëüçÿ ñðàçó íà÷èíàòü àòàêîâàòü èëè áåãàòü:
2151 case FState of
2152 MONSTATE_DIE, MONSTATE_DEAD, MONSTATE_REVIVE:
2153 if (State <> MONSTATE_DEAD) and (State <> MONSTATE_REVIVE) and
2154 (State <> MONSTATE_GO) then
2155 Exit;
2156 end;
2158 // Ñìåíà ñîñòîÿíèÿ:
2159 FState := State;
2161 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID, ForceAnim);
2163 // Íîâàÿ àíèìàöèÿ ïðè íîâîì ñîñòîÿíèè:
2164 case FState of
2165 MONSTATE_SLEEP: Anim := ANIM_SLEEP;
2166 MONSTATE_PAIN: Anim := ANIM_PAIN;
2167 MONSTATE_WAIT: Anim := ANIM_SLEEP;
2168 MONSTATE_CLIMB, MONSTATE_RUN, MONSTATE_RUNOUT, MONSTATE_GO: Anim := ANIM_GO;
2169 MONSTATE_SHOOT: Anim := ANIM_ATTACK;
2170 MONSTATE_ATTACK: Anim := ANIM_ATTACK;
2171 MONSTATE_DIE: Anim := ANIM_DIE;
2172 MONSTATE_REVIVE:
2173 begin // íà÷àëè âîñðåøàòüñÿ
2174 Anim := FCurAnim;
2175 FAnim[Anim, FDirection].Revert(True);
2177 FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
2178 FHealth := MONSTERTABLE[FMonsterType].Health;
2179 FAmmo := 0;
2180 FPain := 0;
2181 end;
2182 else Exit;
2183 end;
2185 // Íàäî ñìåíèòü àíèìàöèþ íà íåñòàíäàðòíóþ:
2186 if ForceAnim <> 255 then
2187 Anim := ForceAnim;
2189 // Åñëè àíèìàöèÿ íîâàÿ - ïåðåçàïóñêàåì å¸:
2190 if FCurAnim <> Anim then
2191 if FAnim[Anim, FDirection] <> nil then
2192 begin
2193 FAnim[Anim, FDirection].Reset();
2194 FCurAnim := Anim;
2195 end;
2196 end;
2198 function TMonster.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
2199 var
2200 TA: TAnimation;
2201 FramesID: DWORD;
2202 begin
2203 Result := False;
2205 //  òî÷êå íàçíà÷åíèÿ ñòåíà:
2206 if g_CollideLevel(X, Y, FObj.Rect.Width, FObj.Rect.Height) then
2207 begin
2208 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
2209 if g_Game_IsServer and g_Game_IsNet then
2210 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
2211 Exit;
2212 end;
2214 TA := nil;
2216 // Ýôôåêò òåëåïîðòà â ïîçèöèè ìîíñòðà:
2217 if not silent then
2218 begin
2219 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
2220 TA := TAnimation.Create(FramesID, False, 6);
2221 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', Obj.X, Obj.Y);
2222 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2223 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2225 if g_Game_IsServer and g_Game_IsNet then
2226 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2227 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 1,
2228 NET_GFX_TELE);
2229 end;
2231 FObj.X := X - FObj.Rect.X;
2232 FObj.Y := Y - FObj.Rect.Y;
2233 positionChanged();
2235 if dir = 1 then
2236 FDirection := D_LEFT
2237 else
2238 if dir = 2 then
2239 FDirection := D_RIGHT
2240 else
2241 if dir = 3 then
2242 begin // îáðàòíîå
2243 if FDirection = D_RIGHT then
2244 FDirection := D_LEFT
2245 else
2246 FDirection := D_RIGHT;
2247 end;
2249 // Ýôôåêò òåëåïîðòà â òî÷êå íàçíà÷åíèÿ:
2250 if not silent and (TA <> nil) then
2251 begin
2252 g_GFX_OnceAnim(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2253 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, TA);
2254 TA.Free();
2256 if g_Game_IsServer and g_Game_IsNet then
2257 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-32,
2258 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-32, 0,
2259 NET_GFX_TELE);
2260 end;
2262 if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
2263 Result := True;
2264 end;
2266 procedure TMonster.Update();
2267 var
2268 a, b, sx, sy, wx, wy, oldvelx: Integer;
2269 st: Word;
2270 o, co: TObj;
2271 fall: Boolean;
2272 mon: TMonster;
2273 label
2274 _end;
2275 begin
2276 fall := True;
2278 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
2279 if FMonsterType = MONSTER_FISH then
2280 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
2281 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2282 fall := False;
2284 // Ëåòàþùèå ìîíòñðû:
2285 if ((FMonsterType = MONSTER_SOUL) or
2286 (FMonsterType = MONSTER_PAIN) or
2287 (FMonsterType = MONSTER_CACO)) and
2288 (FState <> MONSTATE_DIE) and
2289 (FState <> MONSTATE_DEAD) then
2290 fall := False;
2292 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
2293 if gTime mod (GAME_TICK*2) <> 0 then
2294 begin
2295 g_Obj_Move(@FObj, fall, True, True);
2296 positionChanged(); // this updates spatial accelerators
2297 Exit;
2298 end;
2300 if FPainTicks > 0 then
2301 Dec(FPainTicks)
2302 else
2303 FPainSound := False;
2305 // Äâèãàåìñÿ:
2306 st := g_Obj_Move(@FObj, fall, True, True);
2307 positionChanged(); // this updates spatial accelerators
2309 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
2310 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
2311 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
2312 begin
2313 FRemoved := True;
2314 if Live and (gLMSRespawn = LMS_RESPAWN_NONE) then
2315 begin
2316 Inc(gCoopMonstersKilled);
2317 if g_Game_IsNet then
2318 MH_SEND_GameStats;
2319 end;
2320 ActivateTriggers();
2321 Exit;
2322 end;
2324 oldvelx := FObj.Vel.X;
2326 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
2327 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
2328 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
2330 if FFireTime > 0 then
2331 begin
2332 if WordBool(st and MOVE_INWATER) then
2333 FFireTime := 0
2334 else
2335 begin
2336 OnFireFlame(1);
2337 FFireTime := FFireTime - 1;
2338 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
2339 if FFirePainTime = 0 then
2340 begin
2341 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
2342 FFirePainTime := 18;
2343 end
2344 else
2345 FFirePainTime := FFirePainTime - 1;
2346 end;
2347 end;
2349 // Ìåðòâûé íè÷åãî íå äåëàåò:
2350 if (FState = MONSTATE_DEAD) then
2351 goto _end;
2353 // AI ìîíñòðîâ âûêëþ÷åí:
2354 if g_debug_MonsterOff then
2355 begin
2356 FSleep := 1;
2357 if FState <> MONSTATE_SLEEP then
2358 SetState(MONSTATE_SLEEP);
2359 end;
2361 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
2362 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
2363 case FMonsterType of
2364 MONSTER_FISH:
2365 if Random(4) = 0 then
2366 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2367 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2368 MONSTER_ROBO, MONSTER_BARREL:
2369 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
2370 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
2371 else begin
2372 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
2373 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
2374 if Random(2) = 0 then
2375 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
2376 else
2377 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
2378 end;
2379 end;
2381 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
2382 if FMonsterType = MONSTER_BARREL then
2383 begin
2384 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
2385 (FAnim[FCurAnim, FDirection].Counter = 0) then
2386 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2387 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
2388 60, FUID);
2389 end;
2391 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
2392 if FMonsterType = MONSTER_SOUL then
2393 if WordBool(st and MOVE_HITAIR) then
2394 g_Obj_SetSpeed(@FObj, 16);
2396 if FAmmo < 0 then
2397 FAmmo := FAmmo + 1;
2399 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
2400 if FObj.Vel.Y < 0 then
2401 if WordBool(st and MOVE_INWATER) then
2402 FObj.Vel.Y := -4;
2404 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
2405 FTargetTime := FTargetTime + 1;
2407 // Ãèëüçû
2408 if FShellTimer > -1 then
2409 if FShellTimer = 0 then
2410 begin
2411 if FShellType = SHELL_SHELL then
2412 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2413 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2414 GameVelX, GameVelY-2, SHELL_SHELL)
2415 else if FShellType = SHELL_DBLSHELL then
2416 begin
2417 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2418 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2419 GameVelX-1, GameVelY-2, SHELL_SHELL);
2420 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2421 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2422 GameVelX+1, GameVelY-2, SHELL_SHELL);
2423 end;
2424 FShellTimer := -1;
2425 end else Dec(FShellTimer);
2427 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
2428 if fall then
2429 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
2430 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
2431 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2432 FObj.Rect.Width, FObj.Rect.Height, 50) then
2433 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2434 (FObj.Accel.Y = 0) then
2435 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2437 case FState of
2438 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
2439 begin
2440 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
2441 if FPain >= MONSTERTABLE[FMonsterType].Pain then
2442 begin
2443 FPain := MONSTERTABLE[FMonsterType].Pain;
2444 if gSoundEffectsDF then PainSound();
2445 end;
2446 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
2447 PainSound();
2449 // Ñíèæàåì áîëü ñî âðåìåíåì:
2450 FPain := FPain - 5;
2452 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
2453 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
2454 begin
2455 FPain := 0;
2456 FAmmo := -9;
2457 SetState(MONSTATE_GO);
2458 end;
2459 end;
2461 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
2462 begin
2463 // Ñïèì:
2464 FSleep := FSleep + 1;
2466 // Ïðîñïàëè äîñòàòî÷íî:
2467 if FSleep >= 18 then
2468 FSleep := 0
2469 else // åùå ñïèì
2470 goto _end;
2472 // Íà èãðîêîâ èäóò òîëüêî îáû÷íûå ìîíñòðû, êèëëåðû è ìàíüÿêè
2473 if (FBehaviour = BH_NORMAL) or (FBehaviour = BH_KILLER) or (FBehaviour = BH_MANIAC) then
2474 // Åñëè åñòü èãðîê ðÿäîì, ïðîñûïàåìñÿ è èäåì ê íåìó:
2475 if (gPlayers <> nil) then
2476 for a := 0 to High(gPlayers) do
2477 if (gPlayers[a] <> nil) and (gPlayers[a].Live)
2478 and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
2479 with gPlayers[a] do
2480 if g_Look(@FObj, @Obj, FDirection) then
2481 begin
2482 FTargetUID := gPlayers[a].UID;
2483 FTargetTime := 0;
2484 WakeUpSound();
2485 SetState(MONSTATE_GO);
2486 Break;
2487 end;
2489 // Íà ìîíñòðîâ òÿíåò ìàíüÿêîâ, ïîåõàâøèõ è êàííèáàëîâ
2490 if (FTargetUID = 0) and ((FBehaviour = BH_MANIAC)
2491 or (FBehaviour = BH_INSANE) or (FBehaviour = BH_CANNIBAL)) then
2492 // Åñëè åñòü ïîäõîäÿùèé ìîíñòð ðÿäîì:
2493 if gMonsters <> nil then
2494 for a := 0 to High(gMonsters) do
2495 if (gMonsters[a] <> nil) and (gMonsters[a].Live) and
2496 (gMonsters[a].FUID <> FUID) then
2497 begin
2498 // Ìàíüÿêè íàïàäàþò íà âñåõ ìîíñòðîâ, êðîìå äðóçåé
2499 if (FBehaviour = BH_MANIAC) and
2500 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2501 Continue;
2502 // Ïîåõàâøèå òàêæå, íî ìîãóò îáîçëèòüñÿ íà áî÷êó
2503 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL) and
2504 (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
2505 Continue;
2506 // Êàííèáàëû íàïàäàþò íà ñåáå ïîäîáíûõ
2507 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
2508 Continue;
2509 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
2510 begin
2511 FTargetUID := gMonsters[a].UID;
2512 FTargetTime := 0;
2513 WakeUpSound();
2514 SetState(MONSTATE_GO);
2515 Break;
2516 end;
2517 end;
2518 end;
2520 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
2521 begin
2522 // Æäåì:
2523 FSleep := FSleep - 1;
2525 // Âûæäàëè äîñòàòî÷íî - èäåì:
2526 if FSleep < 0 then
2527 SetState(MONSTATE_GO);
2528 end;
2530 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
2531 begin
2532 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2533 if WordBool(st and MOVE_BLOCK) then
2534 begin
2535 Turn();
2536 FSleep := 40;
2537 SetState(MONSTATE_RUNOUT);
2539 goto _end;
2540 end;
2542 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
2543 if (FMonsterType = MONSTER_VILE) then
2544 if isCorpse(@FObj, False) <> -1 then
2545 begin
2546 FObj.Vel.X := 0;
2547 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
2549 goto _end;
2550 end;
2552 // Öåëü ïîãèáëà èëè äàâíî æäåì:
2553 if (not GetPos(FTargetUID, @o)) or (FTargetTime > MAX_ATM) then
2554 if not findNewPrey() then
2555 begin // Íîâûõ öåëåé íåò
2556 FTargetUID := 0;
2557 o.X := FObj.X+pt_x;
2558 o.Y := FObj.Y+pt_y;
2559 o.Vel.X := 0;
2560 o.Vel.Y := 0;
2561 o.Accel.X := 0;
2562 o.Accel.Y := 0;
2563 o.Rect := _Rect(0, 0, 0, 1);
2564 end
2565 else // Íîâàÿ öåëü åñòü - áåðåì åå êîîðäèíàòû
2566 GetPos(FTargetUID, @o);
2568 // Öåëü î÷åíü áëèçêî - ïèíàåì:
2569 if g_Obj_Collide(@FObj, @o) and (FTargetUID <> 0) then
2570 begin
2571 FTargetTime := 0;
2572 if (FMonsterType <> MONSTER_CYBER) or (Random(2) = 0) then
2573 begin
2574 if kick(@o) then
2575 goto _end;
2576 end;
2577 end;
2579 // Ðàññòîÿíèå äî öåëè:
2580 sx := o.X+o.Rect.X+(o.Rect.Width div 2)-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
2581 sy := o.Y+o.Rect.Y+(o.Rect.Height div 2)-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
2583 // Ïîâîðà÷èâàåìñÿ â ñòîðîíó öåëè:
2584 if sx > 0 then
2585 FDirection := D_RIGHT
2586 else
2587 FDirection := D_LEFT;
2589 // Åñëè ìîíñòð óìååò ñòðåëÿòü è åñòü ïî êîìó - ñòðåëÿåì:
2590 if canShoot(FMonsterType) and (FTargetUID <> 0) then
2591 if Abs(sx) > Abs(sy) then // óãîë âûñòðåëà óäîáíûé
2592 if shoot(@o, False) then
2593 goto _end;
2595 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
2596 if Abs(sx) < 40 then
2597 if FMonsterType <> MONSTER_FISH then
2598 begin
2599 FSleep := 15;
2600 SetState(MONSTATE_RUN);
2601 if Random(2) = 0 then
2602 FDirection := D_LEFT
2603 else
2604 FDirection := D_RIGHT;
2606 goto _end;
2607 end;
2609 // Óïåðëèñü â ñòåíó:
2610 if WordBool(st and MOVE_HITWALL) then
2611 begin
2612 if g_Triggers_PressR(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width,
2613 FObj.Rect.Height, FUID, ACTIVATE_MONSTERPRESS) <> nil then
2614 begin // Ñìîãëè íàæàòü êíîïêó - íåáîëüøîå îæèäàíèå
2615 FSleep := 4;
2616 SetState(MONSTATE_WAIT);
2618 goto _end;
2619 end;
2621 case FMonsterType of
2622 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
2623 else // Íå ëåòàþò:
2624 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
2625 (FObj.Accel.Y = 0) then
2626 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
2627 // Ïðûæîê ÷åðåç ñòåíó:
2628 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2629 SetState(MONSTATE_CLIMB);
2630 end;
2631 end;
2633 goto _end;
2634 end;
2636 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
2637 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
2638 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
2639 begin
2640 if FMonsterType = MONSTER_FISH then
2641 begin // Ðûáà
2642 if not WordBool(st and MOVE_INWATER) then
2643 begin // Ðûáà âíå âîäû:
2644 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2645 begin // "Ñòîèò" òâåðäî
2646 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
2647 if FObj.Accel.Y = 0 then FObj.Vel.Y := -6;
2648 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
2649 end;
2651 // Ðûáå áîëüíî:
2652 SetState(MONSTATE_PAIN);
2653 FPain := FPain + 50;
2654 end
2655 else // Ðûáà â âîäå
2656 begin
2657 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2658 if Abs(sy) > 8 then
2659 FObj.Vel.Y := g_basic.Sign(sy)*4
2660 else
2661 FObj.Vel.Y := 0;
2663 // Ðûáà ïëûâåò ââåðõ:
2664 if FObj.Vel.Y < 0 then
2665 if not g_Obj_CollideWater(@FObj, 0, -16) then
2666 begin
2667 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
2668 FObj.Vel.Y := 0;
2669 // Ïëàâàåì òóäà-ñþäà:
2670 if Random(2) = 0 then
2671 FDirection := D_LEFT
2672 else
2673 FDirection := D_RIGHT;
2674 FSleep := 20;
2675 SetState(MONSTATE_RUN);
2676 end;
2677 end;
2678 end
2679 else // Ëåòàþùèå ìîíñòðû
2680 begin
2681 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
2682 if Abs(sy) > 8 then
2683 FObj.Vel.Y := g_basic.Sign(sy)*4
2684 else
2685 FObj.Vel.Y := 0;
2686 end;
2687 end
2688 else // "Íàçåìíûå" ìîíñòðû
2689 begin
2690 // Âîçìîæíî, ïèíàåì êóñêè:
2691 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
2692 begin
2693 b := Abs(FObj.Vel.X);
2694 if b > 1 then b := b * (Random(8 div b) + 1);
2695 for a := 0 to High(gGibs) do
2696 begin
2697 if gGibs[a].Live and
2698 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2699 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
2700 begin
2701 // Ïèíàåì êóñêè
2702 if FObj.Vel.X < 0 then
2703 begin
2704 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
2705 end
2706 else
2707 begin
2708 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
2709 end;
2710 end;
2711 end;
2712 end;
2713 // Áîññû ìîãóò ïèíàòü òðóïû:
2714 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
2715 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
2716 begin
2717 b := Abs(FObj.Vel.X);
2718 if b > 1 then b := b * (Random(8 div b) + 1);
2719 for a := 0 to High(gCorpses) do
2720 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
2721 begin
2722 co := gCorpses[a].Obj;
2723 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
2724 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
2725 // Ïèíàåì òðóïû
2726 if FObj.Vel.X < 0 then
2727 gCorpses[a].Damage(b*2, -b, Random(7)) // íàëåâî
2728 else
2729 gCorpses[a].Damage(b*2, b, Random(7)); // íàïðàâî
2730 end;
2731 end;
2732 // Åñëè öåëü âûñîêî, òî, âîçìîæíî, ïðûãàåì:
2733 if sy < -40 then
2734 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
2735 // ñòîèò òâåðäî
2736 if (Random(4) = 0) and (FObj.Accel.Y = 0) then
2737 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
2738 end;
2740 FSleep := FSleep + 1;
2742 // Èíîãäà ðû÷èì:
2743 if FSleep >= 8 then
2744 begin
2745 FSleep := 0;
2746 if Random(8) = 0 then
2747 ActionSound();
2748 end;
2750 // Áåæèì â âûáðàííóþ ñòîðîíó:
2751 if FDirection = D_RIGHT then
2752 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2753 else
2754 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2756 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2757 if WordBool(st and MOVE_INWATER) then
2758 FObj.Vel.X := FObj.Vel.X div 2
2759 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2760 if FMonsterType = MONSTER_FISH then
2761 FObj.Vel.X := 0;
2762 end;
2764 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
2765 begin
2766 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
2767 if WordBool(st and MOVE_BLOCK) then
2768 begin
2769 Turn();
2770 FSleep := 40;
2771 SetState(MONSTATE_RUNOUT);
2773 goto _end;
2774 end;
2776 FSleep := FSleep - 1;
2778 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
2779 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
2780 begin
2781 FSleep := 0;
2782 SetState(MONSTATE_GO);
2783 // Ñòåíà - èäåì îáðàòíî:
2784 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
2785 Turn();
2786 // Èíîãäà ðû÷èì:
2787 if Random(8) = 0 then
2788 ActionSound();
2789 end;
2791 // Áåæèì â âûáðàííóþ ñòîðîíó:
2792 if FDirection = D_RIGHT then
2793 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2794 else
2795 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2797 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2798 if WordBool(st and MOVE_INWATER) then
2799 FObj.Vel.X := FObj.Vel.X div 2
2800 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2801 if FMonsterType = MONSTER_FISH then
2802 FObj.Vel.X := 0;
2803 end;
2805 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
2806 begin
2807 // Âûøëè èç ÁëîêÌîíà:
2808 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
2809 FSleep := 0;
2811 FSleep := FSleep - 1;
2813 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
2814 if FSleep <= -18 then
2815 begin
2816 FSleep := 0;
2817 SetState(MONSTATE_GO);
2818 // Ñòåíà/ÁëîêÌîí - èäåì îáðàòíî:
2819 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
2820 Turn();
2821 // Èíîãäà ðû÷èì:
2822 if Random(8) = 0 then
2823 ActionSound();
2824 end;
2826 // Áåæèì â âûáðàííóþ ñòîðîíó:
2827 if FDirection = D_RIGHT then
2828 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2829 else
2830 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2832 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2833 if WordBool(st and MOVE_INWATER) then
2834 FObj.Vel.X := FObj.Vel.X div 2
2835 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2836 if FMonsterType = MONSTER_FISH then
2837 FObj.Vel.X := 0;
2838 end;
2840 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
2841 begin
2842 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
2843 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
2844 (not WordBool(st and MOVE_HITWALL)) then
2845 begin
2846 FSleep := 0;
2847 SetState(MONSTATE_GO);
2849 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
2850 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
2851 begin
2852 Turn();
2853 FSleep := 15;
2854 SetState(MONSTATE_RUN);
2855 end;
2856 end;
2858 // Áåæèì â âûáðàííóþ ñòîðîíó:
2859 if FDirection = D_RIGHT then
2860 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
2861 else
2862 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
2864 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
2865 if WordBool(st and MOVE_INWATER) then
2866 FObj.Vel.X := FObj.Vel.X div 2
2867 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
2868 if FMonsterType = MONSTER_FISH then
2869 FObj.Vel.X := 0;
2870 end;
2872 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
2873 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
2874 begin
2875 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
2876 if FMonsterType = MONSTER_SOUL then
2877 begin
2878 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
2879 SetState(MONSTATE_GO);
2881 goto _end;
2882 end;
2884 // Çàìåäëÿåìñÿ ïðè àòàêå:
2885 if FMonsterType <> MONSTER_FISH then
2886 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
2888 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
2889 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
2890 begin
2891 // Öåëü ïîãèáëà => èäåì äàëüøå:
2892 if not GetPos(FTargetUID, @o) then
2893 begin
2894 SetState(MONSTATE_GO);
2896 goto _end;
2897 end;
2899 // Öåëü íå âèäíî => èäåì äàëüøå:
2900 if not g_Look(@FObj, @o, FDirection) then
2901 begin
2902 SetState(MONSTATE_GO);
2904 goto _end;
2905 end;
2907 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
2908 if g_Obj_CollideWater(@o, 0, 0) then
2909 begin
2910 SetState(MONSTATE_GO);
2912 goto _end;
2913 end;
2915 // Æàðèì öåëü:
2916 tx := o.X+o.Rect.X+(o.Rect.Width div 2);
2917 ty := o.Y+o.Rect.Y+(o.Rect.Height div 2);
2918 g_Weapon_HitUID(FTargetUID, 2, FUID, HIT_SOME);
2919 end;
2920 end;
2921 end; // case FState of ...
2923 _end:
2925 // Ñîñòîÿíèå - Âîñêðåøåíèå:
2926 if FState = MONSTATE_REVIVE then
2927 if FAnim[FCurAnim, FDirection].Played then
2928 begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
2929 FAnim[FCurAnim, FDirection].Revert(False);
2930 SetState(MONSTATE_GO);
2931 end;
2933 // Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
2934 if vilefire <> nil then
2935 vilefire.Update();
2937 // Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
2938 if (FState = MONSTATE_DIE) and
2939 (FAnim[FCurAnim, FDirection] <> nil) and
2940 (FAnim[FCurAnim, FDirection].Played) then
2941 begin
2942 // Óìåð:
2943 SetState(MONSTATE_DEAD);
2945 // Pain_Elemental ïðè ñìåðòè âûïóñêàåò 3 Lost_Soul'à:
2946 if (FMonsterType = MONSTER_PAIN) then
2947 begin
2948 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-30,
2949 FObj.Y+FObj.Rect.Y+20, D_LEFT);
2950 if mon <> nil then
2951 begin
2952 mon.SetState(MONSTATE_GO);
2953 mon.FNoRespawn := True;
2954 Inc(gTotalMonsters);
2955 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
2956 end;
2958 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2959 FObj.Y+FObj.Rect.Y+20, D_RIGHT);
2960 if mon <> nil then
2961 begin
2962 mon.SetState(MONSTATE_GO);
2963 mon.FNoRespawn := True;
2964 Inc(gTotalMonsters);
2965 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
2966 end;
2968 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-15,
2969 FObj.Y+FObj.Rect.Y, D_RIGHT);
2970 if mon <> nil then
2971 begin
2972 mon.SetState(MONSTATE_GO);
2973 mon.FNoRespawn := True;
2974 Inc(gTotalMonsters);
2975 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
2976 end;
2978 if g_Game_IsNet then MH_SEND_CoopStats();
2979 end;
2981 // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
2982 if (FMonsterType = MONSTER_PAIN) or
2983 (FMonsterType = MONSTER_SOUL) or
2984 (FMonsterType = MONSTER_BARREL) then
2985 FRemoved := True;
2986 end;
2988 // Ñîâåðøåíèå àòàêè è ñòðåëüáû:
2989 if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
2990 if (FAnim[FCurAnim, FDirection] <> nil) then
2991 // Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
2992 if (FAnim[FCurAnim, FDirection].Played) then
2993 begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
2994 if FState = MONSTATE_ATTACK then
2995 begin // Ñîñòîÿíèå - Àòàêà
2996 // Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
2997 if FMonsterType <> MONSTER_SOUL then
2998 SetState(MONSTATE_GO);
2999 end
3000 else // Ñîñòîÿíèå - Ñòðåëüáà
3001 begin
3002 // Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
3003 if not FChainFire then
3004 SetState(MONSTATE_GO)
3005 else
3006 begin // Íàäî ñòðåëÿòü åùå
3007 FChainFire := False;
3008 // Ò.ê. ñîñòîÿíèå íå èçìåíèëîñü, è íóæåí
3009 // íîâûé öèêë îæèäàíèÿ çàâåðøåíèÿ àíèìàöèè:
3010 FAnim[FCurAnim, FDirection].Reset();
3011 end;
3012 end;
3014 FWaitAttackAnim := False;
3015 end
3017 else // Àíèìàöèÿ àòàêè åùå èäåò (èñêëþ÷åíèå - Lost_Soul):
3018 if (FMonsterType = MONSTER_SOUL) or
3019 ( (not FWaitAttackAnim) and
3020 (FAnim[FCurAnim, FDirection].CurrentFrame =
3021 (FAnim[FCurAnim, FDirection].TotalFrames div 2))
3022 ) then
3023 begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
3024 if FState = MONSTATE_ATTACK then
3025 begin // Ñîñòîÿíèå - Àòàêà
3026 // Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
3027 if FMonsterType = MONSTER_SOUL then
3028 FAnim[FCurAnim, FDirection].Reset();
3030 case FMonsterType of
3031 MONSTER_SOUL, MONSTER_IMP, MONSTER_DEMON:
3032 // Ãðûçåì ïåðâîãî ïîïàâøåãîñÿ:
3033 if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
3034 // Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
3035 if FMonsterType = MONSTER_SOUL then
3036 SetState(MONSTATE_GO);
3038 MONSTER_FISH:
3039 // Ðûáà êóñàåò ïåðâîãî ïîïàâøåãîñÿ ñî çâóêîì:
3040 if g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME) <> 0 then
3041 g_Sound_PlayExAt('SOUND_MONSTER_FISH_ATTACK', FObj.X, FObj.Y);
3043 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
3044 // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
3045 if FCurAnim = ANIM_ATTACK2 then
3046 begin
3047 o := FObj;
3048 o.Vel.X := IfThen(FDirection = D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
3049 if g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME) <> 0 then
3050 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_HIT', FObj.X, FObj.Y);
3051 end;
3053 MONSTER_VILE:
3054 // Êîëäóí ïûòàåòñÿ âîñêðåøàòü:
3055 if FCurAnim = ANIM_ATTACK2 then
3056 begin
3057 sx := isCorpse(@FObj, True);
3058 if sx <> -1 then
3059 begin // Íàøëè, êîãî âîñêðåñèòü
3060 gMonsters[sx].SetState(MONSTATE_REVIVE);
3061 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
3062 // Âîñêðåøàòü - ñåáå âðåäèòü:
3063 {g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
3064 end;
3065 end;
3066 end;
3067 end
3069 else // Ñîñòîÿíèå - Ñòðåëüáà
3070 begin
3071 // Âû÷èñëÿåì êîîðäèíàòû, îòêóäà âûëåòèò ïóëÿ:
3072 wx := MONSTER_ANIMTABLE[FMonsterType].wX;
3074 if FDirection = D_LEFT then
3075 begin
3076 wx := MONSTER_ANIMTABLE[FMonsterType].wX-(MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2));
3077 wx := MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2)-wx;
3078 end; // Ýòî çíà÷èò: wx := hitX + (hitWidth / 2) - (wx - (hitX + (hitWidth / 2)))
3080 wx := FObj.X + wx;
3081 wy := FObj.Y + MONSTER_ANIMTABLE[FMonsterType].wY;
3083 // Äåëàåì âûñòðåë íóæíûì îðóæèåì:
3084 case FMonsterType of
3085 MONSTER_IMP:
3086 g_Weapon_ball1(wx, wy, tx, ty, FUID);
3087 MONSTER_ZOMBY:
3088 begin
3089 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3090 g_Weapon_gun(wx, wy, tx, ty, 1, 3, FUID, False);
3091 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3092 end;
3093 MONSTER_SERG:
3094 begin
3095 g_Weapon_shotgun(wx, wy, tx, ty, FUID);
3096 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3097 FShellTimer := 10;
3098 FShellType := SHELL_SHELL;
3099 end;
3100 MONSTER_MAN:
3101 begin
3102 g_Weapon_dshotgun(wx, wy, tx, ty, FUID);
3103 FShellTimer := 13;
3104 FShellType := SHELL_DBLSHELL;
3105 FAmmo := -36;
3106 end;
3107 MONSTER_CYBER:
3108 begin
3109 g_Weapon_rocket(wx, wy, tx, ty, FUID);
3110 // MH_SEND_MonsterAttack(FUID, wx, wy, tx, ty);
3111 end;
3112 MONSTER_SKEL:
3113 g_Weapon_revf(wx, wy, tx, ty, FUID, FTargetUID);
3114 MONSTER_CGUN:
3115 begin
3116 g_Weapon_mgun(wx, wy, tx, ty, FUID);
3117 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3118 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3119 end;
3120 MONSTER_SPIDER:
3121 begin
3122 g_Weapon_mgun(wx, wy, tx, ty, FUID);
3123 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3124 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
3125 end;
3126 MONSTER_BSP:
3127 g_Weapon_aplasma(wx, wy, tx, ty, FUID);
3128 MONSTER_ROBO:
3129 g_Weapon_plasma(wx, wy, tx, ty, FUID);
3130 MONSTER_MANCUB:
3131 g_Weapon_manfire(wx, wy, tx, ty, FUID);
3132 MONSTER_BARON, MONSTER_KNIGHT:
3133 g_Weapon_ball7(wx, wy, tx, ty, FUID);
3134 MONSTER_CACO:
3135 g_Weapon_ball2(wx, wy, tx, ty, FUID);
3136 MONSTER_PAIN:
3137 begin // Ñîçäàåì Lost_Soul:
3138 mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+(FObj.Rect.Width div 2),
3139 FObj.Y+FObj.Rect.Y, FDirection);
3141 if mon <> nil then
3142 begin // Öåëü - öåëü Pain_Elemental'à. Ëåòèì ê íåé:
3143 mon.FTargetUID := FTargetUID;
3144 GetPos(FTargetUID, @o);
3145 mon.FTargetTime := 0;
3146 mon.FNoRespawn := True;
3147 mon.SetState(MONSTATE_GO);
3148 mon.shoot(@o, True);
3149 Inc(gTotalMonsters);
3151 if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
3152 end;
3153 end;
3154 end;
3156 if FMonsterType <> MONSTER_PAIN then
3157 if g_Game_IsNet then
3158 MH_SEND_MonsterShot(FUID, wx, wy, tx, ty);
3160 // Ñêîðîñòðåëüíûå ìîíñòðû:
3161 if (FMonsterType = MONSTER_CGUN) or
3162 (FMonsterType = MONSTER_SPIDER) or
3163 (FMonsterType = MONSTER_BSP) or
3164 (FMonsterType = MONSTER_MANCUB) or
3165 (FMonsterType = MONSTER_ROBO) then
3166 if not GetPos(FTargetUID, @o) then
3167 // Öåëü ìåðòâà - èùåì íîâóþ:
3168 findNewPrey()
3169 else // Öåëü æèâà - ïðîäîëæàåì ñòðåëÿòü:
3170 if shoot(@o, False) then
3171 FChainFire := True;
3172 end;
3174 // Àòàêà òîëüêî 1 ðàç çà àíèìàöèþ àòàêè:
3175 FWaitAttackAnim := True;
3176 end;
3178 // Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
3179 if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
3180 case FState of
3181 MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
3182 // Çâóêè ïðè ïåðåäâèæåíèè:
3183 case FMonsterType of
3184 MONSTER_CYBER:
3185 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3186 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3187 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_WALK', FObj.X, FObj.Y);
3188 MONSTER_SPIDER:
3189 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3190 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3191 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_WALK', FObj.X, FObj.Y);
3192 MONSTER_BSP:
3193 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3194 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3195 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3196 MONSTER_ROBO:
3197 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3198 (FAnim[FCurAnim, FDirection].CurrentFrame = 5) then
3199 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3200 end;
3201 end;
3203 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
3204 not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
3205 FObj.Vel.X := oldvelx;
3207 // Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
3208 if FAnim[FCurAnim, FDirection] <> nil then
3209 FAnim[FCurAnim, FDirection].Update();
3210 end;
3212 procedure TMonster.SetDeadAnim;
3213 begin
3214 if FAnim <> nil then
3215 FAnim[FCurAnim, FDirection].CurrentFrame := FAnim[FCurAnim, FDirection].TotalFrames - 1;
3216 end;
3218 procedure TMonster.RevertAnim(R: Boolean = True);
3219 begin
3220 if FAnim <> nil then
3221 if FAnim[FCurAnim, FDirection].IsReverse <> R then
3222 FAnim[FCurAnim, FDirection].Revert(R);
3223 end;
3225 function TMonster.AnimIsReverse: Boolean;
3226 begin
3227 if FAnim <> nil then
3228 Result := FAnim[FCurAnim, FDirection].IsReverse
3229 else
3230 Result := False;
3231 end;
3233 procedure TMonster.ClientUpdate();
3234 var
3235 a, b, sx, sy, oldvelx: Integer;
3236 st: Word;
3237 o, co: TObj;
3238 fall: Boolean;
3239 label
3240 _end;
3241 begin
3242 sx := 0; // SHUT UP COMPILER
3243 sy := 0;
3244 fall := True;
3245 // Ðûáû "ëåòàþò" òîëüêî â âîäå:
3246 if FMonsterType = MONSTER_FISH then
3247 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3248 if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
3249 fall := False;
3251 // Ëåòàþùèå ìîíòñðû:
3252 if ((FMonsterType = MONSTER_SOUL) or
3253 (FMonsterType = MONSTER_PAIN) or
3254 (FMonsterType = MONSTER_CACO)) and
3255 (FState <> MONSTATE_DIE) and
3256 (FState <> MONSTATE_DEAD) then
3257 fall := False;
3259 // Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
3260 if gTime mod (GAME_TICK*2) <> 0 then
3261 begin
3262 g_Obj_Move(@FObj, fall, True, True);
3263 positionChanged(); // this updates spatial accelerators
3264 Exit;
3265 end;
3267 if FPainTicks > 0 then
3268 Dec(FPainTicks)
3269 else
3270 FPainSound := False;
3272 // Äâèãàåìñÿ:
3273 st := g_Obj_Move(@FObj, fall, True, True);
3274 positionChanged(); // this updates spatial accelerators
3276 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
3277 if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
3278 (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
3279 begin
3280 FRemoved := True;
3281 Exit;
3282 end;
3284 oldvelx := FObj.Vel.X;
3286 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
3287 if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
3288 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3290 if FFireTime > 0 then
3291 begin
3292 if WordBool(st and MOVE_INWATER) then
3293 FFireTime := 0
3294 else
3295 begin
3296 OnFireFlame(1);
3297 FFireTime := FFireTime - 1;
3298 end;
3299 end;
3301 // Ìåðòâûé íè÷åãî íå äåëàåò:
3302 if (FState = MONSTATE_DEAD) then
3303 goto _end;
3305 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
3306 if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
3307 case FMonsterType of
3308 MONSTER_FISH:
3309 if Random(4) = 0 then
3310 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
3311 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
3312 MONSTER_ROBO, MONSTER_BARREL:
3313 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
3314 FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
3315 else begin
3316 g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
3317 FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
3318 if Random(2) = 0 then
3319 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
3320 else
3321 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
3322 end;
3323 end;
3325 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
3326 if FMonsterType = MONSTER_BARREL then
3327 begin
3328 if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
3329 (FAnim[FCurAnim, FDirection].Counter = 0) then
3330 g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3331 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
3332 60, FUID);
3333 end;
3335 // Lost_Soul âûëåòåë èç âîäû => óñêîðÿåòñÿ:
3336 if FMonsterType = MONSTER_SOUL then
3337 if WordBool(st and MOVE_HITAIR) then
3338 g_Obj_SetSpeed(@FObj, 16);
3340 if FAmmo < 0 then
3341 FAmmo := FAmmo + 1;
3343 // Åñëè íà÷àëè âñïëûâàòü, òî ïðîäîëæàåì:
3344 if FObj.Vel.Y < 0 then
3345 if WordBool(st and MOVE_INWATER) then
3346 FObj.Vel.Y := -4;
3348 // Òàéìåð - æäåì ïîñëå ïîòåðè öåëè:
3349 FTargetTime := FTargetTime + 1;
3351 if FShellTimer > -1 then
3352 if FShellTimer = 0 then
3353 begin
3354 if FShellType = SHELL_SHELL then
3355 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3356 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3357 GameVelX, GameVelY-2, SHELL_SHELL)
3358 else if FShellType = SHELL_DBLSHELL then
3359 begin
3360 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3361 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3362 GameVelX-1, GameVelY-2, SHELL_SHELL);
3363 g_Player_CreateShell(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
3364 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
3365 GameVelX+1, GameVelY-2, SHELL_SHELL);
3366 end;
3367 FShellTimer := -1;
3368 end else Dec(FShellTimer);
3370 // Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
3371 if fall then
3372 if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
3373 MONSTATE_ATTACK, MONSTATE_SHOOT]) then
3374 if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3375 FObj.Rect.Width, FObj.Rect.Height, 50) then
3376 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
3377 (FObj.Accel.Y = 0) then
3378 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
3380 case FState of
3381 MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
3382 begin
3383 // Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
3384 if FPain >= MONSTERTABLE[FMonsterType].Pain then
3385 begin
3386 FPain := MONSTERTABLE[FMonsterType].Pain;
3387 if gSoundEffectsDF then PainSound();
3388 end;
3389 if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
3390 PainSound();
3392 // Ñíèæàåì áîëü ñî âðåìåíåì:
3393 FPain := FPain - 5;
3395 // Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
3396 if FPain <= MONSTERTABLE[FMonsterType].MinPain then
3397 begin
3398 SetState(MONSTATE_GO);
3399 FPain := 0;
3400 end;
3401 end;
3403 MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
3404 begin
3405 // Ñïèì:
3406 FSleep := FSleep + 1;
3408 // Ïðîñïàëè äîñòàòî÷íî:
3409 if FSleep >= 18 then
3410 FSleep := 0
3411 else // åùå ñïèì
3412 goto _end;
3413 end;
3415 MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
3416 begin
3417 // Æäåì:
3418 FSleep := FSleep - 1;
3419 end;
3421 MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
3422 begin
3423 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
3424 if WordBool(st and MOVE_BLOCK) then
3425 begin
3426 Turn();
3427 FSleep := 40;
3428 SetState(MONSTATE_RUNOUT);
3430 goto _end;
3431 end;
3433 // Åñëè ìîíñòð - êîëäóí, òî ïðîáóåì âîñêðåñèòü êîãî-íèáóäü:
3434 if (FMonsterType = MONSTER_VILE) then
3435 if isCorpse(@FObj, False) <> -1 then
3436 begin
3437 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
3438 FObj.Vel.X := 0;
3440 goto _end;
3441 end;
3443 // Åñëè öåëü ïî÷òè íà îäíîé âåðòèêàëè - áåãàåì òóäà-ñþäà:
3444 if Abs(sx) < 40 then
3445 if FMonsterType <> MONSTER_FISH then
3446 begin
3447 SetState(MONSTATE_RUN);
3448 FSleep := 15;
3450 goto _end;
3451 end;
3453 // Óïåðëèñü â ñòåíó:
3454 if WordBool(st and MOVE_HITWALL) then
3455 begin
3456 case FMonsterType of
3457 MONSTER_CACO, MONSTER_SOUL, MONSTER_PAIN, MONSTER_FISH: ;
3458 else // Íå ëåòàþò:
3459 if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
3460 (FObj.Accel.Y = 0) then
3461 begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
3462 // Ïðûæîê ÷åðåç ñòåíó:
3463 FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
3464 SetState(MONSTATE_CLIMB);
3465 end;
3466 end;
3468 goto _end;
3469 end;
3471 // Ìîíñòðû, íå ïîäâåðæåííûå ãðàâèòàöèè:
3472 if (FMonsterType = MONSTER_CACO) or (FMonsterType = MONSTER_SOUL) or
3473 (FMonsterType = MONSTER_PAIN) or (FMonsterType = MONSTER_FISH) then
3474 begin
3475 if FMonsterType = MONSTER_FISH then
3476 begin // Ðûáà
3477 if not WordBool(st and MOVE_INWATER) then
3478 begin // Ðûáà âíå âîäû:
3479 if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
3480 begin // "Ñòîèò" òâåðäî
3481 // Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
3482 if FObj.Accel.Y = 0 then
3483 FObj.Vel.Y := -6;
3484 FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
3485 end;
3487 // Ðûáå áîëüíî:
3488 SetState(MONSTATE_PAIN);
3489 FPain := FPain + 50;
3490 end
3491 else // Ðûáà â âîäå
3492 begin
3493 // Ïëûâåì â ñòîðîíó öåëè ïî-âåðòèêàëè:
3494 if Abs(sy) > 8 then
3495 FObj.Vel.Y := g_basic.Sign(sy)*4
3496 else
3497 FObj.Vel.Y := 0;
3499 // Ðûáà ïëûâåò ââåðõ:
3500 if FObj.Vel.Y < 0 then
3501 if not g_Obj_CollideWater(@FObj, 0, -16) then
3502 begin
3503 // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
3504 FObj.Vel.Y := 0;
3505 // Ïëàâàåì òóäà-ñþäà:
3506 SetState(MONSTATE_RUN);
3507 FSleep := 20;
3508 end;
3509 end;
3510 end
3511 else // Ëåòàþùèå ìîíñòðû
3512 begin
3513 // Ëåòèì â ñòîðîíó öåëè ïî-âåðòèêàëè:
3514 if Abs(sy) > 8 then
3515 FObj.Vel.Y := g_basic.Sign(sy)*4
3516 else
3517 FObj.Vel.Y := 0;
3518 end;
3519 end
3520 else // "Íàçåìíûå" ìîíñòðû
3521 begin
3522 // Âîçìîæíî, ïèíàåì êóñêè:
3523 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
3524 begin
3525 b := Abs(FObj.Vel.X);
3526 if b > 1 then b := b * (Random(8 div b) + 1);
3527 for a := 0 to High(gGibs) do
3528 begin
3529 if gGibs[a].Live and
3530 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
3531 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
3532 begin
3533 // Ïèíàåì êóñêè
3534 if FObj.Vel.X < 0 then
3535 begin
3536 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
3537 end
3538 else
3539 begin
3540 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
3541 end;
3542 positionChanged(); // this updates spatial accelerators
3543 end;
3544 end;
3545 end;
3546 // Áîññû ìîãóò ïèíàòü òðóïû:
3547 if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
3548 (FObj.Vel.X <> 0) and (gCorpses <> nil) then
3549 begin
3550 b := Abs(FObj.Vel.X);
3551 if b > 1 then b := b * (Random(8 div b) + 1);
3552 for a := 0 to High(gCorpses) do
3553 if (gCorpses[a] <> nil) and (gCorpses[a].State > 0) then
3554 begin
3555 co := gCorpses[a].Obj;
3556 if g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
3557 FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
3558 // Ïèíàåì òðóïû
3559 if FObj.Vel.X < 0 then
3560 gCorpses[a].Damage(b*2, -b, Random(7)) // íàëåâî
3561 else
3562 gCorpses[a].Damage(b*2, b, Random(7)); // íàïðàâî
3563 end;
3564 end;
3565 end;
3567 FSleep := FSleep + 1;
3569 // Èíîãäà ðû÷èì:
3570 if FSleep >= 8 then
3571 begin
3572 FSleep := 0;
3573 if Random(8) = 0 then
3574 ActionSound();
3575 end;
3577 // Áåæèì â âûáðàííóþ ñòîðîíó:
3578 if FDirection = D_RIGHT then
3579 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3580 else
3581 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3583 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3584 if WordBool(st and MOVE_INWATER) then
3585 FObj.Vel.X := FObj.Vel.X div 2
3586 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3587 if FMonsterType = MONSTER_FISH then
3588 FObj.Vel.X := 0;
3589 end;
3591 MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
3592 begin
3593 // Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
3594 if WordBool(st and MOVE_BLOCK) then
3595 begin
3596 SetState(MONSTATE_RUNOUT);
3597 FSleep := 40;
3599 goto _end;
3600 end;
3602 FSleep := FSleep - 1;
3604 // Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
3605 if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
3606 begin
3607 SetState(MONSTATE_GO);
3608 FSleep := 0;
3610 // Èíîãäà ðû÷èì:
3611 if Random(8) = 0 then
3612 ActionSound();
3613 end;
3615 // Áåæèì â âûáðàííóþ ñòîðîíó:
3616 if FDirection = D_RIGHT then
3617 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3618 else
3619 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3621 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3622 if WordBool(st and MOVE_INWATER) then
3623 FObj.Vel.X := FObj.Vel.X div 2
3624 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3625 if FMonsterType = MONSTER_FISH then
3626 FObj.Vel.X := 0;
3627 end;
3629 MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
3630 begin
3631 // Âûøëè èç ÁëîêÌîíà:
3632 if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
3633 FSleep := 0;
3635 FSleep := FSleep - 1;
3637 // Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
3638 if FSleep <= -18 then
3639 begin
3640 SetState(MONSTATE_GO);
3641 FSleep := 0;
3643 // Èíîãäà ðû÷èì:
3644 if Random(8) = 0 then
3645 ActionSound();
3646 end;
3648 // Áåæèì â âûáðàííóþ ñòîðîíó:
3649 if FDirection = D_RIGHT then
3650 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3651 else
3652 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3654 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3655 if WordBool(st and MOVE_INWATER) then
3656 FObj.Vel.X := FObj.Vel.X div 2
3657 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3658 if FMonsterType = MONSTER_FISH then
3659 FObj.Vel.X := 0;
3660 end;
3662 MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
3663 begin
3664 // Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
3665 if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
3666 (not WordBool(st and MOVE_HITWALL)) then
3667 begin
3668 SetState(MONSTATE_GO);
3669 FSleep := 0;
3671 // Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
3672 if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
3673 begin
3674 SetState(MONSTATE_RUN);
3675 FSleep := 15;
3676 end;
3677 end;
3679 // Áåæèì â âûáðàííóþ ñòîðîíó:
3680 if FDirection = D_RIGHT then
3681 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3682 else
3683 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3685 // Åñëè â âîäå, òî çàìåäëÿåìñÿ:
3686 if WordBool(st and MOVE_INWATER) then
3687 FObj.Vel.X := FObj.Vel.X div 2
3688 else // Ðûáàì íå íóæíî çàìåäëÿòüñÿ
3689 if FMonsterType = MONSTER_FISH then
3690 FObj.Vel.X := 0;
3691 end;
3693 MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
3694 MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
3695 begin
3696 // Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
3697 if FMonsterType = MONSTER_SOUL then
3698 begin
3699 if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
3700 SetState(MONSTATE_GO);
3702 goto _end;
3703 end;
3705 // Çàìåäëÿåìñÿ ïðè àòàêå:
3706 if FMonsterType <> MONSTER_FISH then
3707 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
3709 // Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
3710 if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
3711 begin
3712 // Öåëü ïîãèáëà => èäåì äàëüøå:
3713 if not GetPos(FTargetUID, @o) then
3714 begin
3715 SetState(MONSTATE_GO);
3717 goto _end;
3718 end;
3720 // Öåëü íå âèäíî => èäåì äàëüøå:
3721 if not g_Look(@FObj, @o, FDirection) then
3722 begin
3723 SetState(MONSTATE_GO);
3725 goto _end;
3726 end;
3728 // Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
3729 if g_Obj_CollideWater(@o, 0, 0) then
3730 begin
3731 SetState(MONSTATE_GO);
3733 goto _end;
3734 end;
3735 end;
3736 end;
3737 end; // case FState of ...
3739 _end:
3741 // Ñîñòîÿíèå - Âîñêðåøåíèå:
3742 if FState = MONSTATE_REVIVE then
3743 if FAnim[FCurAnim, FDirection].Played then
3744 begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
3745 FAnim[FCurAnim, FDirection].Revert(False);
3746 SetState(MONSTATE_GO);
3747 end;
3749 // Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
3750 if vilefire <> nil then
3751 vilefire.Update();
3753 // Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
3754 if (FState = MONSTATE_DIE) and
3755 (FAnim[FCurAnim, FDirection] <> nil) and
3756 (FAnim[FCurAnim, FDirection].Played) then
3757 begin
3758 // Óìåð:
3759 SetState(MONSTATE_DEAD);
3761 // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
3762 if (FMonsterType = MONSTER_PAIN) or
3763 (FMonsterType = MONSTER_SOUL) or
3764 (FMonsterType = MONSTER_BARREL) then
3765 FRemoved := True
3766 else
3767 FAnim[FCurAnim, FDirection].CurrentFrame := FAnim[FCurAnim, FDirection].TotalFrames - 1;
3768 end;
3770 // Ñîâåðøåíèå àòàêè è ñòðåëüáû:
3771 if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
3772 if (FAnim[FCurAnim, FDirection] <> nil) then
3773 // Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
3774 if (FAnim[FCurAnim, FDirection].Played) then
3775 begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
3776 if FState = MONSTATE_ATTACK then
3777 begin // Ñîñòîÿíèå - Àòàêà
3778 // Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
3779 if FMonsterType <> MONSTER_SOUL then
3780 SetState(MONSTATE_GO);
3781 end
3782 else // Ñîñòîÿíèå - Ñòðåëüáà
3783 begin
3784 // Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
3785 if not FChainFire then
3786 SetState(MONSTATE_GO)
3787 else
3788 begin // Íàäî ñòðåëÿòü åùå
3789 FChainFire := False;
3790 // Ò.ê. ñîñòîÿíèå íå èçìåíèëîñü, è íóæåí
3791 // íîâûé öèêë îæèäàíèÿ çàâåðøåíèÿ àíèìàöèè:
3792 FAnim[FCurAnim, FDirection].Reset();
3793 end;
3794 end;
3796 FWaitAttackAnim := False;
3797 end
3799 else // Àíèìàöèÿ àòàêè åùå èäåò (èñêëþ÷åíèå - Lost_Soul):
3800 if (FMonsterType = MONSTER_SOUL) or
3801 ( (not FWaitAttackAnim) and
3802 (FAnim[FCurAnim, FDirection].CurrentFrame =
3803 (FAnim[FCurAnim, FDirection].TotalFrames div 2))
3804 ) then
3805 begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
3806 if FState = MONSTATE_ATTACK then
3807 begin // Ñîñòîÿíèå - Àòàêà
3808 // Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
3809 if FMonsterType = MONSTER_SOUL then
3810 FAnim[FCurAnim, FDirection].Reset();
3812 case FMonsterType of
3813 MONSTER_SOUL, MONSTER_IMP, MONSTER_DEMON:
3814 // Ãðûçåì ïåðâîãî ïîïàâøåãîñÿ:
3815 if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
3816 // Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
3817 if FMonsterType = MONSTER_SOUL then
3818 SetState(MONSTATE_GO);
3820 MONSTER_FISH:
3821 g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME);
3823 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
3824 // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
3825 if FCurAnim = ANIM_ATTACK2 then
3826 begin
3827 o := FObj;
3828 o.Vel.X := IfThen(FDirection = D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
3829 g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME);
3830 end;
3832 MONSTER_VILE:
3833 // Êîëäóí ïûòàåòñÿ âîñêðåøàòü:
3834 if FCurAnim = ANIM_ATTACK2 then
3835 begin
3836 sx := isCorpse(@FObj, True);
3837 if sx <> -1 then
3838 begin // Íàøëè, êîãî âîñêðåñèòü
3839 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
3840 // Âîñêðåøàòü - ñåáå âðåäèòü:
3841 {g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
3842 end;
3843 end;
3844 end;
3845 end
3847 else // Ñîñòîÿíèå - Ñòðåëüáà
3848 begin
3849 // Ñêîðîñòðåëüíûå ìîíñòðû:
3850 if (FMonsterType = MONSTER_CGUN) or
3851 (FMonsterType = MONSTER_SPIDER) or
3852 (FMonsterType = MONSTER_BSP) or
3853 (FMonsterType = MONSTER_MANCUB) or
3854 (FMonsterType = MONSTER_ROBO) then
3855 if not GetPos(FTargetUID, @o) then
3856 // Öåëü ìåðòâà - èùåì íîâóþ:
3857 findNewPrey()
3858 else // Öåëü æèâà - ïðîäîëæàåì ñòðåëÿòü:
3859 if shoot(@o, False) then
3860 FChainFire := True;
3861 end;
3863 // Àòàêà òîëüêî 1 ðàç çà àíèìàöèþ àòàêè:
3864 FWaitAttackAnim := True;
3865 end;
3867 // Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
3868 if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
3869 case FState of
3870 MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
3871 // Çâóêè ïðè ïåðåäâèæåíèè:
3872 case FMonsterType of
3873 MONSTER_CYBER:
3874 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3875 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3876 g_Sound_PlayExAt('SOUND_MONSTER_CYBER_WALK', FObj.X, FObj.Y);
3877 MONSTER_SPIDER:
3878 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3879 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3880 g_Sound_PlayExAt('SOUND_MONSTER_SPIDER_WALK', FObj.X, FObj.Y);
3881 MONSTER_BSP:
3882 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3883 (FAnim[FCurAnim, FDirection].CurrentFrame = 2) then
3884 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3885 MONSTER_ROBO:
3886 if (FAnim[FCurAnim, FDirection].CurrentFrame = 0) or
3887 (FAnim[FCurAnim, FDirection].CurrentFrame = 5) then
3888 g_Sound_PlayExAt('SOUND_MONSTER_BSP_WALK', FObj.X, FObj.Y);
3889 end;
3890 end;
3892 // Êîñòûëü äëÿ ïîòîêîâ
3893 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
3894 not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
3895 FObj.Vel.X := oldvelx;
3897 // Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
3898 if FAnim[FCurAnim, FDirection] <> nil then
3899 FAnim[FCurAnim, FDirection].Update();
3900 end;
3902 procedure TMonster.ClientAttack(wx, wy, atx, aty: Integer);
3903 begin
3904 case FMonsterType of
3905 MONSTER_ZOMBY:
3906 begin
3907 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3908 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3909 end;
3910 MONSTER_SERG:
3911 begin
3912 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3913 FShellTimer := 10;
3914 FShellType := SHELL_SHELL;
3915 end;
3916 MONSTER_MAN:
3917 begin
3918 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', wx, wy);
3919 FShellTimer := 13;
3920 FShellType := SHELL_DBLSHELL;
3921 end;
3922 MONSTER_CGUN, MONSTER_SPIDER:
3923 begin
3924 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3925 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
3926 end;
3927 MONSTER_IMP:
3928 g_Weapon_ball1(wx, wy, atx, aty, FUID);
3929 MONSTER_CYBER:
3930 g_Weapon_rocket(wx, wy, atx, aty, FUID);
3931 MONSTER_SKEL:
3932 g_Weapon_revf(wx, wy, atx, aty, FUID, FTargetUID);
3933 MONSTER_BSP:
3934 g_Weapon_aplasma(wx, wy, atx, aty, FUID);
3935 MONSTER_ROBO:
3936 g_Weapon_plasma(wx, wy, atx, aty, FUID);
3937 MONSTER_MANCUB:
3938 g_Weapon_manfire(wx, wy, atx, aty, FUID);
3939 MONSTER_BARON, MONSTER_KNIGHT:
3940 g_Weapon_ball7(wx, wy, atx, aty, FUID);
3941 MONSTER_CACO:
3942 g_Weapon_ball2(wx, wy, atx, aty, FUID);
3943 end;
3944 end;
3946 procedure TMonster.Turn();
3947 begin
3948 // Ðàçâîðà÷èâàåìñÿ:
3949 if FDirection = D_LEFT then
3950 FDirection := D_RIGHT
3951 else
3952 FDirection := D_LEFT;
3954 // Áåæèì â âûáðàííóþ ñòîðîíó:
3955 if FDirection = D_RIGHT then
3956 FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
3957 else
3958 FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
3959 end;
3961 function TMonster.findNewPrey(): Boolean;
3962 var
3963 a: DWORD;
3964 l, l2: Integer;
3965 PlayersSee, MonstersSee: Array of DWORD;
3966 PlayerNear, MonsterNear: Integer;
3967 begin
3968 Result := False;
3969 SetLength(MonstersSee, 0);
3970 SetLength(PlayersSee, 0);
3972 FTargetUID := 0;
3973 l := 32000;
3974 PlayerNear := -1;
3975 MonsterNear := -1;
3977 // Ïîåõàâøèå, êàííèáàëû, è äîáðûå èãðîêîâ íå òðîãàþò
3978 if (gPlayers <> nil) and (FBehaviour <> BH_INSANE) and
3979 (FBehaviour <> BH_CANNIBAL) and (FBehaviour <> BH_GOOD) then
3980 for a := 0 to High(gPlayers) do
3981 if (gPlayers[a] <> nil) and (gPlayers[a].Live)
3982 and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
3983 begin
3984 if g_Look(@FObj, @gPlayers[a].Obj, FDirection) then
3985 begin
3986 SetLength(PlayersSee, Length(PlayersSee) + 1);
3987 PlayersSee[High(PlayersSee)] := a;
3988 end;
3989 l2 := Abs(gPlayers[a].GameX-FObj.X)+
3990 Abs(gPlayers[a].GameY-FObj.Y);
3991 if l2 < l then
3992 begin
3993 l := l2;
3994 PlayerNear := Integer(a);
3995 end;
3996 end;
3998 // Êèëëåðû è äîáðûå íå òðîãàþò ìîíñòðîâ
3999 if (gMonsters <> nil) and (FBehaviour <> BH_KILLER) and (FBehaviour <> BH_GOOD) then
4000 for a := 0 to High(gMonsters) do
4001 if (gMonsters[a] <> nil) and (gMonsters[a].Live) and
4002 (gMonsters[a].FUID <> FUID) then
4003 begin
4004 if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
4005 Continue; // Êàííèáàëû àòàêóþò òîëüêî ñîðîäè÷åé
4006 if (FBehaviour = BH_INSANE) and (gMonsters[a].FMonsterType <> MONSTER_BARREL)
4007 and (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
4008 Continue; // Ïîåõàâøèå íå òðîãàþò äðóçåé, íî èì íå íðàâÿòñÿ áî÷êè
4009 if ((FBehaviour = BH_NORMAL) or (FBehaviour = BH_MANIAC))
4010 and (IsFriend(gMonsters[a].FMonsterType, FMonsterType)) then
4011 Continue; // Îñòàâøèåñÿ òèïû, êðîìå êàííèáàëîâ, íå òðîãàþò ñâîèõ äðóçåé
4013 if g_Look(@FObj, @gMonsters[a].Obj, FDirection) then
4014 begin
4015 SetLength(MonstersSee, Length(MonstersSee) + 1);
4016 MonstersSee[High(MonstersSee)] := a;
4017 end;
4018 l2 := Abs(gMonsters[a].FObj.X-FObj.X)+
4019 Abs(gMonsters[a].FObj.Y-FObj.Y);
4020 if l2 < l then
4021 begin
4022 l := l2;
4023 MonsterNear := Integer(a);
4024 end;
4025 end;
4027 case FBehaviour of
4028 BH_NORMAL, BH_KILLER:
4029 begin
4030 // Îáû÷íûé è êèëëåð ñíà÷àëà èùóò èãðîêîâ â ïîëå çðåíèÿ
4031 if (FTargetUID = 0) and (Length(PlayersSee) > 0) then
4032 begin
4033 a := PlayersSee[Random(Length(PlayersSee))];
4034 FTargetUID := gPlayers[a].UID;
4035 end;
4036 // Çàòåì ïîáëèçîñòè
4037 if (FTargetUID = 0) and (PlayerNear > -1) then
4038 begin
4039 a := PlayerNear;
4040 FTargetUID := gPlayers[a].UID;
4041 end;
4042 // Ïîòîì îáû÷íûå èùóò ìîíñòðîâ â ïîëå çðåíèÿ
4043 if (FTargetUID = 0) and (Length(MonstersSee) > 0) then
4044 begin
4045 a := MonstersSee[Random(Length(MonstersSee))];
4046 FTargetUID := gMonsters[a].UID;
4047 end;
4048 // Çàòåì ïîáëèçîñòè
4049 if (FTargetUID = 0) and (MonsterNear > -1) then
4050 begin
4051 a := MonsterNear;
4052 FTargetUID := gMonsters[a].UID;
4053 end;
4054 end;
4055 BH_MANIAC, BH_INSANE, BH_CANNIBAL:
4056 begin
4057 // Ìàíüÿêè, ïîåõàâøèå è êàííèáàëû ñíà÷àëà èñòðåáëÿþò âñ¸ â ïîëå çðåíèÿ
4058 if (FTargetUID = 0) and (Length(PlayersSee) > 0) then
4059 begin
4060 a := PlayersSee[Random(Length(PlayersSee))];
4061 FTargetUID := gPlayers[a].UID;
4062 end;
4063 if (FTargetUID = 0) and (Length(MonstersSee) > 0) then
4064 begin
4065 a := MonstersSee[Random(Length(MonstersSee))];
4066 FTargetUID := gMonsters[a].UID;
4067 end;
4068 // Çàòåì èùóò êîãî-òî ïîáëèçîñòè
4069 if (FTargetUID = 0) and (PlayerNear > -1) then
4070 begin
4071 a := PlayerNear;
4072 FTargetUID := gPlayers[a].UID;
4073 end;
4074 if (FTargetUID = 0) and (MonsterNear > -1) then
4075 begin
4076 a := MonsterNear;
4077 FTargetUID := gMonsters[a].UID;
4078 end;
4079 end;
4080 end;
4082 // Åñëè è ìîíñòðîâ íåò - íà÷èíàåì æäàòü öåëü:
4083 if FTargetUID = 0 then
4084 begin
4085 // Ïîåõàâøèé ïûòàåòñÿ ñàìîóáèòüñÿ
4086 if FBehaviour = BH_INSANE then
4087 FTargetUID := FUID
4088 else
4089 FTargetTime := MAX_ATM;
4090 end
4091 else
4092 begin // Öåëü íàøëè
4093 FTargetTime := 0;
4094 Result := True;
4095 end;
4096 end;
4098 function TMonster.kick(o: PObj): Boolean;
4099 begin
4100 Result := False;
4102 case FMonsterType of
4103 MONSTER_FISH:
4104 begin
4105 SetState(MONSTATE_ATTACK);
4106 Result := True;
4107 end;
4108 MONSTER_DEMON:
4109 begin
4110 SetState(MONSTATE_ATTACK);
4111 g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ATTACK', FObj.X, FObj.Y);
4112 Result := True;
4113 end;
4114 MONSTER_IMP:
4115 begin
4116 SetState(MONSTATE_ATTACK);
4117 g_Sound_PlayExAt('SOUND_MONSTER_IMP_ATTACK', FObj.X, FObj.Y);
4118 Result := True;
4119 end;
4120 MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
4121 begin
4122 SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
4123 g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ATTACK', FObj.X, FObj.Y);
4124 Result := True;
4125 end;
4126 MONSTER_BARON, MONSTER_KNIGHT,
4127 MONSTER_CACO, MONSTER_MANCUB:
4128 // Ýòè ìîíñòðû íå ïèíàþò - îíè ñòðåëÿþò â óïîð:
4129 if not g_Game_IsClient then Result := shoot(o, True);
4130 end;
4131 end;
4133 function TMonster.shoot(o: PObj; immediately: Boolean): Boolean;
4134 var
4135 xd, yd, m: Integer;
4136 begin
4137 Result := False;
4139 // Ñòðåëÿòü ðàíî:
4140 if FAmmo < 0 then
4141 Exit;
4143 // Æäàòü âðåìåíè ãîòîâíîñòè ê âûñòðåëó:
4144 if not immediately then
4145 case FMonsterType of
4146 MONSTER_FISH, MONSTER_BARREL, MONSTER_DEMON:
4147 Exit; // íå ñòðåëÿþò
4148 MONSTER_CGUN, MONSTER_BSP, MONSTER_ROBO:
4149 begin
4150 FAmmo := FAmmo + 1;
4151 // Âðåìÿ âûñòðåëà óïóùåíî:
4152 if FAmmo >= 50 then
4153 FAmmo := IfThen(FMonsterType = MONSTER_ROBO, -200, -50);
4154 end;
4155 MONSTER_MAN: ;
4156 MONSTER_MANCUB:
4157 begin
4158 FAmmo := FAmmo + 1;
4159 // Âðåìÿ âûñòðåëà óïóùåíî:
4160 if FAmmo >= 5 then
4161 FAmmo := -50;
4162 end;
4163 MONSTER_SPIDER:
4164 begin
4165 FAmmo := FAmmo + 1;
4166 // Âðåìÿ âûñòðåëà óïóùåíî:
4167 if FAmmo >= 100 then
4168 FAmmo := -50;
4169 end;
4170 MONSTER_CYBER:
4171 begin
4172 // Ñòðåëÿåò íå âñåãäà:
4173 if Random(2) = 0 then
4174 Exit;
4175 FAmmo := FAmmo + 1;
4176 // Âðåìÿ âûñòðåëà óïóùåíî:
4177 if FAmmo >= 10 then
4178 FAmmo := -50;
4179 end;
4180 MONSTER_BARON, MONSTER_KNIGHT: if Random(8) <> 0 then Exit;
4181 MONSTER_SKEL: if Random(32) <> 0 then Exit;
4182 MONSTER_VILE: if Random(8) <> 0 then Exit;
4183 MONSTER_PAIN: if Random(8) <> 0 then Exit;
4184 else if Random(16) <> 0 then Exit;
4185 end;
4187 // Öåëè íå âèäíî:
4188 if not g_Look(@FObj, o, FDirection) then
4189 Exit;
4191 FTargetTime := 0;
4193 tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2)+((o^.Vel.X{+o^.Accel.X})*12);
4194 ty := o^.Y+o^.Rect.Y+(o^.Rect.Height div 2)+((o^.Vel.Y{+o^.Accel.Y})*12);
4196 // Ðàçíèöà ïî âûñîòå áîëüøå ðàçíèöû ïî ãîðèçîíòàëè
4197 // (íå ìîæåò ñòðåëÿòü ïîä òàêèì áîëüøèì óãëîì):
4198 if Abs(tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2))) <
4199 Abs(ty-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2))) then
4200 Exit;
4202 case FMonsterType of
4203 MONSTER_IMP, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO:
4204 begin
4205 SetState(MONSTATE_SHOOT);
4206 {nn}
4207 end;
4208 MONSTER_SKEL:
4209 begin
4210 SetState(MONSTATE_SHOOT);
4211 {nn}
4212 end;
4213 MONSTER_VILE:
4214 begin // Çàæèãàåì îãîíü
4215 tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2);
4216 ty := o^.Y+o^.Rect.Y;
4217 SetState(MONSTATE_SHOOT);
4219 vilefire.Reset();
4221 g_Sound_PlayExAt('SOUND_MONSTER_VILE_ATTACK', FObj.X, FObj.Y);
4222 g_Sound_PlayExAt('SOUND_FIRE', o^.X, o^.Y);
4223 end;
4224 MONSTER_SOUL:
4225 begin // Ëåòèò â ñòîðîíó öåëè:
4226 SetState(MONSTATE_ATTACK);
4227 g_Sound_PlayExAt('SOUND_MONSTER_SOUL_ATTACK', FObj.X, FObj.Y);
4229 xd := tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
4230 yd := ty-(FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
4231 m := Max(Abs(xd), Abs(yd));
4232 if m = 0 then
4233 m := 1;
4235 FObj.Vel.X := (xd*16) div m;
4236 FObj.Vel.Y := (yd*16) div m;
4237 end;
4238 MONSTER_MANCUB, MONSTER_ZOMBY, MONSTER_SERG, MONSTER_BSP, MONSTER_ROBO,
4239 MONSTER_CYBER, MONSTER_CGUN, MONSTER_SPIDER, MONSTER_PAIN, MONSTER_MAN:
4240 begin
4241 // Ìàíêóáóñ ðÿâêàåò ïåðåä ïåðâîé àòàêîé:
4242 if FMonsterType = MONSTER_MANCUB then
4243 if FAmmo = 1 then
4244 g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ATTACK', FObj.X, FObj.Y);
4246 SetState(MONSTATE_SHOOT);
4247 end;
4248 else Exit;
4249 end;
4251 Result := True;
4252 end;
4254 function TMonster.Live(): Boolean;
4255 begin
4256 Result := (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) and (FHealth > 0);
4257 end;
4259 procedure TMonster.SetHealth(aH: Integer);
4260 begin
4261 if (aH > 0) and (aH < 1000000) then
4262 begin
4263 FHealth := aH;
4264 if FHealth > FMaxHealth then
4265 FMaxHealth := FHealth;
4266 end;
4267 end;
4269 procedure TMonster.WakeUp();
4270 begin
4271 if g_Game_IsClient then Exit;
4272 SetState(MONSTATE_GO);
4273 FTargetTime := MAX_ATM;
4274 WakeUpSound();
4275 end;
4277 procedure TMonster.SaveState(var Mem: TBinMemoryWriter);
4278 var
4279 i: Integer;
4280 sig: DWORD;
4281 b: Byte;
4282 anim: Boolean;
4283 begin
4284 if Mem = nil then
4285 Exit;
4287 // Ñèãíàòóðà ìîíñòðà:
4288 sig := MONSTER_SIGNATURE; // 'MONS'
4289 Mem.WriteDWORD(sig);
4290 // UID ìîíñòðà:
4291 Mem.WriteWord(FUID);
4292 // Íàïðàâëåíèå:
4293 if FDirection = D_LEFT then
4294 b := 1
4295 else // D_RIGHT
4296 b := 2;
4297 Mem.WriteByte(b);
4298 // Íàäî ëè óäàëèòü åãî:
4299 Mem.WriteBoolean(FRemoved);
4300 // Îñòàëîñü çäîðîâüÿ:
4301 Mem.WriteInt(FHealth);
4302 // Ñîñòîÿíèå:
4303 Mem.WriteByte(FState);
4304 // Òåêóùàÿ àíèìàöèÿ:
4305 Mem.WriteByte(FCurAnim);
4306 // UID öåëè:
4307 Mem.WriteWord(FTargetUID);
4308 // Âðåìÿ ïîñëå ïîòåðè öåëè:
4309 Mem.WriteInt(FTargetTime);
4310 // Ïîâåäåíèå ìîíñòðà:
4311 Mem.WriteByte(FBehaviour);
4312 // Ãîòîâíîñòü ê âûñòðåëó:
4313 Mem.WriteInt(FAmmo);
4314 // Áîëü:
4315 Mem.WriteInt(FPain);
4316 // Âðåìÿ îæèäàíèÿ:
4317 Mem.WriteInt(FSleep);
4318 // Îçâó÷èâàòü ëè áîëü:
4319 Mem.WriteBoolean(FPainSound);
4320 // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè:
4321 Mem.WriteBoolean(FWaitAttackAnim);
4322 // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå:
4323 Mem.WriteBoolean(FChainFire);
4324 // Ïîäëåæèò ëè ðåñïàâíó:
4325 Mem.WriteBoolean(FNoRespawn);
4326 // Êîîðäèíàòû öåëè:
4327 Mem.WriteInt(tx);
4328 Mem.WriteInt(ty);
4329 // ID ìîíñòðà ïðè ñòàðòå êàðòû:
4330 Mem.WriteInt(FStartID);
4331 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà:
4332 Mem.WriteInt(FSpawnTrigger);
4333 // Îáúåêò ìîíñòðà:
4334 Obj_SaveState(@FObj, Mem);
4335 // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà:
4336 anim := vilefire <> nil;
4337 Mem.WriteBoolean(anim);
4338 // Åñëè åñòü - ñîõðàíÿåì:
4339 if anim then
4340 vilefire.SaveState(Mem);
4341 // Àíèìàöèè:
4342 for i := ANIM_SLEEP to ANIM_PAIN do
4343 begin
4344 // Åñòü ëè ëåâàÿ àíèìàöèÿ:
4345 anim := FAnim[i, D_LEFT] <> nil;
4346 Mem.WriteBoolean(anim);
4347 // Åñëè åñòü - ñîõðàíÿåì:
4348 if anim then
4349 FAnim[i, D_LEFT].SaveState(Mem);
4350 // Åñòü ëè ïðàâàÿ àíèìàöèÿ:
4351 anim := FAnim[i, D_RIGHT] <> nil;
4352 Mem.WriteBoolean(anim);
4353 // Åñëè åñòü - ñîõðàíÿåì:
4354 if anim then
4355 FAnim[i, D_RIGHT].SaveState(Mem);
4356 end;
4357 end;
4360 procedure TMonster.LoadState(var Mem: TBinMemoryReader);
4361 var
4362 i: Integer;
4363 sig: DWORD;
4364 b: Byte;
4365 anim: Boolean;
4366 begin
4367 if Mem = nil then
4368 Exit;
4370 // Ñèãíàòóðà ìîíñòðà:
4371 Mem.ReadDWORD(sig);
4372 if sig <> MONSTER_SIGNATURE then // 'MONS'
4373 begin
4374 raise EBinSizeError.Create('TMonster.LoadState: Wrong Monster Signature');
4375 end;
4376 if (uidMap[FUID] <> nil) and (uidMap[FUID] <> self) then raise Exception.Create('internal error in monster loader (0)');
4377 uidMap[FUID] := nil;
4378 // UID ìîíñòðà:
4379 Mem.ReadWord(FUID);
4380 //if (arrIdx = -1) then raise Exception.Create('internal error in monster loader');
4381 if (uidMap[FUID] <> nil) then raise Exception.Create('internal error in monster loader (1)');
4382 uidMap[FUID] := self;
4383 // Íàïðàâëåíèå:
4384 Mem.ReadByte(b);
4385 if b = 1 then
4386 FDirection := D_LEFT
4387 else // b = 2
4388 FDirection := D_RIGHT;
4389 // Íàäî ëè óäàëèòü åãî:
4390 Mem.ReadBoolean(FRemoved);
4391 // Îñòàëîñü çäîðîâüÿ:
4392 Mem.ReadInt(FHealth);
4393 // Ñîñòîÿíèå:
4394 Mem.ReadByte(FState);
4395 // Òåêóùàÿ àíèìàöèÿ:
4396 Mem.ReadByte(FCurAnim);
4397 // UID öåëè:
4398 Mem.ReadWord(FTargetUID);
4399 // Âðåìÿ ïîñëå ïîòåðè öåëè:
4400 Mem.ReadInt(FTargetTime);
4401 // Ïîâåäåíèå ìîíñòðà:
4402 Mem.ReadByte(FBehaviour);
4403 // Ãîòîâíîñòü ê âûñòðåëó:
4404 Mem.ReadInt(FAmmo);
4405 // Áîëü:
4406 Mem.ReadInt(FPain);
4407 // Âðåìÿ îæèäàíèÿ:
4408 Mem.ReadInt(FSleep);
4409 // Îçâó÷èâàòü ëè áîëü:
4410 Mem.ReadBoolean(FPainSound);
4411 // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè:
4412 Mem.ReadBoolean(FWaitAttackAnim);
4413 // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå:
4414 Mem.ReadBoolean(FChainFire);
4415 // Ïîäëåæèò ëè ðåñïàâíó
4416 Mem.ReadBoolean(FNoRespawn);
4417 // Êîîðäèíàòû öåëè:
4418 Mem.ReadInt(tx);
4419 Mem.ReadInt(ty);
4420 // ID ìîíñòðà ïðè ñòàðòå êàðòû:
4421 Mem.ReadInt(FStartID);
4422 // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà:
4423 Mem.ReadInt(FSpawnTrigger);
4424 // Îáúåêò ìîíñòðà:
4425 Obj_LoadState(@FObj, Mem);
4426 // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà:
4427 Mem.ReadBoolean(anim);
4428 // Åñëè åñòü - çàãðóæàåì:
4429 if anim then
4430 begin
4431 Assert(vilefire <> nil, 'TMonster.LoadState: no vilefire anim');
4432 vilefire.LoadState(Mem);
4433 end;
4434 // Àíèìàöèè:
4435 for i := ANIM_SLEEP to ANIM_PAIN do
4436 begin
4437 // Åñòü ëè ëåâàÿ àíèìàöèÿ:
4438 Mem.ReadBoolean(anim);
4439 // Åñëè åñòü - çàãðóæàåì:
4440 if anim then
4441 begin
4442 Assert(FAnim[i, D_LEFT] <> nil,
4443 'TMonster.LoadState: no '+IntToStr(i)+'_left anim');
4444 FAnim[i, D_LEFT].LoadState(Mem);
4445 end;
4446 // Åñòü ëè ïðàâàÿ àíèìàöèÿ:
4447 Mem.ReadBoolean(anim);
4448 // Åñëè åñòü - çàãðóæàåì:
4449 if anim then
4450 begin
4451 Assert(FAnim[i, D_RIGHT] <> nil,
4452 'TMonster.LoadState: no '+IntToStr(i)+'_right anim');
4453 FAnim[i, D_RIGHT].LoadState(Mem);
4454 end;
4455 end;
4456 end;
4458 procedure TMonster.ActivateTriggers();
4459 var
4460 a: Integer;
4461 begin
4462 if FDieTriggers <> nil then
4463 for a := 0 to High(FDieTriggers) do
4464 g_Triggers_Press(FDieTriggers[a], ACTIVATE_MONSTERPRESS);
4465 if FSpawnTrigger > -1 then
4466 begin
4467 g_Triggers_DecreaseSpawner(FSpawnTrigger);
4468 FSpawnTrigger := -1;
4469 end;
4470 end;
4472 procedure TMonster.AddTrigger(t: Integer);
4473 begin
4474 SetLength(FDieTriggers, Length(FDieTriggers)+1);
4475 FDieTriggers[High(FDieTriggers)] := t;
4476 end;
4478 procedure TMonster.ClearTriggers();
4479 begin
4480 SetLength(FDieTriggers, 0);
4481 end;
4483 procedure TMonster.CatchFire(Attacker: Word);
4484 begin
4485 FFireTime := 100;
4486 FFireAttacker := Attacker;
4487 if g_Game_IsNet and g_Game_IsServer then MH_SEND_MonsterState(FUID);
4488 end;
4490 procedure TMonster.OnFireFlame(Times: DWORD = 1);
4491 var
4492 id, i: DWORD;
4493 Anim: TAnimation;
4494 begin
4495 if (Random(10) = 1) and (Times = 1) then
4496 Exit;
4498 if g_Frames_Get(id, 'FRAMES_FLAME') then
4499 begin
4500 for i := 1 to Times do
4501 begin
4502 Anim := TAnimation.Create(id, False, 3);
4503 Anim.Alpha := 0;
4504 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
4505 Obj.Y+8+Random(8+Times*2)+IfThen(FState = MONSTATE_DEAD, 16, 0), Anim, ONCEANIM_SMOKE);
4506 Anim.Free();
4507 end;
4508 end;
4509 end;
4512 // ////////////////////////////////////////////////////////////////////////// //
4513 // throws on invalid uid
4514 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
4515 begin
4516 result := g_Mons_ByIdx_NC(uid);
4517 if (result = nil) then raise Exception.Create('g_Mons_ByIdx: invalid monster id');
4518 end;
4520 // can return null
4521 function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
4522 begin
4523 if (uid < 0) or (uid > High(gMonsters)) then begin result := nil; exit; end;
4524 result := gMonsters[uid];
4525 end;
4527 function g_Mons_TotalCount (): Integer; inline;
4528 begin
4529 result := Length(gMonsters);
4530 end;
4533 function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
4534 var
4535 idx: Integer;
4536 mon: TMonster;
4537 begin
4538 result := false;
4539 if (gMonsters = nil) or not assigned(cb) then exit;
4540 for idx := 0 to High(gMonsters) do
4541 begin
4542 mon := gMonsters[idx];
4543 if (mon <> nil) then
4544 begin
4545 result := cb(mon);
4546 if result then exit;
4547 end;
4548 end;
4549 end;
4552 function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
4553 var
4554 idx: Integer;
4555 mon: TMonster;
4556 begin
4557 result := false;
4558 if (gMonsters = nil) or not assigned(cb) then exit;
4559 for idx := 0 to High(gMonsters) do
4560 begin
4561 mon := gMonsters[idx];
4562 if (mon <> nil) and mon.Live then
4563 begin
4564 result := cb(mon);
4565 if result then exit;
4566 end;
4567 end;
4568 end;
4571 function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
4573 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4574 begin
4575 result := mon.Live;// and g_Obj_Collide(x, y, width, height, @mon.Obj));
4576 end;
4578 var
4579 idx: Integer;
4580 mon: TMonster;
4581 begin
4582 result := false;
4583 if (width < 1) or (height < 1) then exit;
4584 if gmon_debug_use_sqaccel then
4585 begin
4586 result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4587 end
4588 else
4589 begin
4590 for idx := 0 to High(gMonsters) do
4591 begin
4592 mon := gMonsters[idx];
4593 if (mon <> nil) and mon.Live then
4594 begin
4595 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4596 begin
4597 result := true;
4598 exit;
4599 end;
4600 end;
4601 end;
4602 end;
4603 end;
4606 function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
4608 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4609 begin
4610 result := cb(mon);
4611 end;
4613 var
4614 idx: Integer;
4615 mon: TMonster;
4616 begin
4617 result := false;
4618 if (width < 1) or (height < 1) then exit;
4619 if gmon_debug_use_sqaccel then
4620 begin
4621 result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4622 end
4623 else
4624 begin
4625 for idx := 0 to High(gMonsters) do
4626 begin
4627 mon := gMonsters[idx];
4628 if (mon <> nil) and mon.Live then
4629 begin
4630 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4631 begin
4632 result := cb(mon);
4633 if result then exit;
4634 end;
4635 end;
4636 end;
4637 end;
4638 end;
4641 function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
4643 function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
4644 begin
4645 //result := false;
4646 //if mon.Live and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
4647 if mon.Live then result := cb(mon) else result := false;
4648 end;
4650 var
4651 idx: Integer;
4652 mon: TMonster;
4653 begin
4654 result := false;
4655 if (width < 1) or (height < 1) then exit;
4656 if gmon_debug_use_sqaccel then
4657 begin
4658 if (width = 1) and (height = 1) then
4659 begin
4660 result := (monsGrid.forEachAtPoint(x, y, monsCollCheck) <> nil);
4661 end
4662 else
4663 begin
4664 result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
4665 end;
4666 end
4667 else
4668 begin
4669 for idx := 0 to High(gMonsters) do
4670 begin
4671 mon := gMonsters[idx];
4672 if (mon <> nil) and mon.Live then
4673 begin
4674 if g_Obj_Collide(x, y, width, height, @mon.Obj) then
4675 begin
4676 result := cb(mon);
4677 if result then exit;
4678 end;
4679 end;
4680 end;
4681 end;
4682 end;
4685 end.