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 MAPDEF
, g_textures
, g_basic
, g_weapons
, e_graphics
, wadreader
;
41 A_WALKATTACKDOWN
= 14;
45 A_FISTWALKATTACK
= 18;
49 A_FISTATTACKDOWN
= 22;
52 A_LASTEXT
= A_FISTATTACKDOWN
;
78 TModelSoundArray
= Array of TModelSound
;
79 TGibsArray
= Array of TGibSprite
;
80 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
] of
81 Array [A_STAND
..A_LAST
] of
82 Array [D_LEFT
..D_RIGHT
] of Array of TDFPoint
;
84 TPlayerModel
= class (TObject
)
87 FDirection
: TDirection
;
89 FCurrentAnimation
: Byte;
90 FAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
91 FMaskAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
92 FWeaponPoints
: TWeaponPoints
;
93 FPainSounds
: TModelSoundArray
;
94 FDieSounds
: TModelSoundArray
;
100 FFlagAngle
: SmallInt;
101 FFlagAnim
: TAnimation
;
106 destructor Destroy(); override;
107 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
108 function GetCurrentAnimation
: TAnimation
;
109 function GetCurrentAnimationMask
: TAnimation
;
110 procedure SetColor(Red
, Green
, Blue
: Byte);
111 procedure SetWeapon(Weapon
: Byte);
112 procedure SetFlag(Flag
: Byte);
113 procedure SetFire(Fire
: Boolean);
114 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
116 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
119 property Fire
: Boolean read FFire
;
120 property Direction
: TDirection read FDirection write FDirection
;
121 property Animation
: Byte read FCurrentAnimation
;
122 property Weapon
: Byte read FCurrentWeapon
;
123 property Name
: String read FName
;
126 property Color
: TRGB read FColor write FColor
;
129 procedure g_PlayerModel_LoadData();
130 procedure g_PlayerModel_FreeData();
131 function g_PlayerModel_Load(FileName
: String): Boolean;
132 function g_PlayerModel_GetNames(): SArray
;
133 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
134 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
135 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
136 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
141 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
142 GL
, GLExt
, e_sound
, g_options
, g_map
, Math
, e_log
;
145 TPlayerModelInfo
= record
147 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
150 WeaponPoints
: TWeaponPoints
;
152 PainSounds
: TModelSoundArray
;
153 DieSounds
: TModelSoundArray
;
165 FLAG_BASEPOINT
: TDFPoint
= (X
:16; Y
:43);
166 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
168 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
169 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
170 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
171 (X
:16; Y
:16), (X
:8; Y
:8));
173 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
174 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
175 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
177 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
178 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
179 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
180 'FistAttackUpAnim', 'FistAttackDownAnim');
181 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
182 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
185 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
186 Array [W_POS_NORMAL
..W_POS_DOWN
] of
187 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
188 PlayerModelsArray
: Array of TPlayerModelInfo
;
190 procedure g_PlayerModel_LoadData();
194 for a
:= WP_FIRST
+ 1 to WP_LAST
do
196 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
197 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
198 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
199 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
200 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
201 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
205 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
215 if Length(str
) < 3 then
218 for a
:= 1 to Length(str
) do
219 if (str
[a
] = ',') or (a
= Length(str
)) then
221 s
:= Copy(str
, 1, a
);
222 if s
[Length(s
)] = ',' then
223 SetLength(s
, Length(s
)-1);
226 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
227 (x
< -64) or (x
> 128) or
228 (y
< -64) or (y
> 128) then
240 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
241 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
250 backanim
:= backanim
and (frames
> 2);
252 for a
:= 1 to frames
do
254 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
257 with wpoints
[weapon
, anim
, dir
, a
-1] do
259 X
:= X
- WEAPONBASE
[weapon
].X
;
260 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
266 h
:= High(wpoints
[weapon
, anim
, dir
]);
268 for b
:= h
downto frames
do
269 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
274 procedure ExtAnimFromBaseAnim(MName
: String; AIdx
: Integer);
276 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
277 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
278 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
279 A_ATTACKUP
, A_ATTACKDOWN
284 AName
, OName
: String;
286 // HACK: shitty workaround to duplicate base animations
287 // in place of extended, replace with something better later
289 Assert((AIdx
> A_LASTBASE
) and (AIdx
<= A_LASTEXT
));
290 OIdx
:= CopyAnim
[AIdx
];
292 AName
:= MName
+ '_RIGHTANIM' + IntToStr(AIdx
);
293 OName
:= MName
+ '_RIGHTANIM' + IntToStr(OIdx
);
294 Assert(g_Frames_Dup(AName
, OName
));
295 Assert(g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK'));
296 AName
:= MName
+ '_LEFTANIM' + IntToStr(AIdx
);
297 OName
:= MName
+ '_LEFTANIM' + IntToStr(OIdx
);
298 if g_Frames_Exists(AName
) then
300 g_Frames_Dup(AName
, OName
);
301 g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK');
304 with PlayerModelsArray
[High(PlayerModelsArray
)] do
306 for W
:= WP_FIRST
+ 1 to WP_LAST
do
308 for D
:= D_LEFT
to D_RIGHT
do
310 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
311 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
312 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
318 function g_PlayerModel_Load(FileName
: string): Boolean;
321 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
324 pData
, pData2
: Pointer;
330 e_WriteLog(Format('Loading player model: %s', [ExtractFileName(FileName
)]), MSG_NOTIFY
);
334 WAD
:= TWADFile
.Create
;
335 WAD
.ReadFile(FileName
);
337 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
343 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
349 config
:= TConfig
.CreateMem(pData
, len
);
352 s
:= config
.ReadStr('Model', 'name', '');
360 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
361 ID
:= High(PlayerModelsArray
);
363 prefix
:= FileName
+':TEXTURES\';
365 with PlayerModelsArray
[ID
].Info
do
368 Author
:= config
.ReadStr('Model', 'author', '');
369 Description
:= config
.ReadStr('Model', 'description', '');
372 for b
:= A_STAND
to A_LAST
do
374 aname
:= s
+'_RIGHTANIM'+IntToStr(b
);
375 //e_LogWritefln('### MODEL FILE: [%s]', [prefix+config.ReadStr(AnimNames[b], 'resource', '')]);
376 if not (g_Frames_CreateWAD(nil, aname
,
377 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
378 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
379 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
380 g_Frames_CreateWAD(nil, aname
+'_MASK',
381 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
382 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
383 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
385 if b
<= A_LASTBASE
then
393 ExtAnimFromBaseAnim(s
, b
);
398 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
399 for bb
:= A_STAND
to A_LAST
do
400 for cc
:= D_LEFT
to D_RIGHT
do
402 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
403 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
404 if f
> 2 then f
:= 2*f
-2;
405 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
408 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
409 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
411 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
412 g_Frames_CreateWAD(nil, aname
,
413 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
414 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
415 config
.ReadBool(AnimNames
[b
], 'backanim', False));
417 g_Frames_CreateWAD(nil, aname
+'_MASK',
418 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
419 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
420 config
.ReadBool(AnimNames
[b
], 'backanim', False));
423 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
426 with PlayerModelsArray
[ID
], config
do
428 prefix
:= FileName
+':SOUNDS\';
432 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
435 SetLength(PainSounds
, Length(PainSounds
)+1);
436 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
437 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
444 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
447 SetLength(DieSounds
, Length(DieSounds
)+1);
448 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
449 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
454 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
456 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
459 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
460 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
462 for a
:= 0 to High(Gibs
) do
463 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
464 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
466 Gibs
[a
].Rect
:= e_GetTextureSize2(Gibs
[a
].ID
);
468 if Height
> 3 then Height
:= Height
-1-Random(2);
469 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
477 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
478 for bb
:= A_STAND
to A_LAST
do
479 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
481 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, D_RIGHT
,
482 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
483 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
485 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
487 // workaround for flamethrower
488 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, D_RIGHT
,
489 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
490 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
493 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
498 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
499 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
501 A_WALKATTACK
, A_WALK
:
503 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 9);
504 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 9);
508 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
509 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
511 A_WALKSEEUP
, A_SEEUP
:
513 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
514 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
516 A_WALKSEEDOWN
, A_SEEDOWN
:
518 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
519 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 5);
521 A_WALKATTACKUP
, A_ATTACKUP
:
523 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
524 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
526 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
528 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
529 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 4);
534 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
536 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, D_LEFT
,
537 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
538 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
540 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
542 WeaponPoints
[aa
, bb
, D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
;
543 WeaponPoints
[aa
, bb
, D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
;
546 if not ok
then Break
;
548 {if ok then g_Console_Add(Info.Name+' weapon points ok')
549 else g_Console_Add(Info.Name+' weapon points fail');}
550 Info
.HaveWeapon
:= ok
;
552 s
:= config
.ReadStr('Model', 'flag_point', '');
553 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
555 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
564 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
572 if PlayerModelsArray
= nil then Exit
;
574 for a
:= 0 to High(PlayerModelsArray
) do
575 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
577 Result
:= TPlayerModel
.Create
;
579 with PlayerModelsArray
[a
] do
581 Result
.FName
:= Info
.Name
;
583 for b
:= A_STAND
to A_LAST
do
585 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
586 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
593 Result
.FAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
595 Result
.FMaskAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
597 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
598 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
599 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
600 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
602 Result
.FAnim
[D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
604 Result
.FMaskAnim
[D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
608 Result
.FPainSounds
:= PainSounds
;
609 Result
.FDieSounds
:= DieSounds
;
610 Result
.FSlopSound
:= SlopSound
;
611 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
612 Result
.FWeaponPoints
:= WeaponPoints
;
614 Result
.FFlagPoint
:= FlagPoint
;
615 Result
.FFlagAngle
:= FlagAngle
;
622 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
630 if PlayerModelsArray
= nil then Exit
;
631 for a
:= 0 to High(PlayerModelsArray
) do
632 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
633 with PlayerModelsArray
[a
] do
635 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
637 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
638 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
640 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
641 _Anim
.Speed
:= ModelSpeed
[Anim
];
643 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
644 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
646 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
647 _Mask
.Speed
:= ModelSpeed
[Anim
];
655 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
662 if PlayerModelsArray
= nil then Exit
;
663 if gGibsCount
= 0 then Exit
;
667 SetLength(Gibs
, gGibsCount
);
669 for a
:= 0 to High(PlayerModelsArray
) do
670 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
672 for i
:= 0 to High(Gibs
) do
674 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
681 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
682 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
684 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
686 if Gibs
[i
].OnlyOne
then c
:= True;
694 function g_PlayerModel_GetNames(): SArray
;
700 if PlayerModelsArray
= nil then Exit
;
702 for i
:= 0 to High(PlayerModelsArray
) do
704 SetLength(Result
, Length(Result
)+1);
705 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
709 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
713 FillChar(Result
, SizeOf(Result
), 0);
714 if PlayerModelsArray
= nil then Exit
;
716 for a
:= 0 to High(PlayerModelsArray
) do
717 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
719 Result
:= PlayerModelsArray
[a
].Info
;
724 procedure g_PlayerModel_FreeData();
729 for a
:= WP_FIRST
+ 1 to WP_LAST
do
730 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
731 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
732 e_DeleteTexture(WeaponID
[a
][b
][c
]);
734 e_WriteLog('Releasing models...', MSG_NOTIFY
);
736 if PlayerModelsArray
= nil then Exit
;
738 for i
:= 0 to High(PlayerModelsArray
) do
739 with PlayerModelsArray
[i
] do
741 for a
:= A_STAND
to A_LAST
do
743 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
744 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
745 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
746 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
749 if PainSounds
<> nil then
750 for b
:= 0 to High(PainSounds
) do
751 e_DeleteSound(PainSounds
[b
].ID
);
753 if DieSounds
<> nil then
754 for b
:= 0 to High(DieSounds
) do
755 e_DeleteSound(DieSounds
[b
].ID
);
758 for b
:= 0 to High(Gibs
) do
760 e_DeleteTexture(Gibs
[b
].ID
);
761 e_DeleteTexture(Gibs
[b
].MaskID
);
765 PlayerModelsArray
:= nil;
770 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
772 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
774 FCurrentAnimation
:= Animation
;
776 if (FDirection
= D_LEFT
) and
777 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) and
778 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
780 FAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
781 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
785 FAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
786 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
790 destructor TPlayerModel
.Destroy();
794 for a
:= A_STAND
to A_LAST
do
796 FAnim
[D_LEFT
][a
].Free();
797 FMaskAnim
[D_LEFT
][a
].Free();
798 FAnim
[D_RIGHT
][a
].Free();
799 FMaskAnim
[D_RIGHT
][a
].Free();
805 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
812 if Direction
= D_LEFT
then
815 Mirror
:= M_HORIZONTAL
;
817 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
818 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
820 p
.X
:= IfThen(Direction
= D_LEFT
,
822 64-FLAG_BASEPOINT
.X
);
823 p
.Y
:= FLAG_BASEPOINT
.Y
;
825 FFlagAnim
.DrawEx(X
+IfThen(Direction
= D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
826 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
827 IfThen(FDirection
= D_RIGHT
, FFlagAngle
, -FFlagAngle
));
831 if Direction
= D_RIGHT
then
834 Mirror
:= M_HORIZONTAL
;
837 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
838 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
840 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
843 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
848 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
855 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
856 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
857 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
858 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
859 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
860 0, True, False, Mirror
);
864 if (FDirection
= D_LEFT
) and
865 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
867 FAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
868 FAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
872 FAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
873 FAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
879 if (FDirection
= D_LEFT
) and
880 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
882 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
883 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
887 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
888 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
896 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
898 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
899 Result
:= FAnim
[D_LEFT
][FCurrentAnimation
]
901 Result
:= FAnim
[D_RIGHT
][FCurrentAnimation
];
904 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
906 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
907 Result
:= FMaskAnim
[D_LEFT
][FCurrentAnimation
]
909 Result
:= FMaskAnim
[D_RIGHT
][FCurrentAnimation
];
912 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
914 TempArray
: array of DWORD
;
918 SetLength(TempArray
, 0);
920 if SoundType
= MODELSOUND_PAIN
then
922 if FPainSounds
= nil then Exit
;
924 for a
:= 0 to High(FPainSounds
) do
925 if FPainSounds
[a
].Level
= Level
then
927 SetLength(TempArray
, Length(TempArray
)+1);
928 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
933 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
935 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
936 if FSlopSound
= 1 then
942 if FDieSounds
= nil then Exit
;
944 for a
:= 0 to High(FDieSounds
) do
945 if FDieSounds
[a
].Level
= Level
then
947 SetLength(TempArray
, Length(TempArray
)+1);
948 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
950 if (TempArray
= nil) and (Level
= 5) then
952 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
958 if TempArray
= nil then Exit
;
960 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
965 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
972 procedure TPlayerModel
.SetFire(Fire
: Boolean);
976 if FFire
then FFireCounter
:= FAnim
[D_RIGHT
, A_ATTACK
].Speed
*FAnim
[D_RIGHT
, A_ATTACK
].TotalFrames
977 else FFireCounter
:= 0;
980 procedure TPlayerModel
.SetFlag(Flag
: Byte);
990 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
991 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
995 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
998 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
1000 FCurrentWeapon
:= Weapon
;
1003 procedure TPlayerModel
.Update();
1005 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
1006 FAnim
[D_LEFT
][FCurrentAnimation
].Update
else FAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
1008 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
1009 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
1011 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1013 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;