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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
22 MAPDEF
, g_textures
, g_base
, g_basic
, g_weapons
, r_graphics
, utils
, g_gfx
,
23 ImagingTypes
, Imaging
, ImagingUtility
;
41 A_WALKATTACKDOWN
= 14;
45 A_FISTWALKATTACK
= 18;
49 A_FISTATTACKDOWN
= 22;
52 A_LASTEXT
= A_FISTATTACKDOWN
;
65 FLAG_BASEPOINT
: TDFPoint
= (X
:16; Y
:43);
68 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
, A_STAND
..A_LAST
, TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array of TDFPoint
;
70 TModelMatrix
= Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
, A_STAND
..A_LAST
] of TAnimationState
;
72 TModelTextures
= Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
, A_STAND
..A_LAST
] of record
88 TModelSoundArray
= Array of TModelSound
;
90 TGibsArray
= Array of Integer;
92 TPlayerModel
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
94 FDirection
: TDirection
;
96 FCurrentAnimation
: Byte;
97 FAnimState
: TAnimationState
;
104 destructor Destroy(); override;
105 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
106 procedure SetColor(Red
, Green
, Blue
: Byte);
107 procedure SetWeapon(Weapon
: Byte);
108 procedure SetFlag(Flag
: Byte);
109 procedure SetFire (Fire
: Boolean);
110 function GetFire (): Boolean;
111 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
114 function GetBlood (): TModelBlood
;
115 function GetName (): String;
118 property Direction
: TDirection read FDirection write FDirection
;
119 property Animation
: Byte read FCurrentAnimation
;
120 property Weapon
: Byte read FCurrentWeapon
;
123 property Color
: TRGB read FColor write FColor
;
124 property AnimState
: TAnimationState read FAnimState
;
125 property CurrentAnimation
: Byte read FCurrentAnimation
;
126 property CurrentWeapon
: Byte read FCurrentWeapon
;
127 property Flag
: Byte read FFlag
;
128 property ID
: Integer read FID
;
131 procedure g_PlayerModel_LoadAll
;
132 procedure g_PlayerModel_FreeData();
133 function g_PlayerModel_Load(FileName
: String): Boolean;
134 function g_PlayerModel_GetNames(): SSArray
;
135 function g_PlayerModel_GetBlood(ModelName
: String): TModelBlood
;
136 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
137 function g_PlayerModel_GetAnim(ModelName
: String; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
138 function g_PlayerModel_GetGibs (ModelID
: Integer; var Gibs
: TGibsArray
): Boolean;
139 function g_PlayerModel_GetIndex (ModelName
: String): Integer;
141 (* --- private data --- *)
144 TPlayerModelInfo
= record
149 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
152 WeaponPoints
: TWeaponPoints
;
153 PainSounds
: TModelSoundArray
;
154 DieSounds
: TModelSoundArray
;
157 // =======================
159 Anim
: TModelTextures
;
167 PlayerModelsArray
: Array of TPlayerModelInfo
;
172 g_sound
, g_console
, SysUtils
, g_player
, CONFIG
, r_textures
, r_animations
,
173 e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
176 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
178 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
179 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
180 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
181 (X
:16; Y
:16), (X
:8; Y
:8));
183 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
184 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
185 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
187 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
188 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
189 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
190 'FistAttackUpAnim', 'FistAttackDownAnim');
191 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
192 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
194 function g_PlayerModel_GetIndex (ModelName
: String): Integer;
198 if PlayerModelsArray
<> nil then
201 while (i
< Length(PlayerModelsArray
)) and (PlayerModelsArray
[i
].Name
<> ModelName
) do
203 if i
< Length(PlayerModelsArray
) then
208 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
218 if Length(str
) < 3 then
221 for a
:= 1 to Length(str
) do
222 if (str
[a
] = ',') or (a
= Length(str
)) then
224 s
:= Copy(str
, 1, a
);
225 if s
[Length(s
)] = ',' then
226 SetLength(s
, Length(s
)-1);
229 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
230 (x
< -64) or (x
> 128) or
231 (y
< -64) or (y
> 128) then
243 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
244 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
253 backanim
:= backanim
and (frames
> 2);
255 for a
:= 1 to frames
do
257 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
260 with wpoints
[weapon
, anim
, dir
, a
-1] do
262 X
:= X
- WEAPONBASE
[weapon
].X
;
263 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
264 if dir
= TDirection
.D_LEFT
then
269 h
:= High(wpoints
[weapon
, anim
, dir
]);
271 for b
:= h
downto frames
do
272 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
277 procedure g_PlayerMode_ExtendPoints (id
: Integer; AIdx
: Integer);
279 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
280 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
281 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
282 A_ATTACKUP
, A_ATTACKDOWN
284 var W
, I
, OIdx
: Integer; D
: TDirection
;
286 OIdx
:= CopyAnim
[AIdx
];
287 with PlayerModelsArray
[id
] do
289 for W
:= WP_FIRST
+ 1 to WP_LAST
do
291 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
293 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
294 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
295 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
301 function g_PlayerModel_CalcGibSize (pData
: Pointer; dataSize
, x
, y
, w
, h
: Integer): TRectWH
;
302 var i
, j
: Integer; done
: Boolean; img
: TImageData
;
304 function IsVoid (i
, j
: Integer): Boolean;
306 result
:= Byte((PByte(img
.bits
) + (y
+j
)*img
.width
*4 + (x
+i
)*4 + 3)^) = 0
311 assert(LoadImageFromMemory(pData
, dataSize
, img
));
313 (* trace x from right to left *)
314 done
:= false; i
:= 0;
315 while not done
and (i
< w
) do
318 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
319 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
324 (* trace y from up to down *)
325 done
:= false; j
:= 0;
326 while not done
and (j
< h
) do
329 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
330 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
335 (* trace x from right to left *)
336 done
:= false; i
:= w
- 1;
337 while not done
and (i
>= 0) do
340 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
341 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
342 result
.width
:= i
- result
.x
+ 1;
346 (* trace y from down to up *)
347 done
:= false; j
:= h
- 1;
348 while not done
and (j
>= 0) do
351 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
352 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
353 result
.height
:= j
- result
.y
+ 1;
360 function g_PlayerModel_Load(FileName
: string): Boolean;
363 a
, b
, len
, aa
, bb
, f
: Integer;
370 ok
, chk
, chk2
: Boolean;
372 e_WriteLog(Format('Loading player model "%s"...', [FileName
]), TMsgType
.Notify
);
376 WAD
:= TWADFile
.Create
;
377 WAD
.ReadFile(FileName
);
379 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
385 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
391 config
:= TConfig
.CreateMem(pData
, len
);
394 s
:= config
.ReadStr('Model', 'name', '');
402 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
403 ID
:= High(PlayerModelsArray
);
405 prefix
:= FileName
+':TEXTURES\';
407 PlayerModelsArray
[ID
].Name
:= s
;
408 PlayerModelsArray
[ID
].Author
:= config
.ReadStr('Model', 'author', '');
409 PlayerModelsArray
[ID
].Description
:= config
.ReadStr('Model', 'description', '');
410 PlayerModelsArray
[ID
].FileName
:= FileName
;
411 with PlayerModelsArray
[ID
] do
413 Blood
.R
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'R', 150)));
414 Blood
.G
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'G', 0)));
415 Blood
.B
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'B', 0)));
416 case config
.ReadStr('Blood', 'Kind', 'NORMAL') of
417 'NORMAL': Blood
.Kind
:= BLOOD_NORMAL
;
418 'SPARKS': Blood
.Kind
:= BLOOD_CSPARKS
;
419 'COMBINE': Blood
.Kind
:= BLOOD_COMBINE
;
421 Blood
.Kind
:= BLOOD_NORMAL
425 for b
:= A_STAND
to A_LAST
do
427 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
] do
429 Resource
:= config
.ReadStr(AnimNames
[b
], 'resource', '');
430 Mask
:= config
.ReadStr(AnimNames
[b
], 'mask', '');
431 Frames
:= config
.ReadInt(AnimNames
[b
], 'frames', 1);
432 Back
:= config
.ReadBool(AnimNames
[b
], 'backanim', False);
433 if (Resource
= '') or (Mask
= '') then
435 if b
<= A_LASTBASE
then
443 g_PlayerMode_ExtendPoints(ID
, b
);
449 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
450 for bb
:= A_STAND
to A_LAST
do
451 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
453 f
:= PlayerModelsArray
[ID
].Anim
[cc
, bb
].Frames
;
454 if PlayerModelsArray
[ID
].Anim
[cc
, bb
].Back
and (f
> 2) then
456 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
459 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_LEFT
, b
] do
461 Frames
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Frames
;
462 Back
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Back
;
465 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
468 with PlayerModelsArray
[ID
], config
do
470 prefix
:= FileName
+':SOUNDS\';
474 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
477 SetLength(PainSounds
, Length(PainSounds
)+1);
478 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
479 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
486 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
489 SetLength(DieSounds
, Length(DieSounds
)+1);
490 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
491 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
496 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
498 GibsCount
:= config
.ReadInt('Gibs', 'count', 0);
499 GibsResource
:= config
.ReadStr('Gibs', 'resource', 'GIBS');
500 GibsMask
:= config
.ReadStr('Gibs', 'mask', 'GIBSMASK');
501 GibsOnce
:= config
.ReadInt('Gibs', 'once', -1);
504 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
505 for bb
:= A_STAND
to A_LAST
do
506 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
508 chk
:= GetWeapPoints(
509 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '_points', ''),
513 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
514 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
517 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
519 // workaround for flamethrower
520 chk
:= GetWeapPoints(
521 config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
] + '_points', ''),
525 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
526 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
530 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
535 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
536 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
538 A_WALKATTACK
, A_WALK
:
540 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
541 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
545 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
546 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
548 A_WALKSEEUP
, A_SEEUP
:
550 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
551 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
553 A_WALKSEEDOWN
, A_SEEDOWN
:
555 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
556 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
558 A_WALKATTACKUP
, A_ATTACKUP
:
560 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
561 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
563 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
565 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
566 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
572 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
574 chk2
:= GetWeapPoints(
575 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '2_points', ''),
579 Anim
[TDirection
.D_LEFT
, bb
].Frames
,
580 Anim
[TDirection
.D_LEFT
, bb
].Back
,
585 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
587 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
588 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
592 if not ok
then Break
;
594 {if ok then g_Console_Add(Info.Name+' weapon points ok')
595 else g_Console_Add(Info.Name+' weapon points fail');}
596 PlayerModelsArray
[ID
].HaveWeapon
:= ok
;
598 s
:= config
.ReadStr('Model', 'flag_point', '');
599 if not GetPoint(s
, FlagPoint
) then
600 FlagPoint
:= FLAG_DEFPOINT
;
602 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
611 function g_PlayerModel_Get (ModelName
: String): TPlayerModel
;
616 if PlayerModelsArray
= nil then Exit
;
618 for a
:= 0 to High(PlayerModelsArray
) do
620 if AnsiLowerCase(PlayerModelsArray
[a
].Name
) = AnsiLowerCase(ModelName
) then
622 Result
:= TPlayerModel
.Create
;
624 with PlayerModelsArray
[a
] do
627 Result
.ChangeAnimation(A_STAND
, True);
634 function g_PlayerModel_GetAnim(ModelName
: string; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
642 if PlayerModelsArray
= nil then Exit
;
643 for a
:= 0 to High(PlayerModelsArray
) do
644 if PlayerModelsArray
[a
].Name
= ModelName
then
645 with PlayerModelsArray
[a
] do
647 if AnimTyp
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
649 if not g_Frames_Get(ID
, Name
+ '_RIGHTANIM' + IntToStr(AnimTyp
)) then
650 if not g_Frames_Get(ID
, Name
+ '_LEFTANIM' + IntToStr(AnimTyp
)) then Exit
;
652 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
653 _Anim
.Speed
:= ModelSpeed
[AnimTyp
];
655 if not g_Frames_Get(ID
, Name
+ '_RIGHTANIM' + IntToStr(AnimTyp
) + '_MASK') then
656 if not g_Frames_Get(ID
, Name
+ '_LEFTANIM' + IntToStr(AnimTyp
) + '_MASK') then
659 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
660 _Mask
.Speed
:= ModelSpeed
[AnimTyp
];
668 function g_PlayerModel_GetGibs (ModelID
: Integer; var Gibs
: TGibsArray
): Boolean;
669 var i
, b
: Integer; c
: Boolean;
673 if (PlayerModelsArray
= nil) or (gGibsCount
= 0) then
677 SetLength(Gibs
, gGibsCount
);
678 for i
:= 0 to High(Gibs
) do
680 if c
and (PlayerModelsArray
[ModelID
].GibsCount
= 1) then
687 b
:= Random(PlayerModelsArray
[ModelID
].GibsCount
);
688 until not ((PlayerModelsArray
[ModelID
].GibsOnce
= b
+ 1) and c
);
692 c
:= PlayerModelsArray
[ModelID
].GibsOnce
= b
+ 1;
697 function g_PlayerModel_GetNames(): SSArray
;
703 if PlayerModelsArray
= nil then Exit
;
705 for i
:= 0 to High(PlayerModelsArray
) do
707 SetLength(Result
, Length(Result
)+1);
708 Result
[High(Result
)] := PlayerModelsArray
[i
].Name
;
712 function g_PlayerModel_GetBlood(ModelName
: string): TModelBlood
;
719 Result
.Kind
:= BLOOD_NORMAL
;
720 if PlayerModelsArray
= nil then Exit
;
722 for a
:= 0 to High(PlayerModelsArray
) do
723 if PlayerModelsArray
[a
].Name
= ModelName
then
725 Result
:= PlayerModelsArray
[a
].Blood
;
730 procedure g_PlayerModel_FreeData();
733 e_WriteLog('Releasing models...', TMsgType
.Notify
);
735 if PlayerModelsArray
= nil then Exit
;
737 for i
:= 0 to High(PlayerModelsArray
) do
739 with PlayerModelsArray
[i
] do
741 if PainSounds
<> nil then
742 for b
:= 0 to High(PainSounds
) do
743 e_DeleteSound(PainSounds
[b
].ID
);
744 if DieSounds
<> nil then
745 for b
:= 0 to High(DieSounds
) do
746 e_DeleteSound(DieSounds
[b
].ID
);
749 PlayerModelsArray
:= nil;
754 procedure TPlayerModel
.ChangeAnimation (Animation
: Byte; Force
: Boolean = False);
755 var once
: Boolean; speed
, count
: Integer;
758 if FCurrentAnimation
= Animation
then
760 FCurrentAnimation
:= Animation
;
761 once
:= FCurrentAnimation
in [A_STAND
, A_WALK
];
762 speed
:= PlayerModelsArray
[FID
].ModelSpeed
[FCurrentAnimation
];
763 count
:= PlayerModelsArray
[FID
].Anim
[FDirection
, FCurrentAnimation
].Frames
;
764 FAnimState
:= TAnimationState
.Create(once
, speed
, count
);
767 destructor TPlayerModel
.Destroy();
773 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
775 TempArray
: array of DWORD
;
779 SetLength(TempArray
, 0);
781 if SoundType
= MODELSOUND_PAIN
then
783 if PlayerModelsArray
[FID
].PainSounds
= nil then Exit
;
785 for a
:= 0 to High(PlayerModelsArray
[FID
].PainSounds
) do
786 if PlayerModelsArray
[FID
].PainSounds
[a
].Level
= Level
then
788 SetLength(TempArray
, Length(TempArray
) + 1);
789 TempArray
[High(TempArray
)] := PlayerModelsArray
[FID
].PainSounds
[a
].ID
;
794 if (Level
in [2, 3, 5]) and (PlayerModelsArray
[FID
].SlopSound
> 0) then
796 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
797 if PlayerModelsArray
[FID
].SlopSound
= 1 then
803 if PlayerModelsArray
[FID
].DieSounds
= nil then Exit
;
805 for a
:= 0 to High(PlayerModelsArray
[FID
].DieSounds
) do
806 if PlayerModelsArray
[FID
].DieSounds
[a
].Level
= Level
then
808 SetLength(TempArray
, Length(TempArray
) + 1);
809 TempArray
[High(TempArray
)] := PlayerModelsArray
[FID
].DieSounds
[a
].ID
;
811 if (TempArray
= nil) and (Level
= 5) then
813 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
819 if TempArray
= nil then Exit
;
821 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
826 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
833 procedure TPlayerModel
.SetFire (Fire
: Boolean);
836 FFireCounter
:= PlayerModelsArray
[FID
].ModelSpeed
[A_ATTACK
] * PlayerModelsArray
[FID
].Anim
[TDirection
.D_RIGHT
, A_ATTACK
].Frames
841 function TPlayerModel
.GetFire (): Boolean;
843 Result
:= FFireCounter
> 0
846 procedure TPlayerModel
.SetFlag (Flag
: Byte);
851 procedure TPlayerModel
.SetWeapon (Weapon
: Byte);
853 FCurrentWeapon
:= Weapon
856 function TPlayerModel
.GetBlood (): TModelBlood
;
858 Result
:= PlayerModelsArray
[FID
].Blood
861 function TPlayerModel
.GetName (): String;
863 Result
:= PlayerModelsArray
[FID
].Name
866 procedure TPlayerModel
.Update
;
868 if FAnimState
<> nil then
870 if FFireCounter
> 0 then
874 procedure g_PlayerModel_LoadAll
;
877 knownFiles
: array of AnsiString = nil;
882 // load models from all possible wad types, in all known directories
883 // this does a loosy job (linear search, ooph!), but meh
884 for wext
in wadExtensions
do
886 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
888 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
892 for s
in knownFiles
do
894 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
902 SetLength(knownFiles
, length(knownFiles
)+1);
903 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
905 until (FindNext(SR
) <> 0);
910 if (length(knownFiles
) = 0) then
911 raise Exception
.Create('no player models found!');
912 if (length(knownFiles
) = 1) then
913 e_LogWriteln('1 player model found.', TMsgType
.Notify
)
915 e_LogWritefln('%d player models found.', [Integer(length(knownFiles
))], TMsgType
.Notify
);
916 for s
in knownFiles
do
917 if not g_PlayerModel_Load(s
) then
918 e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);