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}
22 MAPDEF
, g_textures
, g_basic
, g_weapons
, e_graphics
, wadreader
;
40 A_WALKATTACKDOWN
= 14;
44 A_FISTWALKATTACK
= 18;
48 A_FISTATTACKDOWN
= 22;
51 A_LASTEXT
= A_FISTATTACKDOWN
;
77 TModelSoundArray
= Array of TModelSound
;
78 TGibsArray
= Array of TGibSprite
;
79 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
] of
80 Array [A_STAND
..A_LAST
] of
81 Array [D_LEFT
..D_RIGHT
] of Array of TDFPoint
;
83 TPlayerModel
= class (TObject
)
86 FDirection
: TDirection
;
88 FCurrentAnimation
: Byte;
89 FAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
90 FMaskAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
91 FWeaponPoints
: TWeaponPoints
;
92 FPainSounds
: TModelSoundArray
;
93 FDieSounds
: TModelSoundArray
;
100 FFlagAnim
: TAnimation
;
105 destructor Destroy(); override;
106 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
107 function GetCurrentAnimation
: TAnimation
;
108 function GetCurrentAnimationMask
: TAnimation
;
109 procedure SetColor(Red
, Green
, Blue
: Byte);
110 procedure SetWeapon(Weapon
: Byte);
111 procedure SetFlag(Flag
: Byte);
112 procedure SetFire(Fire
: Boolean);
113 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
115 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
117 property Fire
: Boolean read FFire
;
118 property Direction
: TDirection read FDirection write FDirection
;
119 property Animation
: Byte read FCurrentAnimation
;
120 property Weapon
: Byte read FCurrentWeapon
;
121 property Name
: String read FName
;
122 property Color
: TRGB read FColor write FColor
;
125 procedure g_PlayerModel_LoadData();
126 procedure g_PlayerModel_FreeData();
127 function g_PlayerModel_Load(FileName
: String): Boolean;
128 function g_PlayerModel_GetNames(): SArray
;
129 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
130 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
131 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
132 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
137 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
138 GL
, GLExt
, e_sound
, g_options
, g_map
, Math
, e_log
;
141 TPlayerModelInfo
= record
143 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
146 WeaponPoints
: TWeaponPoints
;
148 PainSounds
: TModelSoundArray
;
149 DieSounds
: TModelSoundArray
;
161 FLAG_BASEPOINT
: TDFPoint
= (X
:16; Y
:43);
162 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
164 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
165 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
166 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
167 (X
:16; Y
:16), (X
:8; Y
:8));
169 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
170 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
171 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
173 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
174 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
175 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
176 'FistAttackUpAnim', 'FistAttackDownAnim');
177 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
178 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
181 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
182 Array [W_POS_NORMAL
..W_POS_DOWN
] of
183 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
184 PlayerModelsArray
: Array of TPlayerModelInfo
;
186 procedure g_PlayerModel_LoadData();
190 for a
:= WP_FIRST
+ 1 to WP_LAST
do
192 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
193 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
194 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
195 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
196 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
197 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
201 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
211 if Length(str
) < 3 then
214 for a
:= 1 to Length(str
) do
215 if (str
[a
] = ',') or (a
= Length(str
)) then
217 s
:= Copy(str
, 1, a
);
218 if s
[Length(s
)] = ',' then
219 SetLength(s
, Length(s
)-1);
222 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
223 (x
< -64) or (x
> 128) or
224 (y
< -64) or (y
> 128) then
236 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
237 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
246 backanim
:= backanim
and (frames
> 2);
248 for a
:= 1 to frames
do
250 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
253 with wpoints
[weapon
, anim
, dir
, a
-1] do
255 X
:= X
- WEAPONBASE
[weapon
].X
;
256 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
262 h
:= High(wpoints
[weapon
, anim
, dir
]);
264 for b
:= h
downto frames
do
265 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
270 procedure ExtAnimFromBaseAnim(MName
: String; AIdx
: Integer);
272 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
273 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
274 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
275 A_ATTACKUP
, A_ATTACKDOWN
280 AName
, OName
: String;
282 // HACK: shitty workaround to duplicate base animations
283 // in place of extended, replace with something better later
285 Assert((AIdx
> A_LASTBASE
) and (AIdx
<= A_LASTEXT
));
286 OIdx
:= CopyAnim
[AIdx
];
288 AName
:= MName
+ '_RIGHTANIM' + IntToStr(AIdx
);
289 OName
:= MName
+ '_RIGHTANIM' + IntToStr(OIdx
);
290 Assert(g_Frames_Dup(AName
, OName
));
291 Assert(g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK'));
292 AName
:= MName
+ '_LEFTANIM' + IntToStr(AIdx
);
293 OName
:= MName
+ '_LEFTANIM' + IntToStr(OIdx
);
294 if g_Frames_Exists(AName
) then
296 g_Frames_Dup(AName
, OName
);
297 g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK');
300 with PlayerModelsArray
[High(PlayerModelsArray
)] do
302 for W
:= WP_FIRST
+ 1 to WP_LAST
do
304 for D
:= D_LEFT
to D_RIGHT
do
306 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
307 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
308 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
314 function g_PlayerModel_Load(FileName
: string): Boolean;
317 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
320 pData
, pData2
: Pointer;
326 e_WriteLog(Format('Loading player model: %s', [ExtractFileName(FileName
)]), MSG_NOTIFY
);
330 WAD
:= TWADFile
.Create
;
331 WAD
.ReadFile(FileName
);
333 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
339 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
345 config
:= TConfig
.CreateMem(pData
, len
);
348 s
:= config
.ReadStr('Model', 'name', '');
356 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
357 ID
:= High(PlayerModelsArray
);
359 prefix
:= FileName
+':TEXTURES\';
361 with PlayerModelsArray
[ID
].Info
do
364 Author
:= config
.ReadStr('Model', 'author', '');
365 Description
:= config
.ReadStr('Model', 'description', '');
368 for b
:= A_STAND
to A_LAST
do
370 aname
:= s
+'_RIGHTANIM'+IntToStr(b
);
371 //e_LogWritefln('### MODEL FILE: [%s]', [prefix+config.ReadStr(AnimNames[b], 'resource', '')]);
372 if not (g_Frames_CreateWAD(nil, aname
,
373 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
374 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
375 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
376 g_Frames_CreateWAD(nil, aname
+'_MASK',
377 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
378 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
379 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
381 if b
<= A_LASTBASE
then
389 ExtAnimFromBaseAnim(s
, b
);
394 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
395 for bb
:= A_STAND
to A_LAST
do
396 for cc
:= D_LEFT
to D_RIGHT
do
398 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
399 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
400 if f
> 2 then f
:= 2*f
-2;
401 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
404 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
405 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
407 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
408 g_Frames_CreateWAD(nil, aname
,
409 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
410 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
411 config
.ReadBool(AnimNames
[b
], 'backanim', False));
413 g_Frames_CreateWAD(nil, aname
+'_MASK',
414 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
415 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
416 config
.ReadBool(AnimNames
[b
], 'backanim', False));
419 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
422 with PlayerModelsArray
[ID
], config
do
424 prefix
:= FileName
+':SOUNDS\';
428 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
431 SetLength(PainSounds
, Length(PainSounds
)+1);
432 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
433 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
440 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
443 SetLength(DieSounds
, Length(DieSounds
)+1);
444 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
445 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
450 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
452 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
455 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
456 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
458 for a
:= 0 to High(Gibs
) do
459 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
460 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
462 Gibs
[a
].Rect
:= e_GetTextureSize2(Gibs
[a
].ID
);
464 if Height
> 3 then Height
:= Height
-1-Random(2);
465 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
473 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
474 for bb
:= A_STAND
to A_LAST
do
475 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
477 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, D_RIGHT
,
478 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
479 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
481 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
483 // workaround for flamethrower
484 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, D_RIGHT
,
485 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
486 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
489 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
494 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
495 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
497 A_WALKATTACK
, A_WALK
:
499 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 9);
500 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 9);
504 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
505 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
507 A_WALKSEEUP
, A_SEEUP
:
509 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
510 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
512 A_WALKSEEDOWN
, A_SEEDOWN
:
514 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
515 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 5);
517 A_WALKATTACKUP
, A_ATTACKUP
:
519 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
520 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
522 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
524 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
525 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 4);
530 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
532 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, D_LEFT
,
533 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
534 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
536 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
538 WeaponPoints
[aa
, bb
, D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
;
539 WeaponPoints
[aa
, bb
, D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
;
542 if not ok
then Break
;
544 {if ok then g_Console_Add(Info.Name+' weapon points ok')
545 else g_Console_Add(Info.Name+' weapon points fail');}
546 Info
.HaveWeapon
:= ok
;
548 s
:= config
.ReadStr('Model', 'flag_point', '');
549 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
551 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
560 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
568 if PlayerModelsArray
= nil then Exit
;
570 for a
:= 0 to High(PlayerModelsArray
) do
571 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
573 Result
:= TPlayerModel
.Create
;
575 with PlayerModelsArray
[a
] do
577 Result
.FName
:= Info
.Name
;
579 for b
:= A_STAND
to A_LAST
do
581 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
582 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
589 Result
.FAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
591 Result
.FMaskAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
593 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
594 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
595 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
596 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
598 Result
.FAnim
[D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
600 Result
.FMaskAnim
[D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
604 Result
.FPainSounds
:= PainSounds
;
605 Result
.FDieSounds
:= DieSounds
;
606 Result
.FSlopSound
:= SlopSound
;
607 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
608 Result
.FWeaponPoints
:= WeaponPoints
;
610 Result
.FFlagPoint
:= FlagPoint
;
611 Result
.FFlagAngle
:= FlagAngle
;
618 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
626 if PlayerModelsArray
= nil then Exit
;
627 for a
:= 0 to High(PlayerModelsArray
) do
628 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
629 with PlayerModelsArray
[a
] do
631 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
633 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
634 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
636 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
637 _Anim
.Speed
:= ModelSpeed
[Anim
];
639 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
640 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
642 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
643 _Mask
.Speed
:= ModelSpeed
[Anim
];
651 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
658 if PlayerModelsArray
= nil then Exit
;
659 if gGibsCount
= 0 then Exit
;
663 SetLength(Gibs
, gGibsCount
);
665 for a
:= 0 to High(PlayerModelsArray
) do
666 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
668 for i
:= 0 to High(Gibs
) do
670 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
677 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
678 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
680 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
682 if Gibs
[i
].OnlyOne
then c
:= True;
690 function g_PlayerModel_GetNames(): SArray
;
696 if PlayerModelsArray
= nil then Exit
;
698 for i
:= 0 to High(PlayerModelsArray
) do
700 SetLength(Result
, Length(Result
)+1);
701 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
705 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
709 FillChar(Result
, SizeOf(Result
), 0);
710 if PlayerModelsArray
= nil then Exit
;
712 for a
:= 0 to High(PlayerModelsArray
) do
713 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
715 Result
:= PlayerModelsArray
[a
].Info
;
720 procedure g_PlayerModel_FreeData();
725 for a
:= WP_FIRST
+ 1 to WP_LAST
do
726 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
727 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
728 e_DeleteTexture(WeaponID
[a
][b
][c
]);
730 e_WriteLog('Releasing models...', MSG_NOTIFY
);
732 if PlayerModelsArray
= nil then Exit
;
734 for i
:= 0 to High(PlayerModelsArray
) do
735 with PlayerModelsArray
[i
] do
737 for a
:= A_STAND
to A_LAST
do
739 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
740 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
741 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
742 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
745 if PainSounds
<> nil then
746 for b
:= 0 to High(PainSounds
) do
747 e_DeleteSound(PainSounds
[b
].ID
);
749 if DieSounds
<> nil then
750 for b
:= 0 to High(DieSounds
) do
751 e_DeleteSound(DieSounds
[b
].ID
);
754 for b
:= 0 to High(Gibs
) do
756 e_DeleteTexture(Gibs
[b
].ID
);
757 e_DeleteTexture(Gibs
[b
].MaskID
);
761 PlayerModelsArray
:= nil;
766 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
768 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
770 FCurrentAnimation
:= Animation
;
772 if (FDirection
= D_LEFT
) and
773 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) and
774 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
776 FAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
777 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
781 FAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
782 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
786 destructor TPlayerModel
.Destroy();
790 for a
:= A_STAND
to A_LAST
do
792 FAnim
[D_LEFT
][a
].Free();
793 FMaskAnim
[D_LEFT
][a
].Free();
794 FAnim
[D_RIGHT
][a
].Free();
795 FMaskAnim
[D_RIGHT
][a
].Free();
801 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
808 if Direction
= D_LEFT
then
811 Mirror
:= M_HORIZONTAL
;
813 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
814 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
816 p
.X
:= IfThen(Direction
= D_LEFT
,
818 64-FLAG_BASEPOINT
.X
);
819 p
.Y
:= FLAG_BASEPOINT
.Y
;
821 FFlagAnim
.DrawEx(X
+IfThen(Direction
= D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
822 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
823 IfThen(FDirection
= D_RIGHT
, FFlagAngle
, -FFlagAngle
));
827 if Direction
= D_RIGHT
then
830 Mirror
:= M_HORIZONTAL
;
833 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
834 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
836 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
839 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
844 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
851 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
852 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
853 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
854 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
855 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
856 0, True, False, Mirror
);
860 if (FDirection
= D_LEFT
) and
861 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
863 FAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
864 FAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
868 FAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
869 FAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
875 if (FDirection
= D_LEFT
) and
876 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
878 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
879 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
883 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
884 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
892 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
894 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
895 Result
:= FAnim
[D_LEFT
][FCurrentAnimation
]
897 Result
:= FAnim
[D_RIGHT
][FCurrentAnimation
];
900 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
902 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
903 Result
:= FMaskAnim
[D_LEFT
][FCurrentAnimation
]
905 Result
:= FMaskAnim
[D_RIGHT
][FCurrentAnimation
];
908 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
910 TempArray
: array of DWORD
;
914 SetLength(TempArray
, 0);
916 if SoundType
= MODELSOUND_PAIN
then
918 if FPainSounds
= nil then Exit
;
920 for a
:= 0 to High(FPainSounds
) do
921 if FPainSounds
[a
].Level
= Level
then
923 SetLength(TempArray
, Length(TempArray
)+1);
924 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
929 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
931 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
932 if FSlopSound
= 1 then
938 if FDieSounds
= nil then Exit
;
940 for a
:= 0 to High(FDieSounds
) do
941 if FDieSounds
[a
].Level
= Level
then
943 SetLength(TempArray
, Length(TempArray
)+1);
944 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
946 if (TempArray
= nil) and (Level
= 5) then
948 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
954 if TempArray
= nil then Exit
;
956 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
961 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
968 procedure TPlayerModel
.SetFire(Fire
: Boolean);
972 if FFire
then FFireCounter
:= FAnim
[D_RIGHT
, A_ATTACK
].Speed
*FAnim
[D_RIGHT
, A_ATTACK
].TotalFrames
973 else FFireCounter
:= 0;
976 procedure TPlayerModel
.SetFlag(Flag
: Byte);
986 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
987 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
991 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
994 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
996 FCurrentWeapon
:= Weapon
;
999 procedure TPlayerModel
.Update();
1001 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
1002 FAnim
[D_LEFT
][FCurrentAnimation
].Update
else FAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
1004 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
1005 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
1007 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1009 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;