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;
144 {$INCLUDE ../nogl/noGLuses.inc}
145 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
146 e_sound
, g_options
, g_map
, Math
, e_log
, wadreader
;
149 TPlayerModelInfo
= record
151 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
154 WeaponPoints
: TWeaponPoints
;
156 PainSounds
: TModelSoundArray
;
157 DieSounds
: TModelSoundArray
;
169 FLAG_BASEPOINT
: TDFPoint
= (X
:16; Y
:43);
170 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
172 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
173 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
174 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
175 (X
:16; Y
:16), (X
:8; Y
:8));
177 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
178 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
179 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
181 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
182 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
183 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
184 'FistAttackUpAnim', 'FistAttackDownAnim');
185 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
186 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
189 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
190 Array [W_POS_NORMAL
..W_POS_DOWN
] of
191 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
192 PlayerModelsArray
: Array of TPlayerModelInfo
;
194 procedure g_PlayerModel_LoadData();
198 for a
:= WP_FIRST
+ 1 to WP_LAST
do
200 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
201 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
202 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
203 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
204 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
205 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
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', [ExtractFileName(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 for b
:= A_STAND
to A_LAST
do
437 aname
:= s
+'_RIGHTANIM'+IntToStr(b
);
438 //e_LogWritefln('### MODEL FILE: [%s]', [prefix+config.ReadStr(AnimNames[b], 'resource', '')]);
439 if not (g_Frames_CreateWAD(nil, aname
,
440 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
441 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
442 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
443 g_Frames_CreateWAD(nil, aname
+'_MASK',
444 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
445 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
446 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
448 if b
<= A_LASTBASE
then
456 ExtAnimFromBaseAnim(s
, b
);
461 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
462 for bb
:= A_STAND
to A_LAST
do
463 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
465 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
466 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
467 if f
> 2 then f
:= 2*f
-2;
468 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
471 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
472 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
474 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
475 g_Frames_CreateWAD(nil, aname
,
476 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
477 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
478 config
.ReadBool(AnimNames
[b
], 'backanim', False));
480 g_Frames_CreateWAD(nil, aname
+'_MASK',
481 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
482 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
483 config
.ReadBool(AnimNames
[b
], 'backanim', False));
486 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
489 with PlayerModelsArray
[ID
], config
do
491 prefix
:= FileName
+':SOUNDS\';
495 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
498 SetLength(PainSounds
, Length(PainSounds
)+1);
499 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
500 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
507 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
510 SetLength(DieSounds
, Length(DieSounds
)+1);
511 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
512 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
517 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
519 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
522 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
523 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
525 for a
:= 0 to High(Gibs
) do
526 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
527 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
529 //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
530 Gibs
[a
].Rect
:= g_PlayerModel_CalcGibSize(pData
, lenpd
, a
*32, 0, 32, 32);
532 if Height
> 3 then Height
:= Height
-1-Random(2);
533 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
541 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
542 for bb
:= A_STAND
to A_LAST
do
543 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
545 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
546 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
547 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
549 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
551 // workaround for flamethrower
552 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
553 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
554 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
557 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
562 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
563 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
565 A_WALKATTACK
, A_WALK
:
567 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
568 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
572 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
573 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
575 A_WALKSEEUP
, A_SEEUP
:
577 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
578 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
580 A_WALKSEEDOWN
, A_SEEDOWN
:
582 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
583 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
585 A_WALKATTACKUP
, A_ATTACKUP
:
587 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
588 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
590 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
592 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
593 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
598 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
600 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, TDirection
.D_LEFT
,
601 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
602 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
604 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
606 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
607 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
610 if not ok
then Break
;
612 {if ok then g_Console_Add(Info.Name+' weapon points ok')
613 else g_Console_Add(Info.Name+' weapon points fail');}
614 Info
.HaveWeapon
:= ok
;
616 s
:= config
.ReadStr('Model', 'flag_point', '');
617 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
619 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
628 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
636 if PlayerModelsArray
= nil then Exit
;
638 for a
:= 0 to High(PlayerModelsArray
) do
639 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
641 Result
:= TPlayerModel
.Create
;
643 with PlayerModelsArray
[a
] do
645 Result
.FName
:= Info
.Name
;
647 for b
:= A_STAND
to A_LAST
do
649 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
650 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
657 Result
.FAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
659 Result
.FMaskAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
661 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
662 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
663 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
664 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
666 Result
.FAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
668 Result
.FMaskAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
672 Result
.FPainSounds
:= PainSounds
;
673 Result
.FDieSounds
:= DieSounds
;
674 Result
.FSlopSound
:= SlopSound
;
675 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
676 Result
.FWeaponPoints
:= WeaponPoints
;
678 Result
.FFlagPoint
:= FlagPoint
;
679 Result
.FFlagAngle
:= FlagAngle
;
686 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
694 if PlayerModelsArray
= nil then Exit
;
695 for a
:= 0 to High(PlayerModelsArray
) do
696 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
697 with PlayerModelsArray
[a
] do
699 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
701 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
702 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
704 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
705 _Anim
.Speed
:= ModelSpeed
[Anim
];
707 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
708 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
710 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
711 _Mask
.Speed
:= ModelSpeed
[Anim
];
719 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
726 if PlayerModelsArray
= nil then Exit
;
727 if gGibsCount
= 0 then Exit
;
731 SetLength(Gibs
, gGibsCount
);
733 for a
:= 0 to High(PlayerModelsArray
) do
734 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
736 for i
:= 0 to High(Gibs
) do
738 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
745 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
746 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
748 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
750 if Gibs
[i
].OnlyOne
then c
:= True;
758 function g_PlayerModel_GetNames(): SSArray
;
764 if PlayerModelsArray
= nil then Exit
;
766 for i
:= 0 to High(PlayerModelsArray
) do
768 SetLength(Result
, Length(Result
)+1);
769 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
773 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
777 FillChar(Result
, SizeOf(Result
), 0);
778 if PlayerModelsArray
= nil then Exit
;
780 for a
:= 0 to High(PlayerModelsArray
) do
781 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
783 Result
:= PlayerModelsArray
[a
].Info
;
788 procedure g_PlayerModel_FreeData();
793 for a
:= WP_FIRST
+ 1 to WP_LAST
do
794 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
795 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
796 e_DeleteTexture(WeaponID
[a
][b
][c
]);
798 e_WriteLog('Releasing models...', TMsgType
.Notify
);
800 if PlayerModelsArray
= nil then Exit
;
802 for i
:= 0 to High(PlayerModelsArray
) do
803 with PlayerModelsArray
[i
] do
805 for a
:= A_STAND
to A_LAST
do
807 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
808 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
809 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
810 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
813 if PainSounds
<> nil then
814 for b
:= 0 to High(PainSounds
) do
815 e_DeleteSound(PainSounds
[b
].ID
);
817 if DieSounds
<> nil then
818 for b
:= 0 to High(DieSounds
) do
819 e_DeleteSound(DieSounds
[b
].ID
);
822 for b
:= 0 to High(Gibs
) do
824 e_DeleteTexture(Gibs
[b
].ID
);
825 e_DeleteTexture(Gibs
[b
].MaskID
);
829 PlayerModelsArray
:= nil;
834 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
836 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
838 FCurrentAnimation
:= Animation
;
840 if (FDirection
= TDirection
.D_LEFT
) and
841 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) and
842 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
844 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
845 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
849 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
850 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
854 destructor TPlayerModel
.Destroy();
858 for a
:= A_STAND
to A_LAST
do
860 FAnim
[TDirection
.D_LEFT
][a
].Free();
861 FMaskAnim
[TDirection
.D_LEFT
][a
].Free();
862 FAnim
[TDirection
.D_RIGHT
][a
].Free();
863 FMaskAnim
[TDirection
.D_RIGHT
][a
].Free();
869 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
876 if Direction
= TDirection
.D_LEFT
then
877 Mirror
:= TMirrorType
.None
879 Mirror
:= TMirrorType
.Horizontal
;
881 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
882 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
884 p
.X
:= IfThen(Direction
= TDirection
.D_LEFT
,
886 64-FLAG_BASEPOINT
.X
);
887 p
.Y
:= FLAG_BASEPOINT
.Y
;
889 FFlagAnim
.DrawEx(X
+IfThen(Direction
= TDirection
.D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
890 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
891 IfThen(FDirection
= TDirection
.D_RIGHT
, FFlagAngle
, -FFlagAngle
));
895 if Direction
= TDirection
.D_RIGHT
then
896 Mirror
:= TMirrorType
.None
898 Mirror
:= TMirrorType
.Horizontal
;
901 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
902 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
904 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
907 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
912 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
919 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
920 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
921 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
922 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
923 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
924 0, True, False, Mirror
);
928 if (FDirection
= TDirection
.D_LEFT
) and
929 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
931 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
932 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, TMirrorType
.None
);
936 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
937 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
943 if (FDirection
= TDirection
.D_LEFT
) and
944 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
946 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
947 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, TMirrorType
.None
);
951 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
952 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
960 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
962 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
963 Result
:= FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
965 Result
:= FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
968 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
970 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
971 Result
:= FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
973 Result
:= FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
976 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
978 TempArray
: array of DWORD
;
982 SetLength(TempArray
, 0);
984 if SoundType
= MODELSOUND_PAIN
then
986 if FPainSounds
= nil then Exit
;
988 for a
:= 0 to High(FPainSounds
) do
989 if FPainSounds
[a
].Level
= Level
then
991 SetLength(TempArray
, Length(TempArray
)+1);
992 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
997 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
999 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
1000 if FSlopSound
= 1 then
1006 if FDieSounds
= nil then Exit
;
1008 for a
:= 0 to High(FDieSounds
) do
1009 if FDieSounds
[a
].Level
= Level
then
1011 SetLength(TempArray
, Length(TempArray
)+1);
1012 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
1014 if (TempArray
= nil) and (Level
= 5) then
1016 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
1022 if TempArray
= nil then Exit
;
1024 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
1029 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
1036 procedure TPlayerModel
.SetFire(Fire
: Boolean);
1040 if FFire
then FFireCounter
:= FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].Speed
*FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].TotalFrames
1041 else FFireCounter
:= 0;
1044 procedure TPlayerModel
.SetFlag(Flag
: Byte);
1054 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1055 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1059 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
1062 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
1064 FCurrentWeapon
:= Weapon
;
1067 procedure TPlayerModel
.Update();
1069 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1070 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1072 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1073 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1075 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1077 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;