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
102 TModelSoundArray
= Array of TModelSound
;
103 TGibsArray
= Array of TGibSprite
;
105 TPlayerModel
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
107 FDirection
: TDirection
;
109 FCurrentAnimation
: Byte;
110 FAnimState
: TAnimationState
;
111 FCurrentWeapon
: Byte;
117 destructor Destroy(); override;
118 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
119 procedure SetColor(Red
, Green
, Blue
: Byte);
120 procedure SetWeapon(Weapon
: Byte);
121 procedure SetFlag(Flag
: Byte);
122 procedure SetFire (Fire
: Boolean);
123 function GetFire (): Boolean;
124 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
127 function GetBlood (): TModelBlood
;
128 function GetName (): String;
131 property Direction
: TDirection read FDirection write FDirection
;
132 property Animation
: Byte read FCurrentAnimation
;
133 property Weapon
: Byte read FCurrentWeapon
;
136 property Color
: TRGB read FColor write FColor
;
137 property AnimState
: TAnimationState read FAnimState
;
138 property CurrentAnimation
: Byte read FCurrentAnimation
;
139 property CurrentWeapon
: Byte read FCurrentWeapon
;
140 property Flag
: Byte read FFlag
;
141 property ID
: Integer read FID
;
144 procedure g_PlayerModel_LoadAll
;
145 procedure g_PlayerModel_FreeData();
146 function g_PlayerModel_Load(FileName
: String): Boolean;
147 function g_PlayerModel_GetNames(): SSArray
;
148 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
149 function g_PlayerModel_GetBlood(ModelName
: String): TModelBlood
;
150 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
151 function g_PlayerModel_GetAnim(ModelName
: String; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
152 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
154 (* --- private data --- *)
157 TPlayerModelInfo
= record
159 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
162 WeaponPoints
: TWeaponPoints
;
163 Gibs
: TGibsArray
; // !!! move to render
164 PainSounds
: TModelSoundArray
;
165 DieSounds
: TModelSoundArray
;
168 // =======================
170 Anim
: TModelTextures
;
178 PlayerModelsArray
: Array of TPlayerModelInfo
;
183 g_sound
, g_console
, SysUtils
, g_player
, CONFIG
, r_textures
, r_animations
,
184 e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
187 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
189 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
190 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
191 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
192 (X
:16; Y
:16), (X
:8; Y
:8));
194 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
195 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
196 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
198 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
199 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
200 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
201 'FistAttackUpAnim', 'FistAttackDownAnim');
202 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
203 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
205 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
215 if Length(str
) < 3 then
218 for a
:= 1 to Length(str
) do
219 if (str
[a
] = ',') or (a
= Length(str
)) then
221 s
:= Copy(str
, 1, a
);
222 if s
[Length(s
)] = ',' then
223 SetLength(s
, Length(s
)-1);
226 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
227 (x
< -64) or (x
> 128) or
228 (y
< -64) or (y
> 128) then
240 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
241 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
250 backanim
:= backanim
and (frames
> 2);
252 for a
:= 1 to frames
do
254 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
257 with wpoints
[weapon
, anim
, dir
, a
-1] do
259 X
:= X
- WEAPONBASE
[weapon
].X
;
260 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
261 if dir
= TDirection
.D_LEFT
then
266 h
:= High(wpoints
[weapon
, anim
, dir
]);
268 for b
:= h
downto frames
do
269 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
274 procedure g_PlayerMode_ExtendPoints (id
: Integer; AIdx
: Integer);
276 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
277 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
278 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
279 A_ATTACKUP
, A_ATTACKDOWN
281 var W
, I
, OIdx
: Integer; D
: TDirection
;
283 OIdx
:= CopyAnim
[AIdx
];
284 with PlayerModelsArray
[id
] do
286 for W
:= WP_FIRST
+ 1 to WP_LAST
do
288 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
290 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
291 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
292 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
298 function g_PlayerModel_CalcGibSize (pData
: Pointer; dataSize
, x
, y
, w
, h
: Integer): TRectWH
;
299 var i
, j
: Integer; done
: Boolean; img
: TImageData
;
301 function IsVoid (i
, j
: Integer): Boolean;
303 result
:= Byte((PByte(img
.bits
) + (y
+j
)*img
.width
*4 + (x
+i
)*4 + 3)^) = 0
308 assert(LoadImageFromMemory(pData
, dataSize
, img
));
310 (* trace x from right to left *)
311 done
:= false; i
:= 0;
312 while not done
and (i
< w
) do
315 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
316 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
321 (* trace y from up to down *)
322 done
:= false; j
:= 0;
323 while not done
and (j
< h
) do
326 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
327 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
332 (* trace x from right to left *)
333 done
:= false; i
:= w
- 1;
334 while not done
and (i
>= 0) do
337 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
338 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
339 result
.width
:= i
- result
.x
+ 1;
343 (* trace y from down to up *)
344 done
:= false; j
:= h
- 1;
345 while not done
and (j
>= 0) do
348 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
349 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
350 result
.height
:= j
- result
.y
+ 1;
357 function g_PlayerModel_Load(FileName
: string): Boolean;
360 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
363 pData
, pData2
: Pointer;
367 ok
, chk
, chk2
: Boolean;
369 e_WriteLog(Format('Loading player model "%s"...', [FileName
]), TMsgType
.Notify
);
373 WAD
:= TWADFile
.Create
;
374 WAD
.ReadFile(FileName
);
376 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
382 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
388 config
:= TConfig
.CreateMem(pData
, len
);
391 s
:= config
.ReadStr('Model', 'name', '');
399 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
400 ID
:= High(PlayerModelsArray
);
402 prefix
:= FileName
+':TEXTURES\';
404 with PlayerModelsArray
[ID
].Info
do
407 Author
:= config
.ReadStr('Model', 'author', '');
408 Description
:= config
.ReadStr('Model', 'description', '');
411 PlayerModelsArray
[ID
].FileName
:= FileName
;
412 with PlayerModelsArray
[ID
] do
414 Blood
.R
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'R', 150)));
415 Blood
.G
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'G', 0)));
416 Blood
.B
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'B', 0)));
417 case config
.ReadStr('Blood', 'Kind', 'NORMAL') of
418 'NORMAL': Blood
.Kind
:= BLOOD_NORMAL
;
419 'SPARKS': Blood
.Kind
:= BLOOD_CSPARKS
;
420 'COMBINE': Blood
.Kind
:= BLOOD_COMBINE
;
422 Blood
.Kind
:= BLOOD_NORMAL
426 for b
:= A_STAND
to A_LAST
do
428 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
] do
430 Resource
:= config
.ReadStr(AnimNames
[b
], 'resource', '');
431 Mask
:= config
.ReadStr(AnimNames
[b
], 'mask', '');
432 Frames
:= config
.ReadInt(AnimNames
[b
], 'frames', 1);
433 Back
:= config
.ReadBool(AnimNames
[b
], 'backanim', False);
434 if (Resource
= '') or (Mask
= '') then
436 if b
<= A_LASTBASE
then
444 g_PlayerMode_ExtendPoints(ID
, b
);
450 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
451 for bb
:= A_STAND
to A_LAST
do
452 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
454 f
:= PlayerModelsArray
[ID
].Anim
[cc
, bb
].Frames
;
455 if PlayerModelsArray
[ID
].Anim
[cc
, bb
].Back
and (f
> 2) then
457 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
460 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_LEFT
, b
] do
462 Frames
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Frames
;
463 Back
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Back
;
466 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
469 with PlayerModelsArray
[ID
], config
do
471 prefix
:= FileName
+':SOUNDS\';
475 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
478 SetLength(PainSounds
, Length(PainSounds
)+1);
479 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
480 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
487 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
490 SetLength(DieSounds
, Length(DieSounds
)+1);
491 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
492 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
497 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
499 GibsCount
:= config
.ReadInt('Gibs', 'count', 0);
500 GibsResource
:= config
.ReadStr('Gibs', 'resource', 'GIBS');
501 GibsMask
:= config
.ReadStr('Gibs', 'mask', 'GIBSMASK');
502 GibsOnce
:= config
.ReadInt('Gibs', 'once', -1);
504 SetLength(Gibs
, GibsCount
); // !!! remove load
506 (WAD
.GetResource('TEXTURES/' + GibsResource
, pData
, lenpd
)) and
507 (WAD
.GetResource('TEXTURES/' + GibsMask
, pData2
, lenpd2
)) then
509 for a
:= 0 to High(Gibs
) do
510 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
511 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
513 //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
514 Gibs
[a
].Rect
:= g_PlayerModel_CalcGibSize(pData
, lenpd
, a
*32, 0, 32, 32);
516 if Height
> 3 then Height
:= Height
-1-Random(2);
517 Gibs
[a
].OnlyOne
:= GibsOnce
= a
+ 1;
525 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
526 for bb
:= A_STAND
to A_LAST
do
527 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
529 chk
:= GetWeapPoints(
530 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '_points', ''),
534 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
535 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
538 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
540 // workaround for flamethrower
541 chk
:= GetWeapPoints(
542 config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
] + '_points', ''),
546 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
547 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
551 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
556 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
557 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
559 A_WALKATTACK
, A_WALK
:
561 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
562 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
566 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
567 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
569 A_WALKSEEUP
, A_SEEUP
:
571 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
572 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
574 A_WALKSEEDOWN
, A_SEEDOWN
:
576 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
577 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
579 A_WALKATTACKUP
, A_ATTACKUP
:
581 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
582 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
584 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
586 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
587 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
593 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
595 chk2
:= GetWeapPoints(
596 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '2_points', ''),
600 Anim
[TDirection
.D_LEFT
, bb
].Frames
,
601 Anim
[TDirection
.D_LEFT
, bb
].Back
,
606 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
608 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
609 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
613 if not ok
then Break
;
615 {if ok then g_Console_Add(Info.Name+' weapon points ok')
616 else g_Console_Add(Info.Name+' weapon points fail');}
617 Info
.HaveWeapon
:= ok
;
619 s
:= config
.ReadStr('Model', 'flag_point', '');
620 if not GetPoint(s
, FlagPoint
) then
621 FlagPoint
:= FLAG_DEFPOINT
;
623 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
632 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
637 if PlayerModelsArray
= nil then Exit
;
639 for a
:= 0 to High(PlayerModelsArray
) do
641 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
643 Result
:= TPlayerModel
.Create
;
645 with PlayerModelsArray
[a
] do
648 Result
.ChangeAnimation(A_STAND
, True);
655 function g_PlayerModel_GetAnim(ModelName
: string; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
663 if PlayerModelsArray
= nil then Exit
;
664 for a
:= 0 to High(PlayerModelsArray
) do
665 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
666 with PlayerModelsArray
[a
] do
668 if AnimTyp
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
670 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(AnimTyp
)) then
671 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(AnimTyp
)) then Exit
;
673 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
674 _Anim
.Speed
:= ModelSpeed
[AnimTyp
];
676 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(AnimTyp
)+'_MASK') then
677 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(AnimTyp
)+'_MASK') then Exit
;
679 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
680 _Mask
.Speed
:= ModelSpeed
[AnimTyp
];
688 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
695 if PlayerModelsArray
= nil then Exit
;
696 if gGibsCount
= 0 then Exit
;
700 SetLength(Gibs
, gGibsCount
);
702 for a
:= 0 to High(PlayerModelsArray
) do
703 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
705 for i
:= 0 to High(Gibs
) do
707 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
714 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
715 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
717 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
719 if Gibs
[i
].OnlyOne
then c
:= True;
727 function g_PlayerModel_GetNames(): SSArray
;
733 if PlayerModelsArray
= nil then Exit
;
735 for i
:= 0 to High(PlayerModelsArray
) do
737 SetLength(Result
, Length(Result
)+1);
738 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
742 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
746 FillChar(Result
, SizeOf(Result
), 0);
747 if PlayerModelsArray
= nil then Exit
;
749 for a
:= 0 to High(PlayerModelsArray
) do
750 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
752 Result
:= PlayerModelsArray
[a
].Info
;
757 function g_PlayerModel_GetBlood(ModelName
: string): TModelBlood
;
764 Result
.Kind
:= BLOOD_NORMAL
;
765 if PlayerModelsArray
= nil then Exit
;
767 for a
:= 0 to High(PlayerModelsArray
) do
768 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
770 Result
:= PlayerModelsArray
[a
].Blood
;
775 procedure g_PlayerModel_FreeData();
778 e_WriteLog('Releasing models...', TMsgType
.Notify
);
780 if PlayerModelsArray
= nil then Exit
;
782 for i
:= 0 to High(PlayerModelsArray
) do
784 with PlayerModelsArray
[i
] do
786 if PainSounds
<> nil then
787 for b
:= 0 to High(PainSounds
) do
788 e_DeleteSound(PainSounds
[b
].ID
);
789 if DieSounds
<> nil then
790 for b
:= 0 to High(DieSounds
) do
791 e_DeleteSound(DieSounds
[b
].ID
);
794 PlayerModelsArray
:= nil;
799 procedure TPlayerModel
.ChangeAnimation (Animation
: Byte; Force
: Boolean = False);
800 var once
: Boolean; speed
, count
: Integer;
803 if FCurrentAnimation
= Animation
then
805 FCurrentAnimation
:= Animation
;
806 once
:= FCurrentAnimation
in [A_STAND
, A_WALK
];
807 speed
:= PlayerModelsArray
[FID
].ModelSpeed
[FCurrentAnimation
];
808 count
:= PlayerModelsArray
[FID
].Anim
[FDirection
, FCurrentAnimation
].Frames
;
809 FAnimState
:= TAnimationState
.Create(once
, speed
, count
);
812 destructor TPlayerModel
.Destroy();
818 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
820 TempArray
: array of DWORD
;
824 SetLength(TempArray
, 0);
826 if SoundType
= MODELSOUND_PAIN
then
828 if PlayerModelsArray
[FID
].PainSounds
= nil then Exit
;
830 for a
:= 0 to High(PlayerModelsArray
[FID
].PainSounds
) do
831 if PlayerModelsArray
[FID
].PainSounds
[a
].Level
= Level
then
833 SetLength(TempArray
, Length(TempArray
) + 1);
834 TempArray
[High(TempArray
)] := PlayerModelsArray
[FID
].PainSounds
[a
].ID
;
839 if (Level
in [2, 3, 5]) and (PlayerModelsArray
[FID
].SlopSound
> 0) then
841 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
842 if PlayerModelsArray
[FID
].SlopSound
= 1 then
848 if PlayerModelsArray
[FID
].DieSounds
= nil then Exit
;
850 for a
:= 0 to High(PlayerModelsArray
[FID
].DieSounds
) do
851 if PlayerModelsArray
[FID
].DieSounds
[a
].Level
= Level
then
853 SetLength(TempArray
, Length(TempArray
) + 1);
854 TempArray
[High(TempArray
)] := PlayerModelsArray
[FID
].DieSounds
[a
].ID
;
856 if (TempArray
= nil) and (Level
= 5) then
858 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
864 if TempArray
= nil then Exit
;
866 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
871 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
878 procedure TPlayerModel
.SetFire (Fire
: Boolean);
881 FFireCounter
:= PlayerModelsArray
[FID
].ModelSpeed
[A_ATTACK
] * PlayerModelsArray
[FID
].Anim
[TDirection
.D_RIGHT
, A_ATTACK
].Frames
886 function TPlayerModel
.GetFire (): Boolean;
888 Result
:= FFireCounter
> 0
891 procedure TPlayerModel
.SetFlag (Flag
: Byte);
896 procedure TPlayerModel
.SetWeapon (Weapon
: Byte);
898 FCurrentWeapon
:= Weapon
901 function TPlayerModel
.GetBlood (): TModelBlood
;
903 Result
:= PlayerModelsArray
[FID
].Blood
906 function TPlayerModel
.GetName (): String;
908 Result
:= PlayerModelsArray
[FID
].Info
.Name
911 procedure TPlayerModel
.Update
;
913 if FAnimState
<> nil then
915 if FFireCounter
> 0 then
919 procedure g_PlayerModel_LoadAll
;
922 knownFiles
: array of AnsiString = nil;
927 // load models from all possible wad types, in all known directories
928 // this does a loosy job (linear search, ooph!), but meh
929 for wext
in wadExtensions
do
931 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
933 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
937 for s
in knownFiles
do
939 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
947 SetLength(knownFiles
, length(knownFiles
)+1);
948 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
950 until (FindNext(SR
) <> 0);
955 if (length(knownFiles
) = 0) then
956 raise Exception
.Create('no player models found!');
957 if (length(knownFiles
) = 1) then
958 e_LogWriteln('1 player model found.', TMsgType
.Notify
)
960 e_LogWritefln('%d player models found.', [Integer(length(knownFiles
))], TMsgType
.Notify
);
961 for s
in knownFiles
do
962 if not g_PlayerModel_Load(s
) then
963 e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);