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 FPainSounds
: TModelSoundArray
;
112 FDieSounds
: TModelSoundArray
;
114 FCurrentWeapon
: Byte;
121 destructor Destroy(); override;
122 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
123 procedure SetColor(Red
, Green
, Blue
: Byte);
124 procedure SetWeapon(Weapon
: Byte);
125 procedure SetFlag(Flag
: Byte);
126 procedure SetFire(Fire
: Boolean);
127 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
130 function GetBlood (): TModelBlood
;
131 function GetName (): String;
134 property Fire
: Boolean read FFire
;
135 property Direction
: TDirection read FDirection write FDirection
;
136 property Animation
: Byte read FCurrentAnimation
;
137 property Weapon
: Byte read FCurrentWeapon
;
140 property Color
: TRGB read FColor write FColor
;
141 property AnimState
: TAnimationState read FAnimState
;
142 property CurrentAnimation
: Byte read FCurrentAnimation
;
143 property CurrentWeapon
: Byte read FCurrentWeapon
;
144 property Flag
: Byte read FFlag
;
145 property ID
: Integer read FID
;
148 procedure g_PlayerModel_LoadAll
;
149 procedure g_PlayerModel_FreeData();
150 function g_PlayerModel_Load(FileName
: String): Boolean;
151 function g_PlayerModel_GetNames(): SSArray
;
152 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
153 function g_PlayerModel_GetBlood(ModelName
: String): TModelBlood
;
154 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
155 function g_PlayerModel_GetAnim(ModelName
: String; AnimTyp
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
156 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
158 (* --- private data --- *)
161 TPlayerModelInfo
= record
163 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
166 WeaponPoints
: TWeaponPoints
;
167 Gibs
: TGibsArray
; // !!! move to render
168 PainSounds
: TModelSoundArray
;
169 DieSounds
: TModelSoundArray
;
172 // =======================
174 Anim
: TModelTextures
;
182 PlayerModelsArray
: Array of TPlayerModelInfo
;
187 g_sound
, g_console
, SysUtils
, g_player
, CONFIG
, r_textures
, r_animations
,
188 e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
191 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
193 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
194 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
195 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
196 (X
:16; Y
:16), (X
:8; Y
:8));
198 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
199 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
200 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
202 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
203 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
204 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
205 'FistAttackUpAnim', 'FistAttackDownAnim');
206 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
207 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
209 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
219 if Length(str
) < 3 then
222 for a
:= 1 to Length(str
) do
223 if (str
[a
] = ',') or (a
= Length(str
)) then
225 s
:= Copy(str
, 1, a
);
226 if s
[Length(s
)] = ',' then
227 SetLength(s
, Length(s
)-1);
230 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
231 (x
< -64) or (x
> 128) or
232 (y
< -64) or (y
> 128) then
244 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
245 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
254 backanim
:= backanim
and (frames
> 2);
256 for a
:= 1 to frames
do
258 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
261 with wpoints
[weapon
, anim
, dir
, a
-1] do
263 X
:= X
- WEAPONBASE
[weapon
].X
;
264 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
265 if dir
= TDirection
.D_LEFT
then
270 h
:= High(wpoints
[weapon
, anim
, dir
]);
272 for b
:= h
downto frames
do
273 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
278 procedure g_PlayerMode_ExtendPoints (id
: Integer; AIdx
: Integer);
280 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
281 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
282 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
283 A_ATTACKUP
, A_ATTACKDOWN
285 var W
, I
, OIdx
: Integer; D
: TDirection
;
287 OIdx
:= CopyAnim
[AIdx
];
288 with PlayerModelsArray
[id
] do
290 for W
:= WP_FIRST
+ 1 to WP_LAST
do
292 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
294 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
295 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
296 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
302 function g_PlayerModel_CalcGibSize (pData
: Pointer; dataSize
, x
, y
, w
, h
: Integer): TRectWH
;
303 var i
, j
: Integer; done
: Boolean; img
: TImageData
;
305 function IsVoid (i
, j
: Integer): Boolean;
307 result
:= Byte((PByte(img
.bits
) + (y
+j
)*img
.width
*4 + (x
+i
)*4 + 3)^) = 0
312 assert(LoadImageFromMemory(pData
, dataSize
, img
));
314 (* trace x from right to left *)
315 done
:= false; i
:= 0;
316 while not done
and (i
< w
) do
319 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
320 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
325 (* trace y from up to down *)
326 done
:= false; j
:= 0;
327 while not done
and (j
< h
) do
330 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
331 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
336 (* trace x from right to left *)
337 done
:= false; i
:= w
- 1;
338 while not done
and (i
>= 0) do
341 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
342 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
343 result
.width
:= i
- result
.x
+ 1;
347 (* trace y from down to up *)
348 done
:= false; j
:= h
- 1;
349 while not done
and (j
>= 0) do
352 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
353 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
354 result
.height
:= j
- result
.y
+ 1;
361 function g_PlayerModel_Load(FileName
: string): Boolean;
364 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
367 pData
, pData2
: Pointer;
371 ok
, chk
, chk2
: Boolean;
373 e_WriteLog(Format('Loading player model "%s"...', [FileName
]), TMsgType
.Notify
);
377 WAD
:= TWADFile
.Create
;
378 WAD
.ReadFile(FileName
);
380 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
386 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
392 config
:= TConfig
.CreateMem(pData
, len
);
395 s
:= config
.ReadStr('Model', 'name', '');
403 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
404 ID
:= High(PlayerModelsArray
);
406 prefix
:= FileName
+':TEXTURES\';
408 with PlayerModelsArray
[ID
].Info
do
411 Author
:= config
.ReadStr('Model', 'author', '');
412 Description
:= config
.ReadStr('Model', 'description', '');
415 PlayerModelsArray
[ID
].FileName
:= FileName
;
416 with PlayerModelsArray
[ID
] do
418 Blood
.R
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'R', 150)));
419 Blood
.G
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'G', 0)));
420 Blood
.B
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'B', 0)));
421 case config
.ReadStr('Blood', 'Kind', 'NORMAL') of
422 'NORMAL': Blood
.Kind
:= BLOOD_NORMAL
;
423 'SPARKS': Blood
.Kind
:= BLOOD_CSPARKS
;
424 'COMBINE': Blood
.Kind
:= BLOOD_COMBINE
;
426 Blood
.Kind
:= BLOOD_NORMAL
430 for b
:= A_STAND
to A_LAST
do
432 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
] do
434 Resource
:= config
.ReadStr(AnimNames
[b
], 'resource', '');
435 Mask
:= config
.ReadStr(AnimNames
[b
], 'mask', '');
436 Frames
:= config
.ReadInt(AnimNames
[b
], 'frames', 1);
437 Back
:= config
.ReadBool(AnimNames
[b
], 'backanim', False);
438 if (Resource
= '') or (Mask
= '') then
440 if b
<= A_LASTBASE
then
448 g_PlayerMode_ExtendPoints(ID
, b
);
454 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
455 for bb
:= A_STAND
to A_LAST
do
456 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
458 f
:= PlayerModelsArray
[ID
].Anim
[cc
, bb
].Frames
;
459 if PlayerModelsArray
[ID
].Anim
[cc
, bb
].Back
and (f
> 2) then
461 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
464 with PlayerModelsArray
[ID
].Anim
[TDirection
.D_LEFT
, b
] do
466 Frames
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Frames
;
467 Back
:= PlayerModelsArray
[ID
].Anim
[TDirection
.D_RIGHT
, b
].Back
;
470 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
473 with PlayerModelsArray
[ID
], config
do
475 prefix
:= FileName
+':SOUNDS\';
479 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
482 SetLength(PainSounds
, Length(PainSounds
)+1);
483 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
484 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
491 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
494 SetLength(DieSounds
, Length(DieSounds
)+1);
495 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
496 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
501 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
503 GibsCount
:= config
.ReadInt('Gibs', 'count', 0);
504 GibsResource
:= config
.ReadStr('Gibs', 'resource', 'GIBS');
505 GibsMask
:= config
.ReadStr('Gibs', 'mask', 'GIBSMASK');
506 GibsOnce
:= config
.ReadInt('Gibs', 'once', -1);
508 SetLength(Gibs
, GibsCount
); // !!! remove load
510 (WAD
.GetResource('TEXTURES/' + GibsResource
, pData
, lenpd
)) and
511 (WAD
.GetResource('TEXTURES/' + GibsMask
, pData2
, lenpd2
)) then
513 for a
:= 0 to High(Gibs
) do
514 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
515 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
517 //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
518 Gibs
[a
].Rect
:= g_PlayerModel_CalcGibSize(pData
, lenpd
, a
*32, 0, 32, 32);
520 if Height
> 3 then Height
:= Height
-1-Random(2);
521 Gibs
[a
].OnlyOne
:= GibsOnce
= a
+ 1;
529 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
530 for bb
:= A_STAND
to A_LAST
do
531 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
533 chk
:= GetWeapPoints(
534 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '_points', ''),
538 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
539 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
542 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
544 // workaround for flamethrower
545 chk
:= GetWeapPoints(
546 config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
] + '_points', ''),
550 Anim
[TDirection
.D_RIGHT
, bb
].Frames
,
551 Anim
[TDirection
.D_RIGHT
, bb
].Back
,
555 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
560 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
561 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
563 A_WALKATTACK
, A_WALK
:
565 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
566 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
570 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
571 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
573 A_WALKSEEUP
, A_SEEUP
:
575 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
576 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
578 A_WALKSEEDOWN
, A_SEEDOWN
:
580 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
581 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
583 A_WALKATTACKUP
, A_ATTACKUP
:
585 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
586 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
588 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
590 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
591 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
597 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
599 chk2
:= GetWeapPoints(
600 config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
] + '2_points', ''),
604 Anim
[TDirection
.D_LEFT
, bb
].Frames
,
605 Anim
[TDirection
.D_LEFT
, bb
].Back
,
610 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
612 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
613 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
617 if not ok
then Break
;
619 {if ok then g_Console_Add(Info.Name+' weapon points ok')
620 else g_Console_Add(Info.Name+' weapon points fail');}
621 Info
.HaveWeapon
:= ok
;
623 s
:= config
.ReadStr('Model', 'flag_point', '');
624 if not GetPoint(s
, FlagPoint
) then
625 FlagPoint
:= FLAG_DEFPOINT
;
627 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
636 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
641 if PlayerModelsArray
= nil then Exit
;
643 for a
:= 0 to High(PlayerModelsArray
) do
645 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
647 Result
:= TPlayerModel
.Create
;
649 with PlayerModelsArray
[a
] do
651 Result
.FPainSounds
:= PainSounds
;
652 Result
.FDieSounds
:= DieSounds
;
653 Result
.FSlopSound
:= SlopSound
;
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
].Info
.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
, Info
.Name
+'_RIGHTANIM'+IntToStr(AnimTyp
)) then
678 if not g_Frames_Get(ID
, Info
.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
, Info
.Name
+'_RIGHTANIM'+IntToStr(AnimTyp
)+'_MASK') then
684 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(AnimTyp
)+'_MASK') then Exit
;
686 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[AnimTyp
]);
687 _Mask
.Speed
:= ModelSpeed
[AnimTyp
];
695 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
702 if PlayerModelsArray
= nil then Exit
;
703 if gGibsCount
= 0 then Exit
;
707 SetLength(Gibs
, gGibsCount
);
709 for a
:= 0 to High(PlayerModelsArray
) do
710 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
712 for i
:= 0 to High(Gibs
) do
714 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
721 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
722 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
724 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
726 if Gibs
[i
].OnlyOne
then c
:= True;
734 function g_PlayerModel_GetNames(): SSArray
;
740 if PlayerModelsArray
= nil then Exit
;
742 for i
:= 0 to High(PlayerModelsArray
) do
744 SetLength(Result
, Length(Result
)+1);
745 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
749 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
753 FillChar(Result
, SizeOf(Result
), 0);
754 if PlayerModelsArray
= nil then Exit
;
756 for a
:= 0 to High(PlayerModelsArray
) do
757 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
759 Result
:= PlayerModelsArray
[a
].Info
;
764 function g_PlayerModel_GetBlood(ModelName
: string): TModelBlood
;
771 Result
.Kind
:= BLOOD_NORMAL
;
772 if PlayerModelsArray
= nil then Exit
;
774 for a
:= 0 to High(PlayerModelsArray
) do
775 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
777 Result
:= PlayerModelsArray
[a
].Blood
;
782 procedure g_PlayerModel_FreeData();
785 e_WriteLog('Releasing models...', TMsgType
.Notify
);
787 if PlayerModelsArray
= nil then Exit
;
789 for i
:= 0 to High(PlayerModelsArray
) do
791 with PlayerModelsArray
[i
] do
793 if PainSounds
<> nil then
794 for b
:= 0 to High(PainSounds
) do
795 e_DeleteSound(PainSounds
[b
].ID
);
796 if DieSounds
<> nil then
797 for b
:= 0 to High(DieSounds
) do
798 e_DeleteSound(DieSounds
[b
].ID
);
801 PlayerModelsArray
:= nil;
806 procedure TPlayerModel
.ChangeAnimation (Animation
: Byte; Force
: Boolean = False);
807 var once
: Boolean; speed
, count
: Integer;
810 if FCurrentAnimation
= Animation
then
812 FCurrentAnimation
:= Animation
;
813 once
:= FCurrentAnimation
in [A_STAND
, A_WALK
];
814 speed
:= PlayerModelsArray
[FID
].ModelSpeed
[FCurrentAnimation
];
815 count
:= PlayerModelsArray
[FID
].Anim
[FDirection
, FCurrentAnimation
].Frames
;
816 FAnimState
:= TAnimationState
.Create(once
, speed
, count
);
819 destructor TPlayerModel
.Destroy();
825 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
827 TempArray
: array of DWORD
;
831 SetLength(TempArray
, 0);
833 if SoundType
= MODELSOUND_PAIN
then
835 if FPainSounds
= nil then Exit
;
837 for a
:= 0 to High(FPainSounds
) do
838 if FPainSounds
[a
].Level
= Level
then
840 SetLength(TempArray
, Length(TempArray
)+1);
841 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
846 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
848 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
849 if FSlopSound
= 1 then
855 if FDieSounds
= nil then Exit
;
857 for a
:= 0 to High(FDieSounds
) do
858 if FDieSounds
[a
].Level
= Level
then
860 SetLength(TempArray
, Length(TempArray
)+1);
861 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
863 if (TempArray
= nil) and (Level
= 5) then
865 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
871 if TempArray
= nil then Exit
;
873 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
878 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
885 procedure TPlayerModel
.SetFire(Fire
: Boolean);
889 FFireCounter
:= PlayerModelsArray
[FID
].ModelSpeed
[A_ATTACK
] * PlayerModelsArray
[FID
].Anim
[TDirection
.D_RIGHT
, A_ATTACK
].Frames
894 procedure TPlayerModel
.SetFlag (Flag
: Byte);
899 procedure TPlayerModel
.SetWeapon (Weapon
: Byte);
901 FCurrentWeapon
:= Weapon
904 function TPlayerModel
.GetBlood (): TModelBlood
;
906 Result
:= PlayerModelsArray
[FID
].Blood
909 function TPlayerModel
.GetName (): String;
911 Result
:= PlayerModelsArray
[FID
].Info
.Name
914 procedure TPlayerModel
.Update
;
916 if FAnimState
<> nil then
918 if FFireCounter
> 0 then
924 procedure g_PlayerModel_LoadAll
;
927 knownFiles
: array of AnsiString = nil;
932 // load models from all possible wad types, in all known directories
933 // this does a loosy job (linear search, ooph!), but meh
934 for wext
in wadExtensions
do
936 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
938 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
942 for s
in knownFiles
do
944 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
952 SetLength(knownFiles
, length(knownFiles
)+1);
953 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
955 until (FindNext(SR
) <> 0);
960 if (length(knownFiles
) = 0) then
961 raise Exception
.Create('no player models found!');
962 if (length(knownFiles
) = 1) then
963 e_LogWriteln('1 player model found.', TMsgType
.Notify
)
965 e_LogWritefln('%d player models found.', [Integer(length(knownFiles
))], TMsgType
.Notify
);
966 for s
in knownFiles
do
967 if not g_PlayerModel_Load(s
) then
968 e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);