1 (* Copyright (C) DooM 2D:Forever Developers
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.
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.
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/>.
22 g_textures
, g_basic
, g_weapons
, e_graphics
, wadreader
;
59 TModelSoundArray
= Array of TModelSound
;
60 TGibsArray
= Array of TGibSprite
;
61 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
] of
62 Array [A_STAND
..A_PAIN
] of
63 Array [D_LEFT
..D_RIGHT
] of Array of TPoint
;
65 TPlayerModel
= class (TObject
)
68 FDirection
: TDirection
;
70 FCurrentAnimation
: Byte;
71 FAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_PAIN
] of TAnimation
;
72 FMaskAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_PAIN
] of TAnimation
;
73 FWeaponPoints
: TWeaponPoints
;
74 FPainSounds
: TModelSoundArray
;
75 FDieSounds
: TModelSoundArray
;
82 FFlagAnim
: TAnimation
;
87 destructor Destroy(); override;
88 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
89 function GetCurrentAnimation
: TAnimation
;
90 function GetCurrentAnimationMask
: TAnimation
;
91 procedure SetColor(Red
, Green
, Blue
: Byte);
92 procedure SetWeapon(Weapon
: Byte);
93 procedure SetFlag(Flag
: Byte);
94 procedure SetFire(Fire
: Boolean);
95 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
97 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
99 property Fire
: Boolean read FFire
;
100 property Direction
: TDirection read FDirection write FDirection
;
101 property Animation
: Byte read FCurrentAnimation
;
102 property Weapon
: Byte read FCurrentWeapon
;
103 property Name
: String read FName
;
104 property Color
: TRGB read FColor write FColor
;
107 procedure g_PlayerModel_LoadData();
108 procedure g_PlayerModel_FreeData();
109 function g_PlayerModel_Load(FileName
: String): Boolean;
110 function g_PlayerModel_GetNames(): SArray
;
111 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
112 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
113 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
114 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
119 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
120 GL
, GLExt
, e_sound
, g_options
, g_map
, Math
, e_log
;
123 TPlayerModelInfo
= record
125 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
128 WeaponPoints
: TWeaponPoints
;
130 PainSounds
: TModelSoundArray
;
131 DieSounds
: TModelSoundArray
;
143 FLAG_BASEPOINT
: TPoint
= (X
:16; Y
:43);
144 FLAG_DEFPOINT
: TPoint
= (X
:32; Y
:16);
146 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TPoint
=
147 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
148 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16));
150 AnimNames
: Array [A_STAND
..A_PAIN
] of String =
151 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
152 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim');
153 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
154 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl');
157 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
158 Array [W_POS_NORMAL
..W_POS_DOWN
] of
159 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
160 PlayerModelsArray
: Array of TPlayerModelInfo
;
162 procedure g_PlayerModel_LoadData();
166 for a
:= WP_FIRST
+ 1 to WP_LAST
do
168 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
169 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
170 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
171 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
172 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
173 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
177 function GetPoint(var str
: String; var point
: TPoint
): Boolean;
187 if Length(str
) < 3 then
190 for a
:= 1 to Length(str
) do
191 if (str
[a
] = ',') or (a
= Length(str
)) then
193 s
:= Copy(str
, 1, a
);
194 if s
[Length(s
)] = ',' then
195 SetLength(s
, Length(s
)-1);
198 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
199 (x
< -64) or (x
> 128) or
200 (y
< -64) or (y
> 128) then
212 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
213 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
222 backanim
:= backanim
and (frames
> 2);
224 for a
:= 1 to frames
do
226 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
229 with wpoints
[weapon
, anim
, dir
, a
-1] do
231 X
:= X
- WEAPONBASE
[weapon
].X
;
232 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
238 h
:= High(wpoints
[weapon
, anim
, dir
]);
240 for b
:= h
downto frames
do
241 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
246 function g_PlayerModel_Load(FileName
: string): Boolean;
249 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
252 pData
, pData2
: Pointer;
258 e_WriteLog(Format('Loading player model: %s', [ExtractFileName(FileName
)]), MSG_NOTIFY
);
262 WAD
:= TWADFile
.Create
;
263 WAD
.ReadFile(FileName
);
265 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
271 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
277 config
:= TConfig
.CreateMem(pData
, len
);
280 s
:= config
.ReadStr('Model', 'name', '');
288 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
289 ID
:= High(PlayerModelsArray
);
291 prefix
:= FileName
+':TEXTURES\';
293 with PlayerModelsArray
[ID
].Info
do
296 Author
:= config
.ReadStr('Model', 'author', '');
297 Description
:= config
.ReadStr('Model', 'description', '');
300 for b
:= A_STAND
to A_PAIN
do
302 if not (g_Frames_CreateWAD(nil, s
+'_RIGHTANIM'+IntToStr(b
),
303 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
304 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
305 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
306 g_Frames_CreateWAD(nil, s
+'_RIGHTANIM'+IntToStr(b
)+'_MASK',
307 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
308 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
309 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
316 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
317 for bb
:= A_STAND
to A_PAIN
do
318 for cc
:= D_LEFT
to D_RIGHT
do
320 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
321 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
322 if f
> 2 then f
:= 2*f
-2;
323 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
326 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
327 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
329 g_Frames_CreateWAD(nil, s
+'_LEFTANIM'+IntToStr(b
),
330 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
331 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
332 config
.ReadBool(AnimNames
[b
], 'backanim', False));
334 g_Frames_CreateWAD(nil, s
+'_LEFTANIM'+IntToStr(b
)+'_MASK',
335 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
336 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
337 config
.ReadBool(AnimNames
[b
], 'backanim', False));
340 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
343 with PlayerModelsArray
[ID
], config
do
345 prefix
:= FileName
+':SOUNDS\';
349 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
352 SetLength(PainSounds
, Length(PainSounds
)+1);
353 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
354 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
361 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
364 SetLength(DieSounds
, Length(DieSounds
)+1);
365 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
366 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
371 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
373 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
376 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
377 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
379 for a
:= 0 to High(Gibs
) do
380 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
381 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
383 Gibs
[a
].Rect
:= e_GetTextureSize2(Gibs
[a
].ID
);
385 if Height
> 3 then Height
:= Height
-1-Random(2);
386 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
394 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
395 for bb
:= A_STAND
to A_PAIN
do
396 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
398 ok
:= ok
and GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, D_RIGHT
,
399 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
400 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
403 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, D_LEFT
,
404 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
405 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
407 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
409 WeaponPoints
[aa
, bb
, D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
;
410 WeaponPoints
[aa
, bb
, D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
;
413 if not ok
then Break
;
415 {if ok then g_Console_Add(Info.Name+' weapon points ok')
416 else g_Console_Add(Info.Name+' weapon points fail');}
417 Info
.HaveWeapon
:= ok
;
419 s
:= config
.ReadStr('Model', 'flag_point', '');
420 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
422 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
431 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
439 if PlayerModelsArray
= nil then Exit
;
441 for a
:= 0 to High(PlayerModelsArray
) do
442 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
444 Result
:= TPlayerModel
.Create
;
446 with PlayerModelsArray
[a
] do
448 Result
.FName
:= Info
.Name
;
450 for b
:= A_STAND
to A_PAIN
do
452 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
453 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
460 Result
.FAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
462 Result
.FMaskAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
464 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
465 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
466 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
467 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
469 Result
.FAnim
[D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
471 Result
.FMaskAnim
[D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
474 Result
.FPainSounds
:= PainSounds
;
475 Result
.FDieSounds
:= DieSounds
;
476 Result
.FSlopSound
:= SlopSound
;
479 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
480 Result
.FWeaponPoints
:= WeaponPoints
;
482 Result
.FFlagPoint
:= FlagPoint
;
483 Result
.FFlagAngle
:= FlagAngle
;
490 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
498 if PlayerModelsArray
= nil then Exit
;
499 for a
:= 0 to High(PlayerModelsArray
) do
500 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
501 with PlayerModelsArray
[a
] do
503 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
505 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
506 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
508 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
509 _Anim
.Speed
:= ModelSpeed
[Anim
];
511 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
512 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
514 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
515 _Mask
.Speed
:= ModelSpeed
[Anim
];
523 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
530 if PlayerModelsArray
= nil then Exit
;
531 if gGibsCount
= 0 then Exit
;
535 SetLength(Gibs
, gGibsCount
);
537 for a
:= 0 to High(PlayerModelsArray
) do
538 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
540 for i
:= 0 to High(Gibs
) do
542 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
549 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
550 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
552 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
554 if Gibs
[i
].OnlyOne
then c
:= True;
562 function g_PlayerModel_GetNames(): SArray
;
568 if PlayerModelsArray
= nil then Exit
;
570 for i
:= 0 to High(PlayerModelsArray
) do
572 SetLength(Result
, Length(Result
)+1);
573 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
577 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
581 FillChar(Result
, SizeOf(Result
), 0);
582 if PlayerModelsArray
= nil then Exit
;
584 for a
:= 0 to High(PlayerModelsArray
) do
585 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
587 Result
:= PlayerModelsArray
[a
].Info
;
592 procedure g_PlayerModel_FreeData();
597 for a
:= WP_FIRST
+ 1 to WP_LAST
do
598 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
599 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
600 e_DeleteTexture(WeaponID
[a
][b
][c
]);
602 e_WriteLog('Releasing models...', MSG_NOTIFY
);
604 if PlayerModelsArray
= nil then Exit
;
606 for i
:= 0 to High(PlayerModelsArray
) do
607 with PlayerModelsArray
[i
] do
609 for a
:= A_STAND
to A_PAIN
do
611 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
612 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
613 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
614 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
617 if PainSounds
<> nil then
618 for b
:= 0 to High(PainSounds
) do
619 e_DeleteSound(PainSounds
[b
].ID
);
621 if DieSounds
<> nil then
622 for b
:= 0 to High(DieSounds
) do
623 e_DeleteSound(DieSounds
[b
].ID
);
626 for b
:= 0 to High(Gibs
) do
628 e_DeleteTexture(Gibs
[b
].ID
);
629 e_DeleteTexture(Gibs
[b
].MaskID
);
633 PlayerModelsArray
:= nil;
638 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
640 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
642 FCurrentAnimation
:= Animation
;
644 if (FDirection
= D_LEFT
) and
645 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) and
646 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
648 FAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
649 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
653 FAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
654 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
658 destructor TPlayerModel
.Destroy();
662 for a
:= A_STAND
to A_PAIN
do
664 FAnim
[D_LEFT
][a
].Free();
665 FMaskAnim
[D_LEFT
][a
].Free();
666 FAnim
[D_RIGHT
][a
].Free();
667 FMaskAnim
[D_RIGHT
][a
].Free();
673 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
680 if Direction
= D_LEFT
then
683 Mirror
:= M_HORIZONTAL
;
685 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
686 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
688 p
.X
:= IfThen(Direction
= D_LEFT
,
690 64-FLAG_BASEPOINT
.X
);
691 p
.Y
:= FLAG_BASEPOINT
.Y
;
693 FFlagAnim
.DrawEx(X
+IfThen(Direction
= D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
694 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
695 IfThen(FDirection
= D_RIGHT
, FFlagAngle
, -FFlagAngle
));
699 if Direction
= D_RIGHT
then
702 Mirror
:= M_HORIZONTAL
;
705 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
706 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
708 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
711 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
716 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
723 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
724 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
725 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
726 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
727 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
728 0, True, False, Mirror
);
732 if (FDirection
= D_LEFT
) and
733 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
735 FAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
736 FAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
740 FAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
741 FAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
747 if (FDirection
= D_LEFT
) and
748 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
750 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
751 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
755 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
756 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
764 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
766 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
767 Result
:= FAnim
[D_LEFT
][FCurrentAnimation
]
769 Result
:= FAnim
[D_RIGHT
][FCurrentAnimation
];
772 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
774 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
775 Result
:= FMaskAnim
[D_LEFT
][FCurrentAnimation
]
777 Result
:= FMaskAnim
[D_RIGHT
][FCurrentAnimation
];
780 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
782 TempArray
: array of DWORD
;
786 SetLength(TempArray
, 0);
788 if SoundType
= MODELSOUND_PAIN
then
790 if FPainSounds
= nil then Exit
;
792 for a
:= 0 to High(FPainSounds
) do
793 if FPainSounds
[a
].Level
= Level
then
795 SetLength(TempArray
, Length(TempArray
)+1);
796 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
801 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
803 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
804 if FSlopSound
= 1 then
810 if FDieSounds
= nil then Exit
;
812 for a
:= 0 to High(FDieSounds
) do
813 if FDieSounds
[a
].Level
= Level
then
815 SetLength(TempArray
, Length(TempArray
)+1);
816 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
818 if (TempArray
= nil) and (Level
= 5) then
820 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
826 if TempArray
= nil then Exit
;
828 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
833 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
840 procedure TPlayerModel
.SetFire(Fire
: Boolean);
844 if FFire
then FFireCounter
:= FAnim
[D_RIGHT
, A_ATTACK
].Speed
*FAnim
[D_RIGHT
, A_ATTACK
].TotalFrames
845 else FFireCounter
:= 0;
848 procedure TPlayerModel
.SetFlag(Flag
: Byte);
858 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
859 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
863 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
866 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
868 FCurrentWeapon
:= Weapon
;
871 procedure TPlayerModel
.Update();
873 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
874 FAnim
[D_LEFT
][FCurrentAnimation
].Update
else FAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
876 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
877 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
879 if FFlagAnim
<> nil then FFlagAnim
.Update
;
881 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;