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);
91 TModelSoundArray
= Array of TModelSound
;
92 TGibsArray
= Array of TGibSprite
;
93 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
] of
94 Array [A_STAND
..A_LAST
] of
95 Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array of TDFPoint
;
96 TModelMatrix
= Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
98 TPlayerModel
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
101 FDirection
: TDirection
;
104 FCurrentAnimation
: Byte;
106 FMaskAnim
: TModelMatrix
;
107 FWeaponPoints
: TWeaponPoints
;
108 FPainSounds
: TModelSoundArray
;
109 FDieSounds
: TModelSoundArray
;
111 FCurrentWeapon
: Byte;
112 FDrawWeapon
: Boolean;
114 FFlagPoint
: TDFPoint
;
115 FFlagAngle
: SmallInt;
116 FFlagAnim
: TAnimation
;
121 destructor Destroy(); override;
122 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
123 function GetCurrentAnimation
: TAnimation
;
124 function GetCurrentAnimationMask
: TAnimation
;
125 procedure SetColor(Red
, Green
, Blue
: Byte);
126 procedure SetWeapon(Weapon
: Byte);
127 procedure SetFlag(Flag
: Byte);
128 procedure SetFire(Fire
: Boolean);
129 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
133 property Fire
: Boolean read FFire
;
134 property Direction
: TDirection read FDirection write FDirection
;
135 property Animation
: Byte read FCurrentAnimation
;
136 property Weapon
: Byte read FCurrentWeapon
;
137 property Name
: String read FName
;
140 property Color
: TRGB read FColor write FColor
;
141 property Blood
: TModelBlood read FBlood
;
143 property Anim
: TModelMatrix read FAnim
;
144 property MaskAnim
: TModelMatrix read FMaskAnim
;
145 property CurrentAnimation
: Byte read FCurrentAnimation
;
147 property CurrentWeapon
: Byte read FCurrentWeapon
;
148 property DrawWeapon
: Boolean read FDrawWeapon
;
149 property WeaponPoints
: TWeaponPoints read FWeaponPoints
;
151 property Flag
: Byte read FFlag
;
152 property FlagAnim
: TAnimation read FFlagAnim
;
153 property FlagAngle
: SmallInt read FFlagAngle
;
154 property FlagPoint
: TDFPoint read FFlagPoint
;
157 procedure g_PlayerModel_FreeData();
158 function g_PlayerModel_Load(FileName
: String): Boolean;
159 function g_PlayerModel_GetNames(): SSArray
;
160 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
161 function g_PlayerModel_GetBlood(ModelName
: String): TModelBlood
;
162 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
163 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
164 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
170 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
171 e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
174 TPlayerModelInfo
= record
176 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
179 WeaponPoints
: TWeaponPoints
;
181 PainSounds
: TModelSoundArray
;
182 DieSounds
: TModelSoundArray
;
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');
207 PlayerModelsArray
: Array of TPlayerModelInfo
;
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 ExtAnimFromBaseAnim(MName
: String; 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
288 AName
, OName
: String;
290 // HACK: shitty workaround to duplicate base animations
291 // in place of extended, replace with something better later
293 Assert((AIdx
> A_LASTBASE
) and (AIdx
<= A_LASTEXT
));
294 OIdx
:= CopyAnim
[AIdx
];
296 AName
:= MName
+ '_RIGHTANIM' + IntToStr(AIdx
);
297 OName
:= MName
+ '_RIGHTANIM' + IntToStr(OIdx
);
298 Assert(g_Frames_Dup(AName
, OName
));
299 Assert(g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK'));
300 AName
:= MName
+ '_LEFTANIM' + IntToStr(AIdx
);
301 OName
:= MName
+ '_LEFTANIM' + IntToStr(OIdx
);
302 if g_Frames_Exists(AName
) then
304 g_Frames_Dup(AName
, OName
);
305 g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK');
308 with PlayerModelsArray
[High(PlayerModelsArray
)] do
310 for W
:= WP_FIRST
+ 1 to WP_LAST
do
312 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
314 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
315 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
316 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
322 function g_PlayerModel_CalcGibSize (pData
: Pointer; dataSize
, x
, y
, w
, h
: Integer): TRectWH
;
323 var i
, j
: Integer; done
: Boolean; img
: TImageData
;
325 function IsVoid (i
, j
: Integer): Boolean;
327 result
:= Byte((PByte(img
.bits
) + (y
+j
)*img
.width
*4 + (x
+i
)*4 + 3)^) = 0
332 assert(LoadImageFromMemory(pData
, dataSize
, img
));
334 (* trace x from right to left *)
335 done
:= false; i
:= 0;
336 while not done
and (i
< w
) do
339 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
340 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
345 (* trace y from up to down *)
346 done
:= false; j
:= 0;
347 while not done
and (j
< h
) do
350 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
351 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
356 (* trace x from right to left *)
357 done
:= false; i
:= w
- 1;
358 while not done
and (i
>= 0) do
361 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
362 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
363 result
.width
:= i
- result
.x
+ 1;
367 (* trace y from down to up *)
368 done
:= false; j
:= h
- 1;
369 while not done
and (j
>= 0) do
372 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
373 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
374 result
.height
:= j
- result
.y
+ 1;
381 function g_PlayerModel_Load(FileName
: string): Boolean;
384 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
387 pData
, pData2
: Pointer;
393 e_WriteLog(Format('Loading player model "%s"...', [FileName
]), TMsgType
.Notify
);
397 WAD
:= TWADFile
.Create
;
398 WAD
.ReadFile(FileName
);
400 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
406 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
412 config
:= TConfig
.CreateMem(pData
, len
);
415 s
:= config
.ReadStr('Model', 'name', '');
423 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
424 ID
:= High(PlayerModelsArray
);
426 prefix
:= FileName
+':TEXTURES\';
428 with PlayerModelsArray
[ID
].Info
do
431 Author
:= config
.ReadStr('Model', 'author', '');
432 Description
:= config
.ReadStr('Model', 'description', '');
435 with PlayerModelsArray
[ID
] do
437 Blood
.R
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'R', 150)));
438 Blood
.G
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'G', 0)));
439 Blood
.B
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'B', 0)));
440 case config
.ReadStr('Blood', 'Kind', 'NORMAL') of
441 'NORMAL': Blood
.Kind
:= BLOOD_NORMAL
;
442 'SPARKS': Blood
.Kind
:= BLOOD_CSPARKS
;
443 'COMBINE': Blood
.Kind
:= BLOOD_COMBINE
;
445 Blood
.Kind
:= BLOOD_NORMAL
449 for b
:= A_STAND
to A_LAST
do
451 aname
:= s
+'_RIGHTANIM'+IntToStr(b
);
452 //e_LogWritefln('### MODEL FILE: [%s]', [prefix+config.ReadStr(AnimNames[b], 'resource', '')]);
453 if not (g_Frames_CreateWAD(nil, aname
,
454 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
455 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
456 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
457 g_Frames_CreateWAD(nil, aname
+'_MASK',
458 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
459 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
460 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
462 if b
<= A_LASTBASE
then
470 ExtAnimFromBaseAnim(s
, b
);
475 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
476 for bb
:= A_STAND
to A_LAST
do
477 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
479 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
480 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
481 if f
> 2 then f
:= 2*f
-2;
482 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
485 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
486 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
488 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
489 g_Frames_CreateWAD(nil, aname
,
490 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
491 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
492 config
.ReadBool(AnimNames
[b
], 'backanim', False));
494 g_Frames_CreateWAD(nil, aname
+'_MASK',
495 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
496 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
497 config
.ReadBool(AnimNames
[b
], 'backanim', False));
500 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
503 with PlayerModelsArray
[ID
], config
do
505 prefix
:= FileName
+':SOUNDS\';
509 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
512 SetLength(PainSounds
, Length(PainSounds
)+1);
513 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
514 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
521 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
524 SetLength(DieSounds
, Length(DieSounds
)+1);
525 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
526 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
531 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
533 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
536 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
537 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
539 for a
:= 0 to High(Gibs
) do
540 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
541 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
543 //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
544 Gibs
[a
].Rect
:= g_PlayerModel_CalcGibSize(pData
, lenpd
, a
*32, 0, 32, 32);
546 if Height
> 3 then Height
:= Height
-1-Random(2);
547 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
555 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
556 for bb
:= A_STAND
to A_LAST
do
557 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
559 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
560 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
561 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
563 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
565 // workaround for flamethrower
566 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
567 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
568 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
571 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
576 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
577 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
579 A_WALKATTACK
, A_WALK
:
581 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
582 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
586 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
587 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
589 A_WALKSEEUP
, A_SEEUP
:
591 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
592 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
594 A_WALKSEEDOWN
, A_SEEDOWN
:
596 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
597 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
599 A_WALKATTACKUP
, A_ATTACKUP
:
601 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
602 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
604 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
606 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
607 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
612 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
614 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, TDirection
.D_LEFT
,
615 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
616 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
618 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
620 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
621 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
624 if not ok
then Break
;
626 {if ok then g_Console_Add(Info.Name+' weapon points ok')
627 else g_Console_Add(Info.Name+' weapon points fail');}
628 Info
.HaveWeapon
:= ok
;
630 s
:= config
.ReadStr('Model', 'flag_point', '');
631 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
633 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
642 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
650 if PlayerModelsArray
= nil then Exit
;
652 for a
:= 0 to High(PlayerModelsArray
) do
653 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
655 Result
:= TPlayerModel
.Create
;
657 with PlayerModelsArray
[a
] do
659 Result
.FName
:= Info
.Name
;
660 Result
.FBlood
:= Blood
;
662 for b
:= A_STAND
to A_LAST
do
664 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
665 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
672 Result
.FAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
674 Result
.FMaskAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
676 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
677 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
678 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
679 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
681 Result
.FAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
683 Result
.FMaskAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
687 Result
.FPainSounds
:= PainSounds
;
688 Result
.FDieSounds
:= DieSounds
;
689 Result
.FSlopSound
:= SlopSound
;
690 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
691 Result
.FWeaponPoints
:= WeaponPoints
;
693 Result
.FFlagPoint
:= FlagPoint
;
694 Result
.FFlagAngle
:= FlagAngle
;
701 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
709 if PlayerModelsArray
= nil then Exit
;
710 for a
:= 0 to High(PlayerModelsArray
) do
711 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
712 with PlayerModelsArray
[a
] do
714 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
716 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
717 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
719 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
720 _Anim
.Speed
:= ModelSpeed
[Anim
];
722 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
723 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
725 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
726 _Mask
.Speed
:= ModelSpeed
[Anim
];
734 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
741 if PlayerModelsArray
= nil then Exit
;
742 if gGibsCount
= 0 then Exit
;
746 SetLength(Gibs
, gGibsCount
);
748 for a
:= 0 to High(PlayerModelsArray
) do
749 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
751 for i
:= 0 to High(Gibs
) do
753 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
760 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
761 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
763 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
765 if Gibs
[i
].OnlyOne
then c
:= True;
773 function g_PlayerModel_GetNames(): SSArray
;
779 if PlayerModelsArray
= nil then Exit
;
781 for i
:= 0 to High(PlayerModelsArray
) do
783 SetLength(Result
, Length(Result
)+1);
784 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
788 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
792 FillChar(Result
, SizeOf(Result
), 0);
793 if PlayerModelsArray
= nil then Exit
;
795 for a
:= 0 to High(PlayerModelsArray
) do
796 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
798 Result
:= PlayerModelsArray
[a
].Info
;
803 function g_PlayerModel_GetBlood(ModelName
: string): TModelBlood
;
810 Result
.Kind
:= BLOOD_NORMAL
;
811 if PlayerModelsArray
= nil then Exit
;
813 for a
:= 0 to High(PlayerModelsArray
) do
814 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
816 Result
:= PlayerModelsArray
[a
].Blood
;
821 procedure g_PlayerModel_FreeData();
826 e_WriteLog('Releasing models...', TMsgType
.Notify
);
828 if PlayerModelsArray
= nil then Exit
;
830 for i
:= 0 to High(PlayerModelsArray
) do
831 with PlayerModelsArray
[i
] do
833 for a
:= A_STAND
to A_LAST
do
835 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
836 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
837 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
838 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
841 if PainSounds
<> nil then
842 for b
:= 0 to High(PainSounds
) do
843 e_DeleteSound(PainSounds
[b
].ID
);
845 if DieSounds
<> nil then
846 for b
:= 0 to High(DieSounds
) do
847 e_DeleteSound(DieSounds
[b
].ID
);
850 for b
:= 0 to High(Gibs
) do
852 e_DeleteTexture(Gibs
[b
].ID
);
853 e_DeleteTexture(Gibs
[b
].MaskID
);
857 PlayerModelsArray
:= nil;
862 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
864 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
866 FCurrentAnimation
:= Animation
;
868 if (FDirection
= TDirection
.D_LEFT
) and
869 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) and
870 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
872 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
873 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
877 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
878 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
882 destructor TPlayerModel
.Destroy();
886 for a
:= A_STAND
to A_LAST
do
888 FAnim
[TDirection
.D_LEFT
][a
].Free();
889 FMaskAnim
[TDirection
.D_LEFT
][a
].Free();
890 FAnim
[TDirection
.D_RIGHT
][a
].Free();
891 FMaskAnim
[TDirection
.D_RIGHT
][a
].Free();
897 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
899 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
900 Result
:= FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
902 Result
:= FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
905 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
907 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
908 Result
:= FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
910 Result
:= FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
913 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
915 TempArray
: array of DWORD
;
919 SetLength(TempArray
, 0);
921 if SoundType
= MODELSOUND_PAIN
then
923 if FPainSounds
= nil then Exit
;
925 for a
:= 0 to High(FPainSounds
) do
926 if FPainSounds
[a
].Level
= Level
then
928 SetLength(TempArray
, Length(TempArray
)+1);
929 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
934 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
936 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
937 if FSlopSound
= 1 then
943 if FDieSounds
= nil then Exit
;
945 for a
:= 0 to High(FDieSounds
) do
946 if FDieSounds
[a
].Level
= Level
then
948 SetLength(TempArray
, Length(TempArray
)+1);
949 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
951 if (TempArray
= nil) and (Level
= 5) then
953 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
959 if TempArray
= nil then Exit
;
961 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
966 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
973 procedure TPlayerModel
.SetFire(Fire
: Boolean);
977 if FFire
then FFireCounter
:= FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].Speed
*FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].TotalFrames
978 else FFireCounter
:= 0;
981 procedure TPlayerModel
.SetFlag(Flag
: Byte);
991 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
992 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
996 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
999 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
1001 FCurrentWeapon
:= Weapon
;
1004 procedure TPlayerModel
.Update();
1006 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1007 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1009 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1010 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1012 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1014 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;