X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fgame%2Fg_monsters.pas;h=bb3d293ded57dc0413327ff01394b2a2055f41f8;hb=38ffc69cb8386eb4f610ad5838e776ac04c6c297;hp=2d6daf6c9de719bd9fed2b43f9c8025dfa9ec14c;hpb=94a927ca673a2d8af4b8449d434f3c70f38b11c1;p=d2df-sdl.git diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index 2d6daf6..bb3d293 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -1,4 +1,4 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* Copyright (C) Doom 2D: Forever Developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,7 +50,8 @@ const } type - TMonster = class(TPoolObject) + PMonster = ^TMonster; + TMonster = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private FMonsterType: Byte; FUID: Word; @@ -62,7 +63,7 @@ type FMaxHealth: Integer; FState: Byte; FCurAnim: Byte; - FAnim: Array of Array [D_LEFT..D_RIGHT] of TAnimation; + FAnim: Array of Array [TDirection.D_LEFT..TDirection.D_RIGHT] of TAnimation; FTargetUID: Word; FTargetTime: Integer; FBehaviour: Byte; @@ -238,8 +239,8 @@ procedure g_Monsters_killedp (); procedure g_Monsters_SaveState (st: TStream); procedure g_Monsters_LoadState (st: TStream); -function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload; -function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload; +function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload; +function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload; function g_Mons_TypeLo (): Integer; inline; function g_Mons_TypeHi (): Integer; inline; @@ -272,10 +273,12 @@ function g_Mons_getNewTrapFrameId (): DWord; inline; function g_Mons_getNewMPlatFrameId (): LongWord; inline; +{ type TMonsAlongLineCB = function (mon: TMonster; tag: Integer): Boolean is nested; function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster; +} var @@ -363,11 +366,13 @@ procedure TMonster.setDirty (); inline; begin mNeedSend := true; end; // ////////////////////////////////////////////////////////////////////////// // +{ function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster; begin if not assigned(cb) then begin result := nil; exit; end; result := monsGrid.forEachAlongLine(x0, y0, x1, y1, cb, -1, log); end; +} //WARNING! call this after monster position was changed, or coldet will not work right! @@ -534,11 +539,11 @@ const 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)); 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))), - (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //ZOMBY + (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //ZOMBY 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)); 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))), - (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //SERG + (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //SERG 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)); 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))), @@ -757,6 +762,7 @@ end; function isCorpse (o: PObj; immediately: Boolean): Integer; + (* function monsCollCheck (mon: TMonster; atag: Integer): Boolean; begin atag := atag; // shut up, fpc! @@ -771,10 +777,13 @@ function isCorpse (o: PObj; immediately: Boolean): Integer; result := true; end; end; + *) var a: Integer; - mon: TMonster; + mon: PMonster; + mres: TMonster = nil; + it: TMonsterGrid.Iter; begin result := -1; @@ -784,8 +793,21 @@ begin // Èùåì ìåðòâûõ ìîíñòðîâ ïîáëèçîñòè if gmon_debug_use_sqaccel then begin - mon := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height, monsCollCheck); - if (mon <> nil) then result := mon.mArrIdx; + //mon := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height, monsCollCheck); + //if (mon <> nil) then result := mon.mArrIdx; + it := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height); + for mon in it do + begin + case mon.FMonsterType of // Íå âîñêðåñèòü: + MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER, + MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: begin end; + // Îñòàëüíûõ ìîæíî âîñêðåñèòü + else mres := mon^; + end; + if (mres <> nil) then break; + end; + it.release(); + if (mres <> nil) then result := mres.mArrIdx; end else begin @@ -809,7 +831,7 @@ end; procedure g_Monsters_LoadData(); begin - e_WriteLog('Loading monsters data...', MSG_NOTIFY); + e_WriteLog('Loading monsters data...', TMsgType.Notify); g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 0%', 0, False); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_SLEEP', GameWAD+':MTEXTURES\BARREL_SLEEP', 64, 64, 3); @@ -821,6 +843,7 @@ begin g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 5%', 0, True); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_MESS', GameWAD+':MTEXTURES\ZOMBY_MESS', 64, 64, 9); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK', GameWAD+':MTEXTURES\ZOMBY_ATTACK', 64, 64, 2); + g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK_L', GameWAD+':MTEXTURES\ZOMBY_ATTACK_L', 64, 64, 2); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_PAIN', GameWAD+':MTEXTURES\ZOMBY_PAIN', 64, 64, 1); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_SLEEP', GameWAD+':MTEXTURES\SERG_SLEEP', 64, 64, 2); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_GO', GameWAD+':MTEXTURES\SERG_GO', 64, 64, 4); @@ -828,6 +851,7 @@ begin g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 10%', 0, True); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_MESS', GameWAD+':MTEXTURES\SERG_MESS', 64, 64, 9); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK', GameWAD+':MTEXTURES\SERG_ATTACK', 64, 64, 2); + g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK_L', GameWAD+':MTEXTURES\SERG_ATTACK_L', 64, 64, 2); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_PAIN', GameWAD+':MTEXTURES\SERG_PAIN', 64, 64, 1); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_SLEEP', GameWAD+':MTEXTURES\MAN_SLEEP', 64, 64, 2); g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_GO', GameWAD+':MTEXTURES\MAN_GO', 64, 64, 4); @@ -1053,7 +1077,7 @@ end; procedure g_Monsters_FreeData(); begin - e_WriteLog('Releasing monsters data...', MSG_NOTIFY); + e_WriteLog('Releasing monsters data...', TMsgType.Notify); g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_SLEEP'); g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_PAIN'); @@ -1063,12 +1087,14 @@ begin g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_DIE'); g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_MESS'); g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK'); + g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK_L'); g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_PAIN'); g_Frames_DeleteByName('FRAMES_MONSTER_SERG_SLEEP'); g_Frames_DeleteByName('FRAMES_MONSTER_SERG_GO'); g_Frames_DeleteByName('FRAMES_MONSTER_SERG_DIE'); g_Frames_DeleteByName('FRAMES_MONSTER_SERG_MESS'); g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK'); + g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK_L'); g_Frames_DeleteByName('FRAMES_MONSTER_SERG_PAIN'); g_Frames_DeleteByName('FRAMES_MONSTER_MAN_SLEEP'); g_Frames_DeleteByName('FRAMES_MONSTER_MAN_GO'); @@ -1523,7 +1549,7 @@ begin // Òèï ìîíñòðà b := utils.readByte(st); // Ñîçäàåì ìîíñòðà - mon := g_Monsters_Create(b, 0, 0, D_LEFT); + mon := g_Monsters_Create(b, 0, 0, TDirection.D_LEFT); if (mon = nil) then raise XStreamError.Create('g_Monsters_LoadState: ID = -1 (can''t create)'); // Çàãðóæàåì äàííûå ìîíñòðà mon.LoadState(st); @@ -1532,7 +1558,7 @@ end; // ////////////////////////////////////////////////////////////////////////// // -function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload; +function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload; begin result := nil; if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then @@ -1542,7 +1568,7 @@ begin end; -function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload; +function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload; begin result := g_Mons_SpawnAt(g_Mons_TypeIdByName(typeName), x, y, dir); end; @@ -1897,8 +1923,8 @@ begin for a := 0 to High(FAnim) do begin - FAnim[a, D_LEFT] := nil; - FAnim[a, D_RIGHT] := nil; + FAnim[a, TDirection.D_LEFT] := nil; + FAnim[a, TDirection.D_RIGHT] := nil; end; for a := ANIM_SLEEP to ANIM_PAIN do @@ -1923,15 +1949,15 @@ begin if g_Frames_Get(FramesID, 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+ '_'+ANIMTABLE[ANIM_DIE].name) then begin - FAnim[a, D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop, + FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop, MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]); - FAnim[a, D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop, + FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop, MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]); Continue; end; end; - FAnim[a, D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop, + FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop, MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]); // Åñëè åñòü îòäåëüíàÿ ëåâàÿ àíèìàöèÿ - çàãðóæàåì: @@ -1943,7 +1969,7 @@ begin g_Frames_Get(FramesID, s); end; - FAnim[a, D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop, + FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop, MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]); end; @@ -1972,10 +1998,7 @@ begin if (t = HIT_ELECTRO) and (FMonsterType = MONSTER_FISH) and g_Game_IsServer then begin FSleep := 20; - if Random(2) = 0 then - FDirection := D_RIGHT - else - FDirection := D_LEFT; + if Random(2) = 0 then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT; Result := True; SetState(MONSTATE_RUN); Exit; @@ -2138,8 +2161,8 @@ var begin for a := 0 to High(FAnim) do begin - FAnim[a, D_LEFT].Free(); - FAnim[a, D_RIGHT].Free(); + FAnim[a, TDirection.D_LEFT].Free(); + FAnim[a, TDirection.D_RIGHT].Free(); end; vilefire.Free(); @@ -2182,7 +2205,7 @@ begin if FState = MONSTATE_SHOOT then if GetPos(FTargetUID, @o) then vilefire.Draw(o.X+o.Rect.X+(o.Rect.Width div 2)-32, - o.Y+o.Rect.Y+o.Rect.Height-128, M_NONE); + o.Y+o.Rect.Y+o.Rect.Height-128, TMirrorType.None); // Íå â îáëàñòè ðèñîâàíèÿ íå ðåñóåì: //FIXME! @@ -2203,22 +2226,22 @@ begin if FAnim[FCurAnim, FDirection] <> nil then begin // Åñëè íåò ëåâîé àíèìàöèè èëè îíà ñîâïàäàåò ñ ïðàâîé => îòðàæàåì ïðàâóþ: - if (FDirection = D_LEFT) and + if (FDirection = TDirection.D_LEFT) and ((not MONSTER_ANIMTABLE[FMonsterType].LeftAnim) or - (FAnim[FCurAnim, D_LEFT].FramesID = FAnim[FCurAnim, D_RIGHT].FramesID)) and + (FAnim[FCurAnim, TDirection.D_LEFT].FramesID = FAnim[FCurAnim, TDirection.D_RIGHT].FramesID)) and (FMonsterType <> MONSTER_BARREL) then - m := M_HORIZONTAL + m := TMirrorType.Horizontal else - m := M_NONE; + m := TMirrorType.None; // Ëåâàÿ àíèìàöèÿ => ìåíÿåì ñìåùåíèå îòíîñèòåëüíî öåíòðà: - if (FDirection = D_LEFT) and + if (FDirection = TDirection.D_LEFT) and (FMonsterType <> MONSTER_BARREL) then begin dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].X; dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].Y; - if m = M_HORIZONTAL then + if m = TMirrorType.Horizontal then begin // Íåò îòäåëüíîé ëåâîé àíèìàöèè // Ðàññòîÿíèå îò êðàÿ òåêñòóðû äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå: c := (MONSTERTABLE[FMonsterType].Rect.X - dx) + MONSTERTABLE[FMonsterType].Rect.Width; @@ -2371,17 +2394,17 @@ begin positionChanged(); if dir = 1 then - FDirection := D_LEFT + FDirection := TDirection.D_LEFT else if dir = 2 then - FDirection := D_RIGHT + FDirection := TDirection.D_RIGHT else if dir = 3 then begin // îáðàòíîå - if FDirection = D_RIGHT then - FDirection := D_LEFT + if FDirection = TDirection.D_RIGHT then + FDirection := TDirection.D_LEFT else - FDirection := D_RIGHT; + FDirection := TDirection.D_RIGHT; end; // Ýôôåêò òåëåïîðòà â òî÷êå íàçíà÷åíèÿ: @@ -2720,9 +2743,9 @@ begin // Ïîâîðà÷èâàåìñÿ â ñòîðîíó öåëè: if sx > 0 then - FDirection := D_RIGHT + FDirection := TDirection.D_RIGHT else - FDirection := D_LEFT; + FDirection := TDirection.D_LEFT; // Åñëè ìîíñòð óìååò ñòðåëÿòü è åñòü ïî êîìó - ñòðåëÿåì: if canShoot(FMonsterType) and (FTargetUID <> 0) then @@ -2737,9 +2760,9 @@ begin FSleep := 15; SetState(MONSTATE_RUN); if Random(2) = 0 then - FDirection := D_LEFT + FDirection := TDirection.D_LEFT else - FDirection := D_RIGHT; + FDirection := TDirection.D_RIGHT; goto _end; end; @@ -2806,9 +2829,9 @@ begin FObj.Vel.Y := 0; // Ïëàâàåì òóäà-ñþäà: if Random(2) = 0 then - FDirection := D_LEFT + FDirection := TDirection.D_LEFT else - FDirection := D_RIGHT; + FDirection := TDirection.D_RIGHT; FSleep := 20; SetState(MONSTATE_RUN); end; @@ -2886,7 +2909,7 @@ begin end; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -2927,7 +2950,7 @@ begin end; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -2962,7 +2985,7 @@ begin end; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -2994,7 +3017,7 @@ begin end; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -3084,7 +3107,7 @@ _end: if (FMonsterType = MONSTER_PAIN) then begin mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-30, - FObj.Y+FObj.Rect.Y+20, D_LEFT); + FObj.Y+FObj.Rect.Y+20, TDirection.D_LEFT); if mon <> nil then begin mon.SetState(MONSTATE_GO); @@ -3094,7 +3117,7 @@ _end: end; mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2), - FObj.Y+FObj.Rect.Y+20, D_RIGHT); + FObj.Y+FObj.Rect.Y+20, TDirection.D_RIGHT); if mon <> nil then begin mon.SetState(MONSTATE_GO); @@ -3104,7 +3127,7 @@ _end: end; mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-15, - FObj.Y+FObj.Rect.Y, D_RIGHT); + FObj.Y+FObj.Rect.Y, TDirection.D_RIGHT); if mon <> nil then begin mon.SetState(MONSTATE_GO); @@ -3183,7 +3206,7 @@ _end: if FCurAnim = ANIM_ATTACK2 then begin o := FObj; - o.Vel.X := IfThen(FDirection = D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50); + o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50); if g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME) <> 0 then g_Sound_PlayExAt('SOUND_MONSTER_SKEL_HIT', FObj.X, FObj.Y); end; @@ -3209,7 +3232,7 @@ _end: // Âû÷èñëÿåì êîîðäèíàòû, îòêóäà âûëåòèò ïóëÿ: wx := MONSTER_ANIMTABLE[FMonsterType].wX; - if FDirection = D_LEFT then + if FDirection = TDirection.D_LEFT then begin wx := MONSTER_ANIMTABLE[FMonsterType].wX-(MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2)); wx := MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2)-wx; @@ -3225,7 +3248,7 @@ _end: MONSTER_ZOMBY: begin g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy); - g_Weapon_gun(wx, wy, tx, ty, 1, 3, FUID, False); + g_Weapon_gun(wx, wy, tx, ty, 1, 3, FUID, True); g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET); end; MONSTER_SERG: @@ -3713,7 +3736,7 @@ begin end; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -3751,7 +3774,7 @@ begin end; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -3784,7 +3807,7 @@ begin end; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -3815,7 +3838,7 @@ begin end; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -3963,7 +3986,7 @@ _end: if FCurAnim = ANIM_ATTACK2 then begin o := FObj; - o.Vel.X := IfThen(FDirection = D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50); + o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50); g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME); end; @@ -4084,13 +4107,10 @@ end; procedure TMonster.Turn(); begin // Ðàçâîðà÷èâàåìñÿ: - if FDirection = D_LEFT then - FDirection := D_RIGHT - else - FDirection := D_LEFT; + if FDirection = TDirection.D_LEFT then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT; // Áåæèì â âûáðàííóþ ñòîðîíó: - if FDirection = D_RIGHT then + if FDirection = TDirection.D_RIGHT then FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel else FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel; @@ -4426,7 +4446,7 @@ begin // UID ìîíñòðà: utils.writeInt(st, Word(FUID)); // Íàïðàâëåíèå - if FDirection = D_LEFT then b := 1 else b := 2; // D_RIGHT + if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT utils.writeInt(st, Byte(b)); // Íàäî ëè óäàëèòü åãî utils.writeBool(st, FRemoved); @@ -4474,15 +4494,15 @@ begin for i := ANIM_SLEEP to ANIM_PAIN do begin // Åñòü ëè ëåâàÿ àíèìàöèÿ - anim := (FAnim[i, D_LEFT] <> nil); + anim := (FAnim[i, TDirection.D_LEFT] <> nil); utils.writeBool(st, anim); // Åñëè åñòü - ñîõðàíÿåì - if anim then FAnim[i, D_LEFT].SaveState(st); + if anim then FAnim[i, TDirection.D_LEFT].SaveState(st); // Åñòü ëè ïðàâàÿ àíèìàöèÿ - anim := (FAnim[i, D_RIGHT] <> nil); + anim := (FAnim[i, TDirection.D_RIGHT] <> nil); utils.writeBool(st, anim); // Åñëè åñòü - ñîõðàíÿåì - if anim then FAnim[i, D_RIGHT].SaveState(st); + if anim then FAnim[i, TDirection.D_RIGHT].SaveState(st); end; end; @@ -4507,7 +4527,7 @@ begin uidMap[FUID] := self; // Íàïðàâëåíèå b := utils.readByte(st); - if b = 1 then FDirection := D_LEFT else FDirection := D_RIGHT; // b = 2 + if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2 // Íàäî ëè óäàëèòü åãî FRemoved := utils.readBool(st); // Îñòàëîñü çäîðîâüÿ @@ -4561,16 +4581,16 @@ begin // Åñëè åñòü - çàãðóæàåì if anim then begin - Assert(FAnim[i, D_LEFT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_left anim'); - FAnim[i, D_LEFT].LoadState(st); + Assert(FAnim[i, TDirection.D_LEFT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_left anim'); + FAnim[i, TDirection.D_LEFT].LoadState(st); end; // Åñòü ëè ïðàâàÿ àíèìàöèÿ anim := utils.readBool(st); // Åñëè åñòü - çàãðóæàåì if anim then begin - Assert(FAnim[i, D_RIGHT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_right anim'); - FAnim[i, D_RIGHT].LoadState(st); + Assert(FAnim[i, TDirection.D_RIGHT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_right anim'); + FAnim[i, TDirection.D_RIGHT].LoadState(st); end; end; end; @@ -4690,21 +4710,26 @@ end; function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean; - + (* function monsCollCheck (mon: TMonster; atag: Integer): Boolean; begin result := mon.alive;// and g_Obj_Collide(x, y, width, height, @mon.Obj)); end; - + *) var idx: Integer; mon: TMonster; + mit: PMonster; + it: TMonsterGrid.Iter; begin result := false; if (width < 1) or (height < 1) then exit; if gmon_debug_use_sqaccel then begin - result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil); + //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil); + it := monsGrid.forEachInAABB(x, y, width, height); + for mit in it do if (mit.alive) then begin result := true; break; end; + it.release(); end else begin @@ -4725,21 +4750,26 @@ end; function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean; - + (* function monsCollCheck (mon: TMonster; atag: Integer): Boolean; begin result := cb(mon); end; - + *) var idx: Integer; mon: TMonster; + mit: PMonster; + it: TMonsterGrid.Iter; begin result := false; if (width < 1) or (height < 1) then exit; if gmon_debug_use_sqaccel then begin - result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil); + //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil); + it := monsGrid.forEachInAABB(x, y, width, height); + for mit in it do if (cb(mit^)) then begin result := true; break; end; + it.release(); end else begin @@ -4760,22 +4790,25 @@ end; function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean; - + (* function monsCollCheck (mon: TMonster; atag: Integer): Boolean; begin //result := false; //if mon.alive and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon); if mon.alive then result := cb(mon) else result := false; end; - + *) var idx: Integer; mon: TMonster; + mit: PMonster; + it: TMonsterGrid.Iter; begin result := false; if (width < 1) or (height < 1) then exit; if gmon_debug_use_sqaccel then begin + { if (width = 1) and (height = 1) then begin result := (monsGrid.forEachAtPoint(x, y, monsCollCheck) <> nil); @@ -4784,6 +4817,16 @@ begin begin result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil); end; + } + it := monsGrid.forEachInAABB(x, y, width, height); + for mit in it do + begin + if (mit^.alive) then + begin + if (cb(mit^)) then begin result := true; break; end; + end; + end; + it.release(); end else begin