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 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
26 MAPDEF
, g_textures
, g_basic
, g_weapons
, e_graphics
, utils
, g_gfx
,
27 ImagingTypes
, Imaging
, ImagingUtility
;
45 A_WALKATTACKDOWN
= 14;
49 A_MELEEWALKATTACK
= 18;
53 A_MELEEATTACKDOWN
= 22;
56 A_LASTEXT
= A_MELEEATTACKDOWN
;
89 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
;
97 TPlayerModel
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
100 FDirection
: TDirection
;
103 FCurrentAnimation
: Byte;
104 FAnim
: Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
105 FMaskAnim
: Array [TDirection
.D_LEFT
..TDirection
.D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
106 FWeaponPoints
: TWeaponPoints
;
107 {$IFDEF ENABLE_SOUND}
108 FPainSounds
: TModelSoundArray
;
109 FDieSounds
: TModelSoundArray
;
112 FCurrentWeapon
: Byte;
113 FDrawWeapon
: Boolean;
115 FFlagPoint
: TDFPoint
;
116 FFlagAngle
: SmallInt
;
117 FFlagAnim
: TAnimation
;
122 destructor Destroy(); override;
123 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
124 function GetCurrentAnimation
: TAnimation
;
125 function GetCurrentAnimationMask
: TAnimation
;
126 procedure SetColor(Red
, Green
, Blue
: Byte);
127 procedure SetWeapon(Weapon
: Byte);
128 procedure SetFlag(Flag
: Byte);
129 procedure SetFire(Fire
: Boolean);
130 {$IFDEF ENABLE_SOUND}
131 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
134 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
137 property Fire
: Boolean read FFire
;
138 property Direction
: TDirection read FDirection write FDirection
;
139 property Animation
: Byte read FCurrentAnimation
;
140 property Weapon
: Byte read FCurrentWeapon
;
141 property Name
: String read FName
;
144 property Color
: TRGB read FColor write FColor
;
145 property Blood
: TModelBlood read FBlood
;
148 procedure g_PlayerModel_LoadData();
149 procedure g_PlayerModel_FreeData();
150 function g_PlayerModel_Load(FileName
: String): Boolean;
151 function g_PlayerModel_GetNames(): SSArray
;
152 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
153 function g_PlayerModel_GetBlood(ModelName
: String): TModelBlood
;
154 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
155 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
156 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
162 {$INCLUDE ../nogl/noGLuses.inc}
163 {$IFDEF ENABLE_SOUND}
166 g_main
, g_console
, SysUtils
, g_player
, CONFIG
,
167 g_options
, g_map
, Math
, e_log
, wadreader
;
170 TPlayerModelInfo
= record
172 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
175 WeaponPoints
: TWeaponPoints
;
177 {$IFDEF ENABLE_SOUND}
178 PainSounds
: TModelSoundArray
;
179 DieSounds
: TModelSoundArray
;
193 FLAG_BASEPOINT
: TDFPoint
= (X
:16; Y
:43);
194 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
196 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
197 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
198 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
199 (X
:16; Y
:16), (X
:8; Y
:8));
201 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
202 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
203 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
205 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
206 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'MeleeStandAnim', 'MeleeWalkAnim',
207 'MeleeAttackAnim', 'MeleeWalkAttackAnim', 'MeleeSeeUpAnim', 'MeleeSeeDownAnim',
208 'MeleeAttackUpAnim', 'MeleeAttackDownAnim');
209 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
210 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
213 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
214 Array [W_POS_NORMAL
..W_POS_DOWN
] of
215 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
216 PlayerModelsArray
: Array of TPlayerModelInfo
;
218 procedure g_PlayerModel_LoadData();
222 for a
:= WP_FIRST
+ 1 to WP_LAST
do
224 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
225 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
226 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
227 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
228 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
229 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
233 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
243 if Length(str
) < 3 then
246 for a
:= 1 to Length(str
) do
247 if (str
[a
] = ',') or (a
= Length(str
)) then
249 s
:= Copy(str
, 1, a
);
250 if s
[Length(s
)] = ',' then
251 SetLength(s
, Length(s
)-1);
254 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
255 (x
< -64) or (x
> 128) or
256 (y
< -64) or (y
> 128) then
268 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
269 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
278 backanim
:= backanim
and (frames
> 2);
280 for a
:= 1 to frames
do
282 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
285 with wpoints
[weapon
, anim
, dir
, a
-1] do
287 X
:= X
- WEAPONBASE
[weapon
].X
;
288 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
289 if dir
= TDirection
.D_LEFT
then
294 h
:= High(wpoints
[weapon
, anim
, dir
]);
296 for b
:= h
downto frames
do
297 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
302 procedure ExtAnimFromBaseAnim(MName
: String; AIdx
: Integer);
304 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
305 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
306 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
307 A_ATTACKUP
, A_ATTACKDOWN
312 AName
, OName
: String;
314 // HACK: shitty workaround to duplicate base animations
315 // in place of extended, replace with something better later
317 Assert((AIdx
> A_LASTBASE
) and (AIdx
<= A_LASTEXT
));
318 OIdx
:= CopyAnim
[AIdx
];
320 AName
:= MName
+ '_RIGHTANIM' + IntToStr(AIdx
);
321 OName
:= MName
+ '_RIGHTANIM' + IntToStr(OIdx
);
322 Assert(g_Frames_Dup(AName
, OName
));
323 Assert(g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK'));
324 AName
:= MName
+ '_LEFTANIM' + IntToStr(AIdx
);
325 OName
:= MName
+ '_LEFTANIM' + IntToStr(OIdx
);
326 if g_Frames_Exists(AName
) then
328 g_Frames_Dup(AName
, OName
);
329 g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK');
332 with PlayerModelsArray
[High(PlayerModelsArray
)] do
334 for W
:= WP_FIRST
+ 1 to WP_LAST
do
336 for D
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
338 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
339 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
340 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
346 function g_PlayerModel_CalcGibSize (pData
: Pointer; dataSize
, x
, y
, w
, h
: Integer): TRectWH
;
347 var i
, j
: Integer; done
: Boolean; img
: TImageData
;
349 function IsVoid (i
, j
: Integer): Boolean;
351 result
:= Byte((PByte(img
.bits
) + (y
+j
)*img
.width
*4 + (x
+i
)*4 + 3)^) = 0
356 assert(LoadImageFromMemory(pData
, dataSize
, img
));
358 (* trace x from right to left *)
359 done
:= false; i
:= 0;
360 while not done
and (i
< w
) do
363 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
364 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
369 (* trace y from up to down *)
370 done
:= false; j
:= 0;
371 while not done
and (j
< h
) do
374 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
375 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
380 (* trace x from right to left *)
381 done
:= false; i
:= w
- 1;
382 while not done
and (i
>= 0) do
385 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
386 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
387 result
.width
:= i
- result
.x
+ 1;
391 (* trace y from down to up *)
392 done
:= false; j
:= h
- 1;
393 while not done
and (j
>= 0) do
396 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
397 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
398 result
.height
:= j
- result
.y
+ 1;
405 function g_PlayerModel_Load(FileName
: string): Boolean;
408 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
411 pData
, pData2
: Pointer;
417 e_WriteLog(Format('Loading player model "%s"...', [FileName
]), TMsgType
.Notify
);
421 WAD
:= TWADFile
.Create
;
422 WAD
.ReadFile(FileName
);
424 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
430 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
436 config
:= TConfig
.CreateMem(pData
, len
);
439 s
:= config
.ReadStr('Model', 'name', '');
447 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
448 ID
:= High(PlayerModelsArray
);
450 prefix
:= FileName
+':TEXTURES\';
452 with PlayerModelsArray
[ID
].Info
do
455 Author
:= config
.ReadStr('Model', 'author', '');
456 Description
:= config
.ReadStr('Model', 'description', '');
459 with PlayerModelsArray
[ID
] do
461 Blood
.R
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'R', 150)));
462 Blood
.G
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'G', 0)));
463 Blood
.B
:= MAX(0, MIN(255, config
.ReadInt('Blood', 'B', 0)));
464 case config
.ReadStr('Blood', 'Kind', 'NORMAL') of
465 'NORMAL': Blood
.Kind
:= BLOOD_NORMAL
;
466 'SPARKS': Blood
.Kind
:= BLOOD_CSPARKS
;
467 'COMBINE': Blood
.Kind
:= BLOOD_COMBINE
;
469 Blood
.Kind
:= BLOOD_NORMAL
473 for b
:= A_STAND
to A_LAST
do
475 aname
:= s
+'_RIGHTANIM'+IntToStr(b
);
476 //e_LogWritefln('### MODEL FILE: [%s]', [prefix+config.ReadStr(AnimNames[b], 'resource', '')]);
477 if not (g_Frames_CreateWAD(nil, aname
,
478 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
479 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
480 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
481 g_Frames_CreateWAD(nil, aname
+'_MASK',
482 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
483 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
484 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
486 if b
<= A_LASTBASE
then
494 ExtAnimFromBaseAnim(s
, b
);
499 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
500 for bb
:= A_STAND
to A_LAST
do
501 for cc
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
503 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
504 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
505 if f
> 2 then f
:= 2*f
-2;
506 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
509 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
510 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
512 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
513 g_Frames_CreateWAD(nil, aname
,
514 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
515 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
516 config
.ReadBool(AnimNames
[b
], 'backanim', False));
518 g_Frames_CreateWAD(nil, aname
+'_MASK',
519 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
520 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
521 config
.ReadBool(AnimNames
[b
], 'backanim', False));
524 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
527 with PlayerModelsArray
[ID
], config
do
529 {$IFDEF ENABLE_SOUND}
530 prefix
:= FileName
+':SOUNDS\';
534 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
537 SetLength(PainSounds
, Length(PainSounds
)+1);
538 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
539 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
546 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
549 SetLength(DieSounds
, Length(DieSounds
)+1);
550 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
551 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
556 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
559 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
562 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
563 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
565 for a
:= 0 to High(Gibs
) do
566 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
567 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
569 //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
570 Gibs
[a
].Rect
:= g_PlayerModel_CalcGibSize(pData
, lenpd
, a
*32, 0, 32, 32);
572 if Height
> 3 then Height
:= Height
-1-Random(2);
573 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
581 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
582 for bb
:= A_STAND
to A_LAST
do
583 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
585 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
586 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
587 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
589 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
591 // workaround for flamethrower
592 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, TDirection
.D_RIGHT
,
593 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
594 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
597 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
602 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
603 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
605 A_WALKATTACK
, A_WALK
:
607 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 9);
608 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 9);
612 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
613 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 8);
615 A_WALKSEEUP
, A_SEEUP
:
617 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
618 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
620 A_WALKSEEDOWN
, A_SEEDOWN
:
622 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
623 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 5);
625 A_WALKATTACKUP
, A_ATTACKUP
:
627 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 5);
628 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 16);
630 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
632 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
, 6);
633 Dec(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
, 4);
638 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
640 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, TDirection
.D_LEFT
,
641 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
642 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
644 for f
:= 0 to High(WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
]) do
646 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].X
;
647 WeaponPoints
[aa
, bb
, TDirection
.D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, TDirection
.D_RIGHT
, f
].Y
;
650 if not ok
then Break
;
652 {if ok then g_Console_Add(Info.Name+' weapon points ok')
653 else g_Console_Add(Info.Name+' weapon points fail');}
654 Info
.HaveWeapon
:= ok
;
656 s
:= config
.ReadStr('Model', 'flag_point', '');
657 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
659 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
668 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
676 if PlayerModelsArray
= nil then Exit
;
678 for a
:= 0 to High(PlayerModelsArray
) do
679 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
681 Result
:= TPlayerModel
.Create
;
683 with PlayerModelsArray
[a
] do
685 Result
.FName
:= Info
.Name
;
686 Result
.FBlood
:= Blood
;
688 for b
:= A_STAND
to A_LAST
do
690 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
691 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
697 Result
.FAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
698 Result
.FMaskAnim
[TDirection
.D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
700 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
701 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
702 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
703 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
705 Result
.FAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
706 Result
.FMaskAnim
[TDirection
.D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
710 {$IFDEF ENABLE_SOUND}
711 Result
.FPainSounds
:= PainSounds
;
712 Result
.FDieSounds
:= DieSounds
;
713 Result
.FSlopSound
:= SlopSound
;
715 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
716 Result
.FWeaponPoints
:= WeaponPoints
;
718 Result
.FFlagPoint
:= FlagPoint
;
719 Result
.FFlagAngle
:= FlagAngle
;
726 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
736 for a
:= 0 to High(PlayerModelsArray
) do
737 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
738 with PlayerModelsArray
[a
] do
740 c
:= Anim
in [A_STAND
, A_WALK
];
742 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
743 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then
746 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
747 _Anim
.Speed
:= ModelSpeed
[Anim
];
749 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
750 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then
753 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
754 _Mask
.Speed
:= ModelSpeed
[Anim
];
761 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
768 if PlayerModelsArray
= nil then Exit
;
769 if gGibsCount
= 0 then Exit
;
773 SetLength(Gibs
, gGibsCount
);
775 for a
:= 0 to High(PlayerModelsArray
) do
776 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
778 for i
:= 0 to High(Gibs
) do
780 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
787 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
788 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
790 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
792 if Gibs
[i
].OnlyOne
then c
:= True;
800 function g_PlayerModel_GetNames(): SSArray
;
806 if PlayerModelsArray
= nil then Exit
;
808 for i
:= 0 to High(PlayerModelsArray
) do
810 SetLength(Result
, Length(Result
)+1);
811 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
815 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
819 Result
:= Default(TModelInfo
);
820 if PlayerModelsArray
= nil then Exit
;
822 for a
:= 0 to High(PlayerModelsArray
) do
823 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
825 Result
:= PlayerModelsArray
[a
].Info
;
830 function g_PlayerModel_GetBlood(ModelName
: string): TModelBlood
;
837 Result
.Kind
:= BLOOD_NORMAL
;
838 if PlayerModelsArray
= nil then Exit
;
840 for a
:= 0 to High(PlayerModelsArray
) do
841 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
843 Result
:= PlayerModelsArray
[a
].Blood
;
848 procedure g_PlayerModel_FreeData();
853 for a
:= WP_FIRST
+ 1 to WP_LAST
do
854 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
855 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
856 e_DeleteTexture(WeaponID
[a
][b
][c
]);
858 e_WriteLog('Releasing models...', TMsgType
.Notify
);
860 if PlayerModelsArray
= nil then Exit
;
862 for i
:= 0 to High(PlayerModelsArray
) do
863 with PlayerModelsArray
[i
] do
865 for a
:= A_STAND
to A_LAST
do
867 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
868 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
869 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
870 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
873 {$IFDEF ENABLE_SOUND}
874 if PainSounds
<> nil then
875 for b
:= 0 to High(PainSounds
) do
876 e_DeleteSound(PainSounds
[b
].ID
);
878 if DieSounds
<> nil then
879 for b
:= 0 to High(DieSounds
) do
880 e_DeleteSound(DieSounds
[b
].ID
);
884 for b
:= 0 to High(Gibs
) do
886 e_DeleteTexture(Gibs
[b
].ID
);
887 e_DeleteTexture(Gibs
[b
].MaskID
);
891 PlayerModelsArray
:= nil;
896 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
898 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
900 FCurrentAnimation
:= Animation
;
902 if (FDirection
= TDirection
.D_LEFT
) and
903 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) and
904 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
906 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
907 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Reset
;
911 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
912 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Reset
;
916 destructor TPlayerModel
.Destroy();
920 for a
:= A_STAND
to A_LAST
do
922 FAnim
[TDirection
.D_LEFT
][a
].Free();
923 FMaskAnim
[TDirection
.D_LEFT
][a
].Free();
924 FAnim
[TDirection
.D_RIGHT
][a
].Free();
925 FMaskAnim
[TDirection
.D_RIGHT
][a
].Free();
931 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
938 if Direction
= TDirection
.D_LEFT
then
939 Mirror
:= TMirrorType
.None
941 Mirror
:= TMirrorType
.Horizontal
;
943 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
944 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
946 p
.X
:= IfThen(Direction
= TDirection
.D_LEFT
,
948 64-FLAG_BASEPOINT
.X
);
949 p
.Y
:= FLAG_BASEPOINT
.Y
;
951 FFlagAnim
.DrawEx(X
+IfThen(Direction
= TDirection
.D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
952 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
953 IfThen(FDirection
= TDirection
.D_RIGHT
, FFlagAngle
, -FFlagAngle
));
957 if Direction
= TDirection
.D_RIGHT
958 then Mirror
:= TMirrorType
.None
959 else Mirror
:= TMirrorType
.Horizontal
;
962 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
963 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
965 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
968 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
]
969 then pos
:= W_POS_DOWN
970 else pos
:= W_POS_NORMAL
;
972 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or FFire
973 then act
:= W_ACT_FIRE
974 else act
:= W_ACT_NORMAL
;
977 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
978 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
979 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
980 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
981 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
982 0, True, False, Mirror
);
986 if (FDirection
= TDirection
.D_LEFT
) and
987 (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
989 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
990 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, TMirrorType
.None
);
994 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
995 FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
1001 if (FDirection
= TDirection
.D_LEFT
) and
1002 (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1004 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
1005 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, TMirrorType
.None
);
1009 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
1010 FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
1018 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
1020 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1021 Result
:= FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
1023 Result
:= FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
1026 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
1028 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1029 Result
:= FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
]
1031 Result
:= FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
];
1034 {$IFDEF ENABLE_SOUND}
1035 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
1037 TempArray
: array of DWORD
;
1041 SetLength(TempArray
, 0);
1043 if SoundType
= MODELSOUND_PAIN
then
1045 if FPainSounds
= nil then Exit
;
1047 for a
:= 0 to High(FPainSounds
) do
1048 if FPainSounds
[a
].Level
= Level
then
1050 SetLength(TempArray
, Length(TempArray
)+1);
1051 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
1056 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
1058 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
1059 if FSlopSound
= 1 then
1065 if FDieSounds
= nil then Exit
;
1067 for a
:= 0 to High(FDieSounds
) do
1068 if FDieSounds
[a
].Level
= Level
then
1070 SetLength(TempArray
, Length(TempArray
)+1);
1071 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
1073 if (TempArray
= nil) and (Level
= 5) then
1075 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
1081 if TempArray
= nil then Exit
;
1083 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
1089 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
1096 procedure TPlayerModel
.SetFire(Fire
: Boolean);
1100 if FFire
then FFireCounter
:= FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].Speed
*FAnim
[TDirection
.D_RIGHT
, A_ATTACK
].TotalFrames
1101 else FFireCounter
:= 0;
1104 procedure TPlayerModel
.SetFlag(Flag
: Byte);
1114 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1115 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1119 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
1122 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
1124 FCurrentWeapon
:= Weapon
;
1127 procedure TPlayerModel
.Update();
1129 if (FDirection
= TDirection
.D_LEFT
) and (FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1130 FAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1132 if (FDirection
= TDirection
.D_LEFT
) and (FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
] <> nil) then
1133 FMaskAnim
[TDirection
.D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[TDirection
.D_RIGHT
][FCurrentAnimation
].Update
;
1135 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1137 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;