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
95 TModelSoundArray
= Array of TModelSound
;
96 TGibsArray
= Array of TGibSprite
;
98 TPlayerModel
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
100 FDirection
: TDirection
;
102 FCurrentAnimation
: Byte;
103 FAnimState
: TAnimationState
;
104 FCurrentWeapon
: Byte;
110 destructor Destroy(); override;
111 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
112 procedure SetColor(Red
, Green
, Blue
: Byte);
113 procedure SetWeapon(Weapon
: Byte);
114 procedure SetFlag(Flag
: Byte);
115 procedure SetFire (Fire
: Boolean);
116 function GetFire (): Boolean;
117 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
120 function GetBlood (): TModelBlood
;
121 function GetName (): String;
124 property Direction
: TDirection read FDirection write FDirection
;
125 property Animation
: Byte read FCurrentAnimation
;
126 property Weapon
: Byte read FCurrentWeapon
;
129 property Color
: TRGB read FColor write FColor
;
130 property AnimState
: TAnimationState read FAnimState
;
131 property CurrentAnimation
: Byte read FCurrentAnimation
;
132 property CurrentWeapon
: Byte read FCurrentWeapon
;
133 property Flag
: Byte read FFlag
;
134 property ID
: Integer read FID
;
137 procedure g_PlayerModel_LoadAll
;
138 procedure g_PlayerModel_FreeData();
139 function g_PlayerModel_Load(FileName
: String): Boolean;
140 function g_PlayerModel_GetNames(): SSArray
;
141 function g_PlayerModel_GetBlood(ModelName
: String): TModelBlood
;
142 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
143 function g_PlayerModel_GetAnim(ModelName
: String; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
144 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
146 function g_PlayerModel_GetIndex (ModelName
: String): Integer;
148 (* --- private data --- *)
151 TPlayerModelInfo
= record
156 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
159 WeaponPoints
: TWeaponPoints
;
160 Gibs
: TGibsArray
; // !!! move to render
161 PainSounds
: TModelSoundArray
;
162 DieSounds
: TModelSoundArray
;
165 // =======================
167 Anim
: TModelTextures
;
175 PlayerModelsArray
: Array of TPlayerModelInfo
;
180 g_sound
, g_console
, SysUtils
, g_player
, CONFIG
, r_textures
, r_animations
,
181 e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
184 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
186 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
187 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
188 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
189 (X
:16; Y
:16), (X
:8; Y
:8));
191 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
192 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
193 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
195 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
196 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
197 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
198 'FistAttackUpAnim', 'FistAttackDownAnim');
199 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
200 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
202 function g_PlayerModel_GetIndex (ModelName
: String): Integer;
206 if PlayerModelsArray
<> nil then
209 while (i
< Length(PlayerModelsArray
)) and (PlayerModelsArray
[i
].Name
<> ModelName
) do
211 if i
< Length(PlayerModelsArray
) then
216 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
226 if Length(str
) < 3 then
229 for a
:= 1 to Length(str
) do
230 if (str
[a
] = ',') or (a
= Length(str
)) then
232 s
:= Copy(str
, 1, a
);
233 if s
[Length(s
)] = ',' then
234 SetLength(s
, Length(s
)-1);
237 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
238 (x
< -64) or (x
> 128) or
239 (y
< -64) or (y
> 128) then
251 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
252 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
261 backanim
:= backanim
and (frames
> 2);
263 for a
:= 1 to frames
do
265 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
268 with wpoints
[weapon
, anim
, dir
, a
-1] do
270 X
:= X
- WEAPONBASE
[weapon
].X
;
271 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
272 if dir
= TDirection
.D_LEFT
then
277 h
:= High(wpoints
[weapon
, anim
, dir
]);
279 for b
:= h
downto frames
do
280 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
285 procedure g_PlayerMode_ExtendPoints (id
: Integer; AIdx
: Integer);
287 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
288 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
289 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
290 A_ATTACKUP
, A_ATTACKDOWN
292 var W
, I
, OIdx
: Integer; D
: TDirection
;
294 OIdx
:= CopyAnim
[AIdx
];
295 with PlayerModelsArray
[id
] do
297 for W
:= WP_FIRST
+ 1 to WP_LAST
do
299 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
301 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
302 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
303 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
309 function g_PlayerModel_CalcGibSize (pData
: Pointer; dataSize
, x
, y
, w
, h
: Integer): TRectWH
;
310 var i
, j
: Integer; done
: Boolean; img
: TImageData
;
312 function IsVoid (i
, j
: Integer): Boolean;
314 result
:= Byte((PByte(img
.bits
) + (y
+j
)*img
.width
*4 + (x
+i
)*4 + 3)^) = 0
319 assert(LoadImageFromMemory(pData
, dataSize
, img
));
321 (* trace x from right to left *)
322 done
:= false; i
:= 0;
323 while not done
and (i
< w
) do
326 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
327 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
332 (* trace y from up to down *)
333 done
:= false; j
:= 0;
334 while not done
and (j
< h
) do
337 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
338 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
343 (* trace x from right to left *)
344 done
:= false; i
:= w
- 1;
345 while not done
and (i
>= 0) do
348 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
349 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
350 result
.width
:= i
- result
.x
+ 1;
354 (* trace y from down to up *)
355 done
:= false; j
:= h
- 1;
356 while not done
and (j
>= 0) do
359 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
360 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
361 result
.height
:= j
- result
.y
+ 1;
368 function g_PlayerModel_Load(FileName
: string): Boolean;
371 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
374 pData
, pData2
: Pointer;
378 ok
, chk
, chk2
: Boolean;
380 e_WriteLog(Format('Loading player model "%s"...', [FileName
]), TMsgType
.Notify
);
384 WAD
:= TWADFile
.Create
;
385 WAD
.ReadFile(FileName
);
387 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
393 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
399 config
:= TConfig
.CreateMem(pData
, len
);
402 s
:= config
.ReadStr('Model', 'name', '');
410 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
411 ID
:= High(PlayerModelsArray
);
413 prefix
:= FileName
+':TEXTURES\';
415 PlayerModelsArray
[ID
].Name
:= s
;
416 PlayerModelsArray
[ID
].Author
:= config
.ReadStr('Model', 'author', '');
417 PlayerModelsArray
[ID
].Description
:= config
.ReadStr('Model', 'description', '');
418 PlayerModelsArray
[ID
].FileName
:= FileName
;
419 with PlayerModelsArray
[ID
] do
421 Blood
.R
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'R', 150)));
422 Blood
.G
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'G', 0)));
423 Blood
.B
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'B', 0)));
424 case config
.ReadStr('Blood', 'Kind', 'NORMAL') of
425 'NORMAL': Blood
.Kind
:= BLOOD_NORMAL
;
426 'SPARKS': Blood
.Kind
:= BLOOD_CSPARKS
;
427 'COMBINE': Blood
.Kind
:= BLOOD_COMBINE
;
429 Blood
.Kind
:= BLOOD_NORMAL
433 for b
:= A_STAND
to A_LAST
do
435 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
] do
437 Resource
:= config
.ReadStr(AnimNames
[b
], 'resource', '');
438 Mask
:= config
.ReadStr(AnimNames
[b
], 'mask', '');
439 Frames
:= config
.ReadInt(AnimNames
[b
], 'frames', 1);
440 Back
:= config
.ReadBool(AnimNames
[b
], 'backanim', False);
441 if (Resource
= '') or (Mask
= '') then
443 if b
<= A_LASTBASE
then
451 g_PlayerMode_ExtendPoints(ID
, b
);
457 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
458 for bb
:= A_STAND
to A_LAST
do
459 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
461 f
:= PlayerModelsArray
[ID
].Anim
[cc
, bb
].Frames
;
462 if PlayerModelsArray
[ID
].Anim
[cc
, bb
].Back
and (f
> 2) then
464 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
467 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_LEFT
, b
] do
469 Frames
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Frames
;
470 Back
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Back
;
473 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
476 with PlayerModelsArray
[ID
], config
do
478 prefix
:= FileName
+':SOUNDS\';
482 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
485 SetLength(PainSounds
, Length(PainSounds
)+1);
486 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
487 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
494 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
497 SetLength(DieSounds
, Length(DieSounds
)+1);
498 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
499 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
504 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
506 GibsCount
:= config
.ReadInt('Gibs', 'count', 0);
507 GibsResource
:= config
.ReadStr('Gibs', 'resource', 'GIBS');
508 GibsMask
:= config
.ReadStr('Gibs', 'mask', 'GIBSMASK');
509 GibsOnce
:= config
.ReadInt('Gibs', 'once', -1);
511 SetLength(Gibs
, GibsCount
); // !!! remove load
513 (WAD
.GetResource('TEXTURES/' + GibsResource
, pData
, lenpd
)) and
514 (WAD
.GetResource('TEXTURES/' + GibsMask
, pData2
, lenpd2
)) then
516 for a
:= 0 to High(Gibs
) do
517 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
518 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
520 //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
521 Gibs
[a
].Rect
:= g_PlayerModel_CalcGibSize(pData
, lenpd
, a
*32, 0, 32, 32);
523 if Height
> 3 then Height
:= Height
-1-Random(2);
524 Gibs
[a
].OnlyOne
:= GibsOnce
= a
+ 1;
532 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
533 for bb
:= A_STAND
to A_LAST
do
534 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
536 chk
:= GetWeapPoints(
537 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '_points', ''),
541 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
542 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
545 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
547 // workaround for flamethrower
548 chk
:= GetWeapPoints(
549 config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
] + '_points', ''),
553 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
554 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
558 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
563 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
564 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
566 A_WALKATTACK
, A_WALK
:
568 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
569 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
573 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
574 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
576 A_WALKSEEUP
, A_SEEUP
:
578 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
579 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
581 A_WALKSEEDOWN
, A_SEEDOWN
:
583 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
584 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
586 A_WALKATTACKUP
, A_ATTACKUP
:
588 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
589 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
591 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
593 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
594 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
600 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
602 chk2
:= GetWeapPoints(
603 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '2_points', ''),
607 Anim
[TDirection
.D_LEFT
, bb
].Frames
,
608 Anim
[TDirection
.D_LEFT
, bb
].Back
,
613 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
615 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
616 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
620 if not ok
then Break
;
622 {if ok then g_Console_Add(Info.Name+' weapon points ok')
623 else g_Console_Add(Info.Name+' weapon points fail');}
624 PlayerModelsArray
[ID
].HaveWeapon
:= ok
;
626 s
:= config
.ReadStr('Model', 'flag_point', '');
627 if not GetPoint(s
, FlagPoint
) then
628 FlagPoint
:= FLAG_DEFPOINT
;
630 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
639 function g_PlayerModel_Get (ModelName
: String): TPlayerModel
;
644 if PlayerModelsArray
= nil then Exit
;
646 for a
:= 0 to High(PlayerModelsArray
) do
648 if AnsiLowerCase(PlayerModelsArray
[a
].Name
) = AnsiLowerCase(ModelName
) then
650 Result
:= TPlayerModel
.Create
;
652 with PlayerModelsArray
[a
] do
655 Result
.ChangeAnimation(A_STAND
, True);
662 function g_PlayerModel_GetAnim(ModelName
: string; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
670 if PlayerModelsArray
= nil then Exit
;
671 for a
:= 0 to High(PlayerModelsArray
) do
672 if PlayerModelsArray
[a
].Name
= ModelName
then
673 with PlayerModelsArray
[a
] do
675 if AnimTyp
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
677 if not g_Frames_Get(ID
, Name
+ '_RIGHTANIM' + IntToStr(AnimTyp
)) then
678 if not g_Frames_Get(ID
, Name
+ '_LEFTANIM' + IntToStr(AnimTyp
)) then Exit
;
680 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
681 _Anim
.Speed
:= ModelSpeed
[AnimTyp
];
683 if not g_Frames_Get(ID
, Name
+ '_RIGHTANIM' + IntToStr(AnimTyp
) + '_MASK') then
684 if not g_Frames_Get(ID
, Name
+ '_LEFTANIM' + IntToStr(AnimTyp
) + '_MASK') then
687 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
688 _Mask
.Speed
:= ModelSpeed
[AnimTyp
];
696 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
703 if PlayerModelsArray
= nil then Exit
;
704 if gGibsCount
= 0 then Exit
;
708 SetLength(Gibs
, gGibsCount
);
710 for a
:= 0 to High(PlayerModelsArray
) do
711 if PlayerModelsArray
[a
].Name
= ModelName
then
713 for i
:= 0 to High(Gibs
) do
715 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
722 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
723 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
725 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
727 if Gibs
[i
].OnlyOne
then c
:= True;
735 function g_PlayerModel_GetNames(): SSArray
;
741 if PlayerModelsArray
= nil then Exit
;
743 for i
:= 0 to High(PlayerModelsArray
) do
745 SetLength(Result
, Length(Result
)+1);
746 Result
[High(Result
)] := PlayerModelsArray
[i
].Name
;
750 function g_PlayerModel_GetBlood(ModelName
: string): TModelBlood
;
757 Result
.Kind
:= BLOOD_NORMAL
;
758 if PlayerModelsArray
= nil then Exit
;
760 for a
:= 0 to High(PlayerModelsArray
) do
761 if PlayerModelsArray
[a
].Name
= ModelName
then
763 Result
:= PlayerModelsArray
[a
].Blood
;
768 procedure g_PlayerModel_FreeData();
771 e_WriteLog('Releasing models...', TMsgType
.Notify
);
773 if PlayerModelsArray
= nil then Exit
;
775 for i
:= 0 to High(PlayerModelsArray
) do
777 with PlayerModelsArray
[i
] do
779 if PainSounds
<> nil then
780 for b
:= 0 to High(PainSounds
) do
781 e_DeleteSound(PainSounds
[b
].ID
);
782 if DieSounds
<> nil then
783 for b
:= 0 to High(DieSounds
) do
784 e_DeleteSound(DieSounds
[b
].ID
);
787 PlayerModelsArray
:= nil;
792 procedure TPlayerModel
.ChangeAnimation (Animation
: Byte; Force
: Boolean = False);
793 var once
: Boolean; speed
, count
: Integer;
796 if FCurrentAnimation
= Animation
then
798 FCurrentAnimation
:= Animation
;
799 once
:= FCurrentAnimation
in [A_STAND
, A_WALK
];
800 speed
:= PlayerModelsArray
[FID
].ModelSpeed
[FCurrentAnimation
];
801 count
:= PlayerModelsArray
[FID
].Anim
[FDirection
, FCurrentAnimation
].Frames
;
802 FAnimState
:= TAnimationState
.Create(once
, speed
, count
);
805 destructor TPlayerModel
.Destroy();
811 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
813 TempArray
: array of DWORD
;
817 SetLength(TempArray
, 0);
819 if SoundType
= MODELSOUND_PAIN
then
821 if PlayerModelsArray
[FID
].PainSounds
= nil then Exit
;
823 for a
:= 0 to High(PlayerModelsArray
[FID
].PainSounds
) do
824 if PlayerModelsArray
[FID
].PainSounds
[a
].Level
= Level
then
826 SetLength(TempArray
, Length(TempArray
) + 1);
827 TempArray
[High(TempArray
)] := PlayerModelsArray
[FID
].PainSounds
[a
].ID
;
832 if (Level
in [2, 3, 5]) and (PlayerModelsArray
[FID
].SlopSound
> 0) then
834 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
835 if PlayerModelsArray
[FID
].SlopSound
= 1 then
841 if PlayerModelsArray
[FID
].DieSounds
= nil then Exit
;
843 for a
:= 0 to High(PlayerModelsArray
[FID
].DieSounds
) do
844 if PlayerModelsArray
[FID
].DieSounds
[a
].Level
= Level
then
846 SetLength(TempArray
, Length(TempArray
) + 1);
847 TempArray
[High(TempArray
)] := PlayerModelsArray
[FID
].DieSounds
[a
].ID
;
849 if (TempArray
= nil) and (Level
= 5) then
851 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
857 if TempArray
= nil then Exit
;
859 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
864 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
871 procedure TPlayerModel
.SetFire (Fire
: Boolean);
874 FFireCounter
:= PlayerModelsArray
[FID
].ModelSpeed
[A_ATTACK
] * PlayerModelsArray
[FID
].Anim
[TDirection
.D_RIGHT
, A_ATTACK
].Frames
879 function TPlayerModel
.GetFire (): Boolean;
881 Result
:= FFireCounter
> 0
884 procedure TPlayerModel
.SetFlag (Flag
: Byte);
889 procedure TPlayerModel
.SetWeapon (Weapon
: Byte);
891 FCurrentWeapon
:= Weapon
894 function TPlayerModel
.GetBlood (): TModelBlood
;
896 Result
:= PlayerModelsArray
[FID
].Blood
899 function TPlayerModel
.GetName (): String;
901 Result
:= PlayerModelsArray
[FID
].Name
904 procedure TPlayerModel
.Update
;
906 if FAnimState
<> nil then
908 if FFireCounter
> 0 then
912 procedure g_PlayerModel_LoadAll
;
915 knownFiles
: array of AnsiString = nil;
920 // load models from all possible wad types, in all known directories
921 // this does a loosy job (linear search, ooph!), but meh
922 for wext
in wadExtensions
do
924 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
926 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
930 for s
in knownFiles
do
932 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
940 SetLength(knownFiles
, length(knownFiles
)+1);
941 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
943 until (FindNext(SR
) <> 0);
948 if (length(knownFiles
) = 0) then
949 raise Exception
.Create('no player models found!');
950 if (length(knownFiles
) = 1) then
951 e_LogWriteln('1 player model found.', TMsgType
.Notify
)
953 e_LogWritefln('%d player models found.', [Integer(length(knownFiles
))], TMsgType
.Notify
);
954 for s
in knownFiles
do
955 if not g_PlayerModel_Load(s
) then
956 e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);