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;
118 destructor Destroy(); override;
119 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
120 procedure SetColor(Red
, Green
, Blue
: Byte);
121 procedure SetWeapon(Weapon
: Byte);
122 procedure SetFlag(Flag
: Byte);
123 procedure SetFire(Fire
: Boolean);
124 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
127 function GetBlood (): TModelBlood
;
128 function GetName (): String;
131 property Fire
: Boolean read FFire
;
132 property Direction
: TDirection read FDirection write FDirection
;
133 property Animation
: Byte read FCurrentAnimation
;
134 property Weapon
: Byte read FCurrentWeapon
;
137 property Color
: TRGB read FColor write FColor
;
138 property AnimState
: TAnimationState read FAnimState
;
139 property CurrentAnimation
: Byte read FCurrentAnimation
;
140 property CurrentWeapon
: Byte read FCurrentWeapon
;
141 property Flag
: Byte read FFlag
;
142 property ID
: Integer read FID
;
145 procedure g_PlayerModel_LoadAll
;
146 procedure g_PlayerModel_FreeData();
147 function g_PlayerModel_Load(FileName
: String): Boolean;
148 function g_PlayerModel_GetNames(): SSArray
;
149 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
150 function g_PlayerModel_GetBlood(ModelName
: String): TModelBlood
;
151 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
152 function g_PlayerModel_GetAnim(ModelName
: String; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
153 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
155 (* --- private data --- *)
158 TPlayerModelInfo
= record
160 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
163 WeaponPoints
: TWeaponPoints
;
164 Gibs
: TGibsArray
; // !!! move to render
165 PainSounds
: TModelSoundArray
;
166 DieSounds
: TModelSoundArray
;
169 // =======================
171 Anim
: TModelTextures
;
179 PlayerModelsArray
: Array of TPlayerModelInfo
;
184 g_sound
, g_console
, SysUtils
, g_player
, CONFIG
, r_textures
, r_animations
,
185 e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
188 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
190 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
191 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
192 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
193 (X
:16; Y
:16), (X
:8; Y
:8));
195 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
196 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
197 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
199 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
200 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
201 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
202 'FistAttackUpAnim', 'FistAttackDownAnim');
203 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
204 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
206 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
216 if Length(str
) < 3 then
219 for a
:= 1 to Length(str
) do
220 if (str
[a
] = ',') or (a
= Length(str
)) then
222 s
:= Copy(str
, 1, a
);
223 if s
[Length(s
)] = ',' then
224 SetLength(s
, Length(s
)-1);
227 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
228 (x
< -64) or (x
> 128) or
229 (y
< -64) or (y
> 128) then
241 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
242 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
251 backanim
:= backanim
and (frames
> 2);
253 for a
:= 1 to frames
do
255 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
258 with wpoints
[weapon
, anim
, dir
, a
-1] do
260 X
:= X
- WEAPONBASE
[weapon
].X
;
261 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
262 if dir
= TDirection
.D_LEFT
then
267 h
:= High(wpoints
[weapon
, anim
, dir
]);
269 for b
:= h
downto frames
do
270 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
275 procedure g_PlayerMode_ExtendPoints (id
: Integer; AIdx
: Integer);
277 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
278 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
279 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
280 A_ATTACKUP
, A_ATTACKDOWN
282 var W
, I
, OIdx
: Integer; D
: TDirection
;
284 OIdx
:= CopyAnim
[AIdx
];
285 with PlayerModelsArray
[id
] do
287 for W
:= WP_FIRST
+ 1 to WP_LAST
do
289 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
291 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
292 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
293 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
299 function g_PlayerModel_CalcGibSize (pData
: Pointer; dataSize
, x
, y
, w
, h
: Integer): TRectWH
;
300 var i
, j
: Integer; done
: Boolean; img
: TImageData
;
302 function IsVoid (i
, j
: Integer): Boolean;
304 result
:= Byte((PByte(img
.bits
) + (y
+j
)*img
.width
*4 + (x
+i
)*4 + 3)^) = 0
309 assert(LoadImageFromMemory(pData
, dataSize
, img
));
311 (* trace x from right to left *)
312 done
:= false; i
:= 0;
313 while not done
and (i
< w
) do
316 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
317 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
322 (* trace y from up to down *)
323 done
:= false; j
:= 0;
324 while not done
and (j
< h
) do
327 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
328 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
333 (* trace x from right to left *)
334 done
:= false; i
:= w
- 1;
335 while not done
and (i
>= 0) do
338 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
339 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
340 result
.width
:= i
- result
.x
+ 1;
344 (* trace y from down to up *)
345 done
:= false; j
:= h
- 1;
346 while not done
and (j
>= 0) do
349 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
350 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
351 result
.height
:= j
- result
.y
+ 1;
358 function g_PlayerModel_Load(FileName
: string): Boolean;
361 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
364 pData
, pData2
: Pointer;
368 ok
, chk
, chk2
: Boolean;
370 e_WriteLog(Format('Loading player model "%s"...', [FileName
]), TMsgType
.Notify
);
374 WAD
:= TWADFile
.Create
;
375 WAD
.ReadFile(FileName
);
377 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
383 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
389 config
:= TConfig
.CreateMem(pData
, len
);
392 s
:= config
.ReadStr('Model', 'name', '');
400 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
401 ID
:= High(PlayerModelsArray
);
403 prefix
:= FileName
+':TEXTURES\';
405 with PlayerModelsArray
[ID
].Info
do
408 Author
:= config
.ReadStr('Model', 'author', '');
409 Description
:= config
.ReadStr('Model', 'description', '');
412 PlayerModelsArray
[ID
].FileName
:= FileName
;
413 with PlayerModelsArray
[ID
] do
415 Blood
.R
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'R', 150)));
416 Blood
.G
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'G', 0)));
417 Blood
.B
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'B', 0)));
418 case config
.ReadStr('Blood', 'Kind', 'NORMAL') of
419 'NORMAL': Blood
.Kind
:= BLOOD_NORMAL
;
420 'SPARKS': Blood
.Kind
:= BLOOD_CSPARKS
;
421 'COMBINE': Blood
.Kind
:= BLOOD_COMBINE
;
423 Blood
.Kind
:= BLOOD_NORMAL
427 for b
:= A_STAND
to A_LAST
do
429 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
] do
431 Resource
:= config
.ReadStr(AnimNames
[b
], 'resource', '');
432 Mask
:= config
.ReadStr(AnimNames
[b
], 'mask', '');
433 Frames
:= config
.ReadInt(AnimNames
[b
], 'frames', 1);
434 Back
:= config
.ReadBool(AnimNames
[b
], 'backanim', False);
435 if (Resource
= '') or (Mask
= '') then
437 if b
<= A_LASTBASE
then
445 g_PlayerMode_ExtendPoints(ID
, b
);
451 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
452 for bb
:= A_STAND
to A_LAST
do
453 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
455 f
:= PlayerModelsArray
[ID
].Anim
[cc
, bb
].Frames
;
456 if PlayerModelsArray
[ID
].Anim
[cc
, bb
].Back
and (f
> 2) then
458 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
461 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_LEFT
, b
] do
463 Frames
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Frames
;
464 Back
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Back
;
467 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
470 with PlayerModelsArray
[ID
], config
do
472 prefix
:= FileName
+':SOUNDS\';
476 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
479 SetLength(PainSounds
, Length(PainSounds
)+1);
480 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
481 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
488 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
491 SetLength(DieSounds
, Length(DieSounds
)+1);
492 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
493 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
498 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
500 GibsCount
:= config
.ReadInt('Gibs', 'count', 0);
501 GibsResource
:= config
.ReadStr('Gibs', 'resource', 'GIBS');
502 GibsMask
:= config
.ReadStr('Gibs', 'mask', 'GIBSMASK');
503 GibsOnce
:= config
.ReadInt('Gibs', 'once', -1);
505 SetLength(Gibs
, GibsCount
); // !!! remove load
507 (WAD
.GetResource('TEXTURES/' + GibsResource
, pData
, lenpd
)) and
508 (WAD
.GetResource('TEXTURES/' + GibsMask
, pData2
, lenpd2
)) then
510 for a
:= 0 to High(Gibs
) do
511 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
512 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
514 //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
515 Gibs
[a
].Rect
:= g_PlayerModel_CalcGibSize(pData
, lenpd
, a
*32, 0, 32, 32);
517 if Height
> 3 then Height
:= Height
-1-Random(2);
518 Gibs
[a
].OnlyOne
:= GibsOnce
= a
+ 1;
526 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
527 for bb
:= A_STAND
to A_LAST
do
528 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
530 chk
:= GetWeapPoints(
531 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '_points', ''),
535 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
536 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
539 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
541 // workaround for flamethrower
542 chk
:= GetWeapPoints(
543 config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
] + '_points', ''),
547 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
548 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
552 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
557 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
558 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
560 A_WALKATTACK
, A_WALK
:
562 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
563 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
567 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
568 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
570 A_WALKSEEUP
, A_SEEUP
:
572 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
573 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
575 A_WALKSEEDOWN
, A_SEEDOWN
:
577 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
578 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
580 A_WALKATTACKUP
, A_ATTACKUP
:
582 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
583 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
585 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
587 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
588 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
594 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
596 chk2
:= GetWeapPoints(
597 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '2_points', ''),
601 Anim
[TDirection
.D_LEFT
, bb
].Frames
,
602 Anim
[TDirection
.D_LEFT
, bb
].Back
,
607 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
609 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
610 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
614 if not ok
then Break
;
616 {if ok then g_Console_Add(Info.Name+' weapon points ok')
617 else g_Console_Add(Info.Name+' weapon points fail');}
618 Info
.HaveWeapon
:= ok
;
620 s
:= config
.ReadStr('Model', 'flag_point', '');
621 if not GetPoint(s
, FlagPoint
) then
622 FlagPoint
:= FLAG_DEFPOINT
;
624 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
633 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
638 if PlayerModelsArray
= nil then Exit
;
640 for a
:= 0 to High(PlayerModelsArray
) do
642 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
644 Result
:= TPlayerModel
.Create
;
646 with PlayerModelsArray
[a
] do
649 Result
.ChangeAnimation(A_STAND
, True);
656 function g_PlayerModel_GetAnim(ModelName
: string; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
664 if PlayerModelsArray
= nil then Exit
;
665 for a
:= 0 to High(PlayerModelsArray
) do
666 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
667 with PlayerModelsArray
[a
] do
669 if AnimTyp
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
671 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(AnimTyp
)) then
672 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(AnimTyp
)) then Exit
;
674 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
675 _Anim
.Speed
:= ModelSpeed
[AnimTyp
];
677 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(AnimTyp
)+'_MASK') then
678 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(AnimTyp
)+'_MASK') then Exit
;
680 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
681 _Mask
.Speed
:= ModelSpeed
[AnimTyp
];
689 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
696 if PlayerModelsArray
= nil then Exit
;
697 if gGibsCount
= 0 then Exit
;
701 SetLength(Gibs
, gGibsCount
);
703 for a
:= 0 to High(PlayerModelsArray
) do
704 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
706 for i
:= 0 to High(Gibs
) do
708 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
715 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
716 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
718 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
720 if Gibs
[i
].OnlyOne
then c
:= True;
728 function g_PlayerModel_GetNames(): SSArray
;
734 if PlayerModelsArray
= nil then Exit
;
736 for i
:= 0 to High(PlayerModelsArray
) do
738 SetLength(Result
, Length(Result
)+1);
739 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
743 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
747 FillChar(Result
, SizeOf(Result
), 0);
748 if PlayerModelsArray
= nil then Exit
;
750 for a
:= 0 to High(PlayerModelsArray
) do
751 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
753 Result
:= PlayerModelsArray
[a
].Info
;
758 function g_PlayerModel_GetBlood(ModelName
: string): TModelBlood
;
765 Result
.Kind
:= BLOOD_NORMAL
;
766 if PlayerModelsArray
= nil then Exit
;
768 for a
:= 0 to High(PlayerModelsArray
) do
769 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
771 Result
:= PlayerModelsArray
[a
].Blood
;
776 procedure g_PlayerModel_FreeData();
779 e_WriteLog('Releasing models...', TMsgType
.Notify
);
781 if PlayerModelsArray
= nil then Exit
;
783 for i
:= 0 to High(PlayerModelsArray
) do
785 with PlayerModelsArray
[i
] do
787 if PainSounds
<> nil then
788 for b
:= 0 to High(PainSounds
) do
789 e_DeleteSound(PainSounds
[b
].ID
);
790 if DieSounds
<> nil then
791 for b
:= 0 to High(DieSounds
) do
792 e_DeleteSound(DieSounds
[b
].ID
);
795 PlayerModelsArray
:= nil;
800 procedure TPlayerModel
.ChangeAnimation (Animation
: Byte; Force
: Boolean = False);
801 var once
: Boolean; speed
, count
: Integer;
804 if FCurrentAnimation
= Animation
then
806 FCurrentAnimation
:= Animation
;
807 once
:= FCurrentAnimation
in [A_STAND
, A_WALK
];
808 speed
:= PlayerModelsArray
[FID
].ModelSpeed
[FCurrentAnimation
];
809 count
:= PlayerModelsArray
[FID
].Anim
[FDirection
, FCurrentAnimation
].Frames
;
810 FAnimState
:= TAnimationState
.Create(once
, speed
, count
);
813 destructor TPlayerModel
.Destroy();
819 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
821 TempArray
: array of DWORD
;
825 SetLength(TempArray
, 0);
827 if SoundType
= MODELSOUND_PAIN
then
829 if PlayerModelsArray
[FID
].PainSounds
= nil then Exit
;
831 for a
:= 0 to High(PlayerModelsArray
[FID
].PainSounds
) do
832 if PlayerModelsArray
[FID
].PainSounds
[a
].Level
= Level
then
834 SetLength(TempArray
, Length(TempArray
) + 1);
835 TempArray
[High(TempArray
)] := PlayerModelsArray
[FID
].PainSounds
[a
].ID
;
840 if (Level
in [2, 3, 5]) and (PlayerModelsArray
[FID
].SlopSound
> 0) then
842 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
843 if PlayerModelsArray
[FID
].SlopSound
= 1 then
849 if PlayerModelsArray
[FID
].DieSounds
= nil then Exit
;
851 for a
:= 0 to High(PlayerModelsArray
[FID
].DieSounds
) do
852 if PlayerModelsArray
[FID
].DieSounds
[a
].Level
= Level
then
854 SetLength(TempArray
, Length(TempArray
) + 1);
855 TempArray
[High(TempArray
)] := PlayerModelsArray
[FID
].DieSounds
[a
].ID
;
857 if (TempArray
= nil) and (Level
= 5) then
859 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
865 if TempArray
= nil then Exit
;
867 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
872 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
879 procedure TPlayerModel
.SetFire(Fire
: Boolean);
883 FFireCounter
:= PlayerModelsArray
[FID
].ModelSpeed
[A_ATTACK
] * PlayerModelsArray
[FID
].Anim
[TDirection
.D_RIGHT
, A_ATTACK
].Frames
888 procedure TPlayerModel
.SetFlag (Flag
: Byte);
893 procedure TPlayerModel
.SetWeapon (Weapon
: Byte);
895 FCurrentWeapon
:= Weapon
898 function TPlayerModel
.GetBlood (): TModelBlood
;
900 Result
:= PlayerModelsArray
[FID
].Blood
903 function TPlayerModel
.GetName (): String;
905 Result
:= PlayerModelsArray
[FID
].Info
.Name
908 procedure TPlayerModel
.Update
;
910 if FAnimState
<> nil then
912 if FFireCounter
> 0 then
918 procedure g_PlayerModel_LoadAll
;
921 knownFiles
: array of AnsiString = nil;
926 // load models from all possible wad types, in all known directories
927 // this does a loosy job (linear search, ooph!), but meh
928 for wext
in wadExtensions
do
930 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
932 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
936 for s
in knownFiles
do
938 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
946 SetLength(knownFiles
, length(knownFiles
)+1);
947 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
949 until (FindNext(SR
) <> 0);
954 if (length(knownFiles
) = 0) then
955 raise Exception
.Create('no player models found!');
956 if (length(knownFiles
) = 1) then
957 e_LogWriteln('1 player model found.', TMsgType
.Notify
)
959 e_LogWritefln('%d player models found.', [Integer(length(knownFiles
))], TMsgType
.Notify
);
960 for s
in knownFiles
do
961 if not g_PlayerModel_Load(s
) then
962 e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);