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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 MAPDEF
, g_textures
, g_basic
, g_weapons
, e_graphics
, utils
;
42 A_WALKATTACKDOWN
= 14;
46 A_FISTWALKATTACK
= 18;
50 A_FISTATTACKDOWN
= 22;
53 A_LASTEXT
= A_FISTATTACKDOWN
;
79 TModelSoundArray
= Array of TModelSound
;
80 TGibsArray
= Array of TGibSprite
;
81 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
] of
82 Array [A_STAND
..A_LAST
] of
83 Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array of TDFPoint
;
85 TPlayerModel
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
88 FDirection
: TDirection
;
90 FCurrentAnimation
: Byte;
91 FAnim
: Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
92 FMaskAnim
: Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
93 FWeaponPoints
: TWeaponPoints
;
94 FPainSounds
: TModelSoundArray
;
95 FDieSounds
: TModelSoundArray
;
100 FFlagPoint
: TDFPoint
;
101 FFlagAngle
: SmallInt;
102 FFlagAnim
: TAnimation
;
107 destructor Destroy(); override;
108 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
109 function GetCurrentAnimation
: TAnimation
;
110 function GetCurrentAnimationMask
: TAnimation
;
111 procedure SetColor(Red
, Green
, Blue
: Byte);
112 procedure SetWeapon(Weapon
: Byte);
113 procedure SetFlag(Flag
: Byte);
114 procedure SetFire(Fire
: Boolean);
115 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
117 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
120 property Fire
: Boolean read FFire
;
121 property Direction
: TDirection read FDirection write FDirection
;
122 property Animation
: Byte read FCurrentAnimation
;
123 property Weapon
: Byte read FCurrentWeapon
;
124 property Name
: String read FName
;
127 property Color
: TRGB read FColor write FColor
;
130 procedure g_PlayerModel_LoadData();
131 procedure g_PlayerModel_FreeData();
132 function g_PlayerModel_Load(FileName
: String): Boolean;
133 function g_PlayerModel_GetNames(): SSArray
;
134 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
135 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
136 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
137 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
143 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
144 GL
, GLExt
, e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
147 TPlayerModelInfo
= record
149 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
152 WeaponPoints
: TWeaponPoints
;
154 PainSounds
: TModelSoundArray
;
155 DieSounds
: TModelSoundArray
;
167 FLAG_BASEPOINT
: TDFPoint
= (X
:16; Y
:43);
168 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
170 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
171 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
172 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
173 (X
:16; Y
:16), (X
:8; Y
:8));
175 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
176 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
177 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
179 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
180 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
181 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
182 'FistAttackUpAnim', 'FistAttackDownAnim');
183 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
184 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
187 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
188 Array [W_POS_NORMAL
..W_POS_DOWN
] of
189 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
190 PlayerModelsArray
: Array of TPlayerModelInfo
;
192 procedure g_PlayerModel_LoadData();
196 for a
:= WP_FIRST
+ 1 to WP_LAST
do
198 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
199 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
200 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
201 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
202 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
203 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
207 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
217 if Length(str
) < 3 then
220 for a
:= 1 to Length(str
) do
221 if (str
[a
] = ',') or (a
= Length(str
)) then
223 s
:= Copy(str
, 1, a
);
224 if s
[Length(s
)] = ',' then
225 SetLength(s
, Length(s
)-1);
228 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
229 (x
< -64) or (x
> 128) or
230 (y
< -64) or (y
> 128) then
242 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
243 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
252 backanim
:= backanim
and (frames
> 2);
254 for a
:= 1 to frames
do
256 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
259 with wpoints
[weapon
, anim
, dir
, a
-1] do
261 X
:= X
- WEAPONBASE
[weapon
].X
;
262 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
263 if dir
= TDirection
.D_LEFT
then
268 h
:= High(wpoints
[weapon
, anim
, dir
]);
270 for b
:= h
downto frames
do
271 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
276 procedure ExtAnimFromBaseAnim(MName
: String; AIdx
: Integer);
278 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
279 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
280 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
281 A_ATTACKUP
, A_ATTACKDOWN
286 AName
, OName
: String;
288 // HACK: shitty workaround to duplicate base animations
289 // in place of extended, replace with something better later
291 Assert((AIdx
> A_LASTBASE
) and (AIdx
<= A_LASTEXT
));
292 OIdx
:= CopyAnim
[AIdx
];
294 AName
:= MName
+ '_RIGHTANIM' + IntToStr(AIdx
);
295 OName
:= MName
+ '_RIGHTANIM' + IntToStr(OIdx
);
296 Assert(g_Frames_Dup(AName
, OName
));
297 Assert(g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK'));
298 AName
:= MName
+ '_LEFTANIM' + IntToStr(AIdx
);
299 OName
:= MName
+ '_LEFTANIM' + IntToStr(OIdx
);
300 if g_Frames_Exists(AName
) then
302 g_Frames_Dup(AName
, OName
);
303 g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK');
306 with PlayerModelsArray
[High(PlayerModelsArray
)] do
308 for W
:= WP_FIRST
+ 1 to WP_LAST
do
310 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
312 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
313 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
314 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
320 function g_PlayerModel_Load(FileName
: string): Boolean;
323 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
326 pData
, pData2
: Pointer;
332 e_WriteLog(Format('Loading player model: %s', [ExtractFileName(FileName
)]), TMsgType
.Notify
);
336 WAD
:= TWADFile
.Create
;
337 WAD
.ReadFile(FileName
);
339 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
345 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
351 config
:= TConfig
.CreateMem(pData
, len
);
354 s
:= config
.ReadStr('Model', 'name', '');
362 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
363 ID
:= High(PlayerModelsArray
);
365 prefix
:= FileName
+':TEXTURES\';
367 with PlayerModelsArray
[ID
].Info
do
370 Author
:= config
.ReadStr('Model', 'author', '');
371 Description
:= config
.ReadStr('Model', 'description', '');
374 for b
:= A_STAND
to A_LAST
do
376 aname
:= s
+'_RIGHTANIM'+IntToStr(b
);
377 //e_LogWritefln('### MODEL FILE: [%s]', [prefix+config.ReadStr(AnimNames[b], 'resource', '')]);
378 if not (g_Frames_CreateWAD(nil, aname
,
379 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
380 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
381 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
382 g_Frames_CreateWAD(nil, aname
+'_MASK',
383 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
384 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
385 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
387 if b
<= A_LASTBASE
then
395 ExtAnimFromBaseAnim(s
, b
);
400 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
401 for bb
:= A_STAND
to A_LAST
do
402 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
404 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
405 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
406 if f
> 2 then f
:= 2*f
-2;
407 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
410 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
411 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
413 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
414 g_Frames_CreateWAD(nil, aname
,
415 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
416 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
417 config
.ReadBool(AnimNames
[b
], 'backanim', False));
419 g_Frames_CreateWAD(nil, aname
+'_MASK',
420 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
421 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
422 config
.ReadBool(AnimNames
[b
], 'backanim', False));
425 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
428 with PlayerModelsArray
[ID
], config
do
430 prefix
:= FileName
+':SOUNDS\';
434 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
437 SetLength(PainSounds
, Length(PainSounds
)+1);
438 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
439 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
446 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
449 SetLength(DieSounds
, Length(DieSounds
)+1);
450 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
451 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
456 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
458 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
461 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
462 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
464 for a
:= 0 to High(Gibs
) do
465 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
466 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
468 Gibs
[a
].Rect
:= e_GetTextureSize2(Gibs
[a
].ID
);
470 if Height
> 3 then Height
:= Height
-1-Random(2);
471 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
479 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
480 for bb
:= A_STAND
to A_LAST
do
481 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
483 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
484 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
485 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
487 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
489 // workaround for flamethrower
490 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
491 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
492 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
495 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
500 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
501 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
503 A_WALKATTACK
, A_WALK
:
505 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
506 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
510 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
511 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
513 A_WALKSEEUP
, A_SEEUP
:
515 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
516 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
518 A_WALKSEEDOWN
, A_SEEDOWN
:
520 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
521 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
523 A_WALKATTACKUP
, A_ATTACKUP
:
525 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
526 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
528 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
530 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
531 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
536 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
538 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, TDirection
.D_LEFT
,
539 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
540 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
542 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
544 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
545 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
548 if not ok
then Break
;
550 {if ok then g_Console_Add(Info.Name+' weapon points ok')
551 else g_Console_Add(Info.Name+' weapon points fail');}
552 Info
.HaveWeapon
:= ok
;
554 s
:= config
.ReadStr('Model', 'flag_point', '');
555 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
557 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
566 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
574 if PlayerModelsArray
= nil then Exit
;
576 for a
:= 0 to High(PlayerModelsArray
) do
577 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
579 Result
:= TPlayerModel
.Create
;
581 with PlayerModelsArray
[a
] do
583 Result
.FName
:= Info
.Name
;
585 for b
:= A_STAND
to A_LAST
do
587 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
588 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
595 Result
.FAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
597 Result
.FMaskAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
599 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
600 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
601 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
602 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
604 Result
.FAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
606 Result
.FMaskAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
610 Result
.FPainSounds
:= PainSounds
;
611 Result
.FDieSounds
:= DieSounds
;
612 Result
.FSlopSound
:= SlopSound
;
613 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
614 Result
.FWeaponPoints
:= WeaponPoints
;
616 Result
.FFlagPoint
:= FlagPoint
;
617 Result
.FFlagAngle
:= FlagAngle
;
624 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
632 if PlayerModelsArray
= nil then Exit
;
633 for a
:= 0 to High(PlayerModelsArray
) do
634 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
635 with PlayerModelsArray
[a
] do
637 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
639 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
640 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
642 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
643 _Anim
.Speed
:= ModelSpeed
[Anim
];
645 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
646 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
648 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
649 _Mask
.Speed
:= ModelSpeed
[Anim
];
657 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
664 if PlayerModelsArray
= nil then Exit
;
665 if gGibsCount
= 0 then Exit
;
669 SetLength(Gibs
, gGibsCount
);
671 for a
:= 0 to High(PlayerModelsArray
) do
672 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
674 for i
:= 0 to High(Gibs
) do
676 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
683 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
684 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
686 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
688 if Gibs
[i
].OnlyOne
then c
:= True;
696 function g_PlayerModel_GetNames(): SSArray
;
702 if PlayerModelsArray
= nil then Exit
;
704 for i
:= 0 to High(PlayerModelsArray
) do
706 SetLength(Result
, Length(Result
)+1);
707 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
711 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
715 FillChar(Result
, SizeOf(Result
), 0);
716 if PlayerModelsArray
= nil then Exit
;
718 for a
:= 0 to High(PlayerModelsArray
) do
719 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
721 Result
:= PlayerModelsArray
[a
].Info
;
726 procedure g_PlayerModel_FreeData();
731 for a
:= WP_FIRST
+ 1 to WP_LAST
do
732 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
733 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
734 e_DeleteTexture(WeaponID
[a
][b
][c
]);
736 e_WriteLog('Releasing models...', TMsgType
.Notify
);
738 if PlayerModelsArray
= nil then Exit
;
740 for i
:= 0 to High(PlayerModelsArray
) do
741 with PlayerModelsArray
[i
] do
743 for a
:= A_STAND
to A_LAST
do
745 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
746 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
747 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
748 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
751 if PainSounds
<> nil then
752 for b
:= 0 to High(PainSounds
) do
753 e_DeleteSound(PainSounds
[b
].ID
);
755 if DieSounds
<> nil then
756 for b
:= 0 to High(DieSounds
) do
757 e_DeleteSound(DieSounds
[b
].ID
);
760 for b
:= 0 to High(Gibs
) do
762 e_DeleteTexture(Gibs
[b
].ID
);
763 e_DeleteTexture(Gibs
[b
].MaskID
);
767 PlayerModelsArray
:= nil;
772 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
774 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
776 FCurrentAnimation
:= Animation
;
778 if (FDirection
= TDirection
.D_LEFT
) and
779 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) and
780 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
782 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
783 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
787 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
788 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
792 destructor TPlayerModel
.Destroy();
796 for a
:= A_STAND
to A_LAST
do
798 FAnim
[TDirection
.D_LEFT
][a
].Free();
799 FMaskAnim
[TDirection
.D_LEFT
][a
].Free();
800 FAnim
[TDirection
.D_RIGHT
][a
].Free();
801 FMaskAnim
[TDirection
.D_RIGHT
][a
].Free();
807 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
814 if Direction
= TDirection
.D_LEFT
then
815 Mirror
:= TMirrorType
.None
817 Mirror
:= TMirrorType
.Horizontal
;
819 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
820 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
822 p
.X
:= IfThen(Direction
= TDirection
.D_LEFT
,
824 64-FLAG_BASEPOINT
.X
);
825 p
.Y
:= FLAG_BASEPOINT
.Y
;
827 FFlagAnim
.DrawEx(X
+IfThen(Direction
= TDirection
.D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
828 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
829 IfThen(FDirection
= TDirection
.D_RIGHT
, FFlagAngle
, -FFlagAngle
));
833 if Direction
= TDirection
.D_RIGHT
then
834 Mirror
:= TMirrorType
.None
836 Mirror
:= TMirrorType
.Horizontal
;
839 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
840 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
842 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
845 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
850 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
857 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
858 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
859 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
860 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
861 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
862 0, True, False, Mirror
);
866 if (FDirection
= TDirection
.D_LEFT
) and
867 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
869 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
870 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, TMirrorType
.None
);
874 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
875 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
881 if (FDirection
= TDirection
.D_LEFT
) and
882 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
884 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
885 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, TMirrorType
.None
);
889 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
890 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
898 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
900 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
901 Result
:= FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
903 Result
:= FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
906 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
908 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
909 Result
:= FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
911 Result
:= FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
914 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
916 TempArray
: array of DWORD
;
920 SetLength(TempArray
, 0);
922 if SoundType
= MODELSOUND_PAIN
then
924 if FPainSounds
= nil then Exit
;
926 for a
:= 0 to High(FPainSounds
) do
927 if FPainSounds
[a
].Level
= Level
then
929 SetLength(TempArray
, Length(TempArray
)+1);
930 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
935 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
937 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
938 if FSlopSound
= 1 then
944 if FDieSounds
= nil then Exit
;
946 for a
:= 0 to High(FDieSounds
) do
947 if FDieSounds
[a
].Level
= Level
then
949 SetLength(TempArray
, Length(TempArray
)+1);
950 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
952 if (TempArray
= nil) and (Level
= 5) then
954 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
960 if TempArray
= nil then Exit
;
962 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
967 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
974 procedure TPlayerModel
.SetFire(Fire
: Boolean);
978 if FFire
then FFireCounter
:= FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].Speed
*FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].TotalFrames
979 else FFireCounter
:= 0;
982 procedure TPlayerModel
.SetFlag(Flag
: Byte);
992 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
993 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
997 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
1000 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
1002 FCurrentWeapon
:= Weapon
;
1005 procedure TPlayerModel
.Update();
1007 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1008 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1010 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1011 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1013 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1015 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;