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
,
25 ImagingTypes
, Imaging
, ImagingUtility
;
43 A_WALKATTACKDOWN
= 14;
47 A_FISTWALKATTACK
= 18;
51 A_FISTATTACKDOWN
= 22;
54 A_LASTEXT
= A_FISTATTACKDOWN
;
80 TModelSoundArray
= Array of TModelSound
;
81 TGibsArray
= Array of TGibSprite
;
82 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
] of
83 Array [A_STAND
..A_LAST
] of
84 Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array of TDFPoint
;
86 TPlayerModel
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
89 FDirection
: TDirection
;
91 FCurrentAnimation
: Byte;
92 FAnim
: Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
93 FMaskAnim
: Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
94 FWeaponPoints
: TWeaponPoints
;
95 FPainSounds
: TModelSoundArray
;
96 FDieSounds
: TModelSoundArray
;
101 FFlagPoint
: TDFPoint
;
102 FFlagAngle
: SmallInt;
103 FFlagAnim
: TAnimation
;
108 destructor Destroy(); override;
109 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
110 function GetCurrentAnimation
: TAnimation
;
111 function GetCurrentAnimationMask
: TAnimation
;
112 procedure SetColor(Red
, Green
, Blue
: Byte);
113 procedure SetWeapon(Weapon
: Byte);
114 procedure SetFlag(Flag
: Byte);
115 procedure SetFire(Fire
: Boolean);
116 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
118 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
121 property Fire
: Boolean read FFire
;
122 property Direction
: TDirection read FDirection write FDirection
;
123 property Animation
: Byte read FCurrentAnimation
;
124 property Weapon
: Byte read FCurrentWeapon
;
125 property Name
: String read FName
;
128 property Color
: TRGB read FColor write FColor
;
131 procedure g_PlayerModel_LoadData();
132 procedure g_PlayerModel_FreeData();
133 function g_PlayerModel_Load(FileName
: String): Boolean;
134 function g_PlayerModel_GetNames(): SSArray
;
135 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
136 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
137 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
138 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
149 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
150 e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
153 TPlayerModelInfo
= record
155 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
158 WeaponPoints
: TWeaponPoints
;
160 PainSounds
: TModelSoundArray
;
161 DieSounds
: TModelSoundArray
;
173 FLAG_BASEPOINT
: TDFPoint
= (X
:16; Y
:43);
174 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
176 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
177 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
178 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
179 (X
:16; Y
:16), (X
:8; Y
:8));
181 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
182 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
183 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
185 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
186 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
187 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
188 'FistAttackUpAnim', 'FistAttackDownAnim');
189 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
190 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
193 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
194 Array [W_POS_NORMAL
..W_POS_DOWN
] of
195 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
196 PlayerModelsArray
: Array of TPlayerModelInfo
;
198 procedure g_PlayerModel_LoadData();
202 for a
:= WP_FIRST
+ 1 to WP_LAST
do
204 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
205 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
206 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
207 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
208 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
209 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
213 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
223 if Length(str
) < 3 then
226 for a
:= 1 to Length(str
) do
227 if (str
[a
] = ',') or (a
= Length(str
)) then
229 s
:= Copy(str
, 1, a
);
230 if s
[Length(s
)] = ',' then
231 SetLength(s
, Length(s
)-1);
234 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
235 (x
< -64) or (x
> 128) or
236 (y
< -64) or (y
> 128) then
248 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
249 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
258 backanim
:= backanim
and (frames
> 2);
260 for a
:= 1 to frames
do
262 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
265 with wpoints
[weapon
, anim
, dir
, a
-1] do
267 X
:= X
- WEAPONBASE
[weapon
].X
;
268 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
269 if dir
= TDirection
.D_LEFT
then
274 h
:= High(wpoints
[weapon
, anim
, dir
]);
276 for b
:= h
downto frames
do
277 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
282 procedure ExtAnimFromBaseAnim(MName
: String; AIdx
: Integer);
284 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
285 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
286 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
287 A_ATTACKUP
, A_ATTACKDOWN
292 AName
, OName
: String;
294 // HACK: shitty workaround to duplicate base animations
295 // in place of extended, replace with something better later
297 Assert((AIdx
> A_LASTBASE
) and (AIdx
<= A_LASTEXT
));
298 OIdx
:= CopyAnim
[AIdx
];
300 AName
:= MName
+ '_RIGHTANIM' + IntToStr(AIdx
);
301 OName
:= MName
+ '_RIGHTANIM' + IntToStr(OIdx
);
302 Assert(g_Frames_Dup(AName
, OName
));
303 Assert(g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK'));
304 AName
:= MName
+ '_LEFTANIM' + IntToStr(AIdx
);
305 OName
:= MName
+ '_LEFTANIM' + IntToStr(OIdx
);
306 if g_Frames_Exists(AName
) then
308 g_Frames_Dup(AName
, OName
);
309 g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK');
312 with PlayerModelsArray
[High(PlayerModelsArray
)] do
314 for W
:= WP_FIRST
+ 1 to WP_LAST
do
316 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
318 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
319 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
320 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
326 function g_PlayerModel_CalcGibSize (pData
: Pointer; dataSize
, x
, y
, w
, h
: Integer): TRectWH
;
327 var i
, j
: Integer; done
: Boolean; img
: TImageData
;
329 function IsVoid (i
, j
: Integer): Boolean;
331 result
:= Byte((PByte(img
.bits
) + (y
+j
)*img
.width
*4 + (x
+i
)*4 + 3)^) = 0
336 assert(LoadImageFromMemory(pData
, dataSize
, img
));
338 (* trace x from right to left *)
339 done
:= false; i
:= 0;
340 while not done
and (i
< w
) do
343 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
344 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
349 (* trace y from up to down *)
350 done
:= false; j
:= 0;
351 while not done
and (j
< h
) do
354 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
355 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
360 (* trace x from right to left *)
361 done
:= false; i
:= w
- 1;
362 while not done
and (i
>= 0) do
365 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
366 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
367 result
.width
:= i
- result
.x
+ 1;
371 (* trace y from down to up *)
372 done
:= false; j
:= h
- 1;
373 while not done
and (j
>= 0) do
376 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
377 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
378 result
.height
:= j
- result
.y
+ 1;
385 function g_PlayerModel_Load(FileName
: string): Boolean;
388 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
391 pData
, pData2
: Pointer;
397 e_WriteLog(Format('Loading player model: %s', [ExtractFileName(FileName
)]), TMsgType
.Notify
);
401 WAD
:= TWADFile
.Create
;
402 WAD
.ReadFile(FileName
);
404 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
410 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
416 config
:= TConfig
.CreateMem(pData
, len
);
419 s
:= config
.ReadStr('Model', 'name', '');
427 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
428 ID
:= High(PlayerModelsArray
);
430 prefix
:= FileName
+':TEXTURES\';
432 with PlayerModelsArray
[ID
].Info
do
435 Author
:= config
.ReadStr('Model', 'author', '');
436 Description
:= config
.ReadStr('Model', 'description', '');
439 for b
:= A_STAND
to A_LAST
do
441 aname
:= s
+'_RIGHTANIM'+IntToStr(b
);
442 //e_LogWritefln('### MODEL FILE: [%s]', [prefix+config.ReadStr(AnimNames[b], 'resource', '')]);
443 if not (g_Frames_CreateWAD(nil, aname
,
444 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
445 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
446 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
447 g_Frames_CreateWAD(nil, aname
+'_MASK',
448 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
449 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
450 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
452 if b
<= A_LASTBASE
then
460 ExtAnimFromBaseAnim(s
, b
);
465 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
466 for bb
:= A_STAND
to A_LAST
do
467 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
469 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
470 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
471 if f
> 2 then f
:= 2*f
-2;
472 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
475 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
476 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
478 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
479 g_Frames_CreateWAD(nil, aname
,
480 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
481 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
482 config
.ReadBool(AnimNames
[b
], 'backanim', False));
484 g_Frames_CreateWAD(nil, aname
+'_MASK',
485 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
486 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
487 config
.ReadBool(AnimNames
[b
], 'backanim', False));
490 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
493 with PlayerModelsArray
[ID
], config
do
495 prefix
:= FileName
+':SOUNDS\';
499 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
502 SetLength(PainSounds
, Length(PainSounds
)+1);
503 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
504 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
511 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
514 SetLength(DieSounds
, Length(DieSounds
)+1);
515 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
516 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
521 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
523 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
526 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
527 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
529 for a
:= 0 to High(Gibs
) do
530 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
531 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
533 //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
534 Gibs
[a
].Rect
:= g_PlayerModel_CalcGibSize(pData
, lenpd
, a
*32, 0, 32, 32);
536 if Height
> 3 then Height
:= Height
-1-Random(2);
537 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
545 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
546 for bb
:= A_STAND
to A_LAST
do
547 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
549 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
550 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
551 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
553 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
555 // workaround for flamethrower
556 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
557 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
558 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
561 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
566 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
567 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
569 A_WALKATTACK
, A_WALK
:
571 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
572 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
576 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
577 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
579 A_WALKSEEUP
, A_SEEUP
:
581 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
582 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
584 A_WALKSEEDOWN
, A_SEEDOWN
:
586 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
587 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
589 A_WALKATTACKUP
, A_ATTACKUP
:
591 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
592 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
594 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
596 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
597 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
602 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
604 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, TDirection
.D_LEFT
,
605 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
606 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
608 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
610 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
611 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 FlagPoint
:= FLAG_DEFPOINT
;
623 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
632 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
640 if PlayerModelsArray
= nil then Exit
;
642 for a
:= 0 to High(PlayerModelsArray
) do
643 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
645 Result
:= TPlayerModel
.Create
;
647 with PlayerModelsArray
[a
] do
649 Result
.FName
:= Info
.Name
;
651 for b
:= A_STAND
to A_LAST
do
653 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
654 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
661 Result
.FAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
663 Result
.FMaskAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
665 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
666 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
667 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
668 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
670 Result
.FAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
672 Result
.FMaskAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
676 Result
.FPainSounds
:= PainSounds
;
677 Result
.FDieSounds
:= DieSounds
;
678 Result
.FSlopSound
:= SlopSound
;
679 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
680 Result
.FWeaponPoints
:= WeaponPoints
;
682 Result
.FFlagPoint
:= FlagPoint
;
683 Result
.FFlagAngle
:= FlagAngle
;
690 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
698 if PlayerModelsArray
= nil then Exit
;
699 for a
:= 0 to High(PlayerModelsArray
) do
700 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
701 with PlayerModelsArray
[a
] do
703 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
705 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
706 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
708 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
709 _Anim
.Speed
:= ModelSpeed
[Anim
];
711 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
712 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
714 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
715 _Mask
.Speed
:= ModelSpeed
[Anim
];
723 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
730 if PlayerModelsArray
= nil then Exit
;
731 if gGibsCount
= 0 then Exit
;
735 SetLength(Gibs
, gGibsCount
);
737 for a
:= 0 to High(PlayerModelsArray
) do
738 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
740 for i
:= 0 to High(Gibs
) do
742 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
749 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
750 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
752 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
754 if Gibs
[i
].OnlyOne
then c
:= True;
762 function g_PlayerModel_GetNames(): SSArray
;
768 if PlayerModelsArray
= nil then Exit
;
770 for i
:= 0 to High(PlayerModelsArray
) do
772 SetLength(Result
, Length(Result
)+1);
773 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
777 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
781 FillChar(Result
, SizeOf(Result
), 0);
782 if PlayerModelsArray
= nil then Exit
;
784 for a
:= 0 to High(PlayerModelsArray
) do
785 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
787 Result
:= PlayerModelsArray
[a
].Info
;
792 procedure g_PlayerModel_FreeData();
797 for a
:= WP_FIRST
+ 1 to WP_LAST
do
798 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
799 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
800 e_DeleteTexture(WeaponID
[a
][b
][c
]);
802 e_WriteLog('Releasing models...', TMsgType
.Notify
);
804 if PlayerModelsArray
= nil then Exit
;
806 for i
:= 0 to High(PlayerModelsArray
) do
807 with PlayerModelsArray
[i
] do
809 for a
:= A_STAND
to A_LAST
do
811 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
812 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
813 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
814 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
817 if PainSounds
<> nil then
818 for b
:= 0 to High(PainSounds
) do
819 e_DeleteSound(PainSounds
[b
].ID
);
821 if DieSounds
<> nil then
822 for b
:= 0 to High(DieSounds
) do
823 e_DeleteSound(DieSounds
[b
].ID
);
826 for b
:= 0 to High(Gibs
) do
828 e_DeleteTexture(Gibs
[b
].ID
);
829 e_DeleteTexture(Gibs
[b
].MaskID
);
833 PlayerModelsArray
:= nil;
838 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
840 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
842 FCurrentAnimation
:= Animation
;
844 if (FDirection
= TDirection
.D_LEFT
) and
845 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) and
846 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
848 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
849 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
853 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
854 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
858 destructor TPlayerModel
.Destroy();
862 for a
:= A_STAND
to A_LAST
do
864 FAnim
[TDirection
.D_LEFT
][a
].Free();
865 FMaskAnim
[TDirection
.D_LEFT
][a
].Free();
866 FAnim
[TDirection
.D_RIGHT
][a
].Free();
867 FMaskAnim
[TDirection
.D_RIGHT
][a
].Free();
873 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
880 if Direction
= TDirection
.D_LEFT
then
881 Mirror
:= TMirrorType
.None
883 Mirror
:= TMirrorType
.Horizontal
;
885 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
886 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
888 p
.X
:= IfThen(Direction
= TDirection
.D_LEFT
,
890 64-FLAG_BASEPOINT
.X
);
891 p
.Y
:= FLAG_BASEPOINT
.Y
;
893 FFlagAnim
.DrawEx(X
+IfThen(Direction
= TDirection
.D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
894 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
895 IfThen(FDirection
= TDirection
.D_RIGHT
, FFlagAngle
, -FFlagAngle
));
899 if Direction
= TDirection
.D_RIGHT
then
900 Mirror
:= TMirrorType
.None
902 Mirror
:= TMirrorType
.Horizontal
;
905 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
906 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
908 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
911 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
916 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
923 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
924 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
925 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
926 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
927 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
928 0, True, False, Mirror
);
932 if (FDirection
= TDirection
.D_LEFT
) and
933 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
935 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
936 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, TMirrorType
.None
);
940 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
941 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
947 if (FDirection
= TDirection
.D_LEFT
) and
948 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
950 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
951 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, TMirrorType
.None
);
955 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
956 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
964 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
966 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
967 Result
:= FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
969 Result
:= FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
972 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
974 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
975 Result
:= FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
977 Result
:= FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
980 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
982 TempArray
: array of DWORD
;
986 SetLength(TempArray
, 0);
988 if SoundType
= MODELSOUND_PAIN
then
990 if FPainSounds
= nil then Exit
;
992 for a
:= 0 to High(FPainSounds
) do
993 if FPainSounds
[a
].Level
= Level
then
995 SetLength(TempArray
, Length(TempArray
)+1);
996 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
1001 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
1003 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
1004 if FSlopSound
= 1 then
1010 if FDieSounds
= nil then Exit
;
1012 for a
:= 0 to High(FDieSounds
) do
1013 if FDieSounds
[a
].Level
= Level
then
1015 SetLength(TempArray
, Length(TempArray
)+1);
1016 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
1018 if (TempArray
= nil) and (Level
= 5) then
1020 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
1026 if TempArray
= nil then Exit
;
1028 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
1033 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
1040 procedure TPlayerModel
.SetFire(Fire
: Boolean);
1044 if FFire
then FFireCounter
:= FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].Speed
*FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].TotalFrames
1045 else FFireCounter
:= 0;
1048 procedure TPlayerModel
.SetFlag(Flag
: Byte);
1058 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1059 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1063 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
1066 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
1068 FCurrentWeapon
:= Weapon
;
1071 procedure TPlayerModel
.Update();
1073 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1074 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1076 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1077 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1079 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1081 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;