b8d0ec6c7ef4b74d3f1c54c6a7297af846029d88
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}
24 MAPDEF
, g_textures
, g_basic
, g_weapons
, e_graphics
, wadreader
;
42 A_WALKATTACKDOWN
= 14;
46 A_FISTWALKATTACK
= 18;
50 A_FISTATTACKDOWN
= 22;
53 A_LASTEXT
= A_FISTATTACKDOWN
;
79 TModelSoundArray
= Array of TModelSound
;
80 TGibsArray
= Array of TGibSprite
;
81 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
] of
82 Array [A_STAND
..A_LAST
] of
83 Array [D_LEFT
..D_RIGHT
] of Array of TDFPoint
;
85 TPlayerModel
= class(TPoolObject
)
88 FDirection
: TDirection
;
90 FCurrentAnimation
: Byte;
91 FAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
92 FMaskAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_LAST
] of TAnimation
;
93 FWeaponPoints
: TWeaponPoints
;
94 FPainSounds
: TModelSoundArray
;
95 FDieSounds
: TModelSoundArray
;
100 FFlagPoint
: TDFPoint
;
101 FFlagAngle
: SmallInt;
102 FFlagAnim
: TAnimation
;
107 destructor Destroy(); override;
108 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
109 function GetCurrentAnimation
: TAnimation
;
110 function GetCurrentAnimationMask
: TAnimation
;
111 procedure SetColor(Red
, Green
, Blue
: Byte);
112 procedure SetWeapon(Weapon
: Byte);
113 procedure SetFlag(Flag
: Byte);
114 procedure SetFire(Fire
: Boolean);
115 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
117 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
120 property Fire
: Boolean read FFire
;
121 property Direction
: TDirection read FDirection write FDirection
;
122 property Animation
: Byte read FCurrentAnimation
;
123 property Weapon
: Byte read FCurrentWeapon
;
124 property Name
: String read FName
;
127 property Color
: TRGB read FColor write FColor
;
130 procedure g_PlayerModel_LoadData();
131 procedure g_PlayerModel_FreeData();
132 function g_PlayerModel_Load(FileName
: String): Boolean;
133 function g_PlayerModel_GetNames(): SArray
;
134 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
135 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
136 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
137 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
142 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
143 GL
, GLExt
, e_sound
, g_options
, g_map
, Math
, e_log
;
146 TPlayerModelInfo
= record
148 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
151 WeaponPoints
: TWeaponPoints
;
153 PainSounds
: TModelSoundArray
;
154 DieSounds
: TModelSoundArray
;
166 FLAG_BASEPOINT
: TDFPoint
= (X
:16; Y
:43);
167 FLAG_DEFPOINT
: TDFPoint
= (X
:32; Y
:16);
169 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TDFPoint
=
170 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
171 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
172 (X
:16; Y
:16), (X
:8; Y
:8));
174 AnimNames
: Array [A_STAND
..A_LASTEXT
] of String =
175 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
176 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim',
178 'WalkAttackAnim', 'WalkSeeUpAnim', 'WalkSeeDownAnim',
179 'WalkAttackUpAnim', 'WalkAttackDownAnim', 'FistStandAnim', 'FistWalkAnim',
180 'FistAttackAnim', 'FistWalkAttackAnim', 'FistSeeUpAnim', 'FistSeeDownAnim',
181 'FistAttackUpAnim', 'FistAttackDownAnim');
182 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
183 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
186 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
187 Array [W_POS_NORMAL
..W_POS_DOWN
] of
188 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
189 PlayerModelsArray
: Array of TPlayerModelInfo
;
191 procedure g_PlayerModel_LoadData();
195 for a
:= WP_FIRST
+ 1 to WP_LAST
do
197 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
198 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
199 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
200 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
201 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
202 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
206 function GetPoint(var str
: String; var point
: TDFPoint
): Boolean;
216 if Length(str
) < 3 then
219 for a
:= 1 to Length(str
) do
220 if (str
[a
] = ',') or (a
= Length(str
)) then
222 s
:= Copy(str
, 1, a
);
223 if s
[Length(s
)] = ',' then
224 SetLength(s
, Length(s
)-1);
227 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
228 (x
< -64) or (x
> 128) or
229 (y
< -64) or (y
> 128) then
241 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
242 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
251 backanim
:= backanim
and (frames
> 2);
253 for a
:= 1 to frames
do
255 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
258 with wpoints
[weapon
, anim
, dir
, a
-1] do
260 X
:= X
- WEAPONBASE
[weapon
].X
;
261 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
267 h
:= High(wpoints
[weapon
, anim
, dir
]);
269 for b
:= h
downto frames
do
270 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
275 procedure ExtAnimFromBaseAnim(MName
: String; AIdx
: Integer);
277 CopyAnim
: array [A_LASTBASE
+1..A_LASTEXT
] of Integer = (
278 A_WALK
, A_WALK
, A_WALK
, A_WALK
, A_WALK
,
279 A_STAND
, A_WALK
, A_ATTACK
, A_WALK
, A_SEEUP
, A_SEEDOWN
,
280 A_ATTACKUP
, A_ATTACKDOWN
285 AName
, OName
: String;
287 // HACK: shitty workaround to duplicate base animations
288 // in place of extended, replace with something better later
290 Assert((AIdx
> A_LASTBASE
) and (AIdx
<= A_LASTEXT
));
291 OIdx
:= CopyAnim
[AIdx
];
293 AName
:= MName
+ '_RIGHTANIM' + IntToStr(AIdx
);
294 OName
:= MName
+ '_RIGHTANIM' + IntToStr(OIdx
);
295 Assert(g_Frames_Dup(AName
, OName
));
296 Assert(g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK'));
297 AName
:= MName
+ '_LEFTANIM' + IntToStr(AIdx
);
298 OName
:= MName
+ '_LEFTANIM' + IntToStr(OIdx
);
299 if g_Frames_Exists(AName
) then
301 g_Frames_Dup(AName
, OName
);
302 g_Frames_Dup(AName
+ '_MASK', OName
+ '_MASK');
305 with PlayerModelsArray
[High(PlayerModelsArray
)] do
307 for W
:= WP_FIRST
+ 1 to WP_LAST
do
309 for D
:= D_LEFT
to D_RIGHT
do
311 SetLength(WeaponPoints
[W
, AIdx
, D
], Length(WeaponPoints
[W
, OIdx
, D
]));
312 for I
:= 0 to High(WeaponPoints
[W
, AIdx
, D
]) do
313 WeaponPoints
[W
, AIdx
, D
, I
] := WeaponPoints
[W
, OIdx
, D
, I
]
319 function g_PlayerModel_Load(FileName
: string): Boolean;
322 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
325 pData
, pData2
: Pointer;
331 e_WriteLog(Format('Loading player model: %s', [ExtractFileName(FileName
)]), MSG_NOTIFY
);
335 WAD
:= TWADFile
.Create
;
336 WAD
.ReadFile(FileName
);
338 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
344 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
350 config
:= TConfig
.CreateMem(pData
, len
);
353 s
:= config
.ReadStr('Model', 'name', '');
361 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
362 ID
:= High(PlayerModelsArray
);
364 prefix
:= FileName
+':TEXTURES\';
366 with PlayerModelsArray
[ID
].Info
do
369 Author
:= config
.ReadStr('Model', 'author', '');
370 Description
:= config
.ReadStr('Model', 'description', '');
373 for b
:= A_STAND
to A_LAST
do
375 aname
:= s
+'_RIGHTANIM'+IntToStr(b
);
376 //e_LogWritefln('### MODEL FILE: [%s]', [prefix+config.ReadStr(AnimNames[b], 'resource', '')]);
377 if not (g_Frames_CreateWAD(nil, aname
,
378 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
379 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
380 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
381 g_Frames_CreateWAD(nil, aname
+'_MASK',
382 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
383 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
384 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
386 if b
<= A_LASTBASE
then
394 ExtAnimFromBaseAnim(s
, b
);
399 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
400 for bb
:= A_STAND
to A_LAST
do
401 for cc
:= D_LEFT
to D_RIGHT
do
403 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
404 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
405 if f
> 2 then f
:= 2*f
-2;
406 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
409 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
410 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
412 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
413 g_Frames_CreateWAD(nil, aname
,
414 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
415 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
416 config
.ReadBool(AnimNames
[b
], 'backanim', False));
418 g_Frames_CreateWAD(nil, aname
+'_MASK',
419 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
420 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
421 config
.ReadBool(AnimNames
[b
], 'backanim', False));
424 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
427 with PlayerModelsArray
[ID
], config
do
429 prefix
:= FileName
+':SOUNDS\';
433 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
436 SetLength(PainSounds
, Length(PainSounds
)+1);
437 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
438 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
445 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
448 SetLength(DieSounds
, Length(DieSounds
)+1);
449 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
450 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
455 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
457 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
460 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
461 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
463 for a
:= 0 to High(Gibs
) do
464 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
465 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
467 Gibs
[a
].Rect
:= e_GetTextureSize2(Gibs
[a
].ID
);
469 if Height
> 3 then Height
:= Height
-1-Random(2);
470 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
478 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
479 for bb
:= A_STAND
to A_LAST
do
480 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
482 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, D_RIGHT
,
483 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
484 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
486 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
488 // workaround for flamethrower
489 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, D_RIGHT
,
490 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
491 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
494 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
499 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
500 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
502 A_WALKATTACK
, A_WALK
:
504 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 9);
505 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 9);
509 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
510 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
512 A_WALKSEEUP
, A_SEEUP
:
514 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
515 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
517 A_WALKSEEDOWN
, A_SEEDOWN
:
519 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
520 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 5);
522 A_WALKATTACKUP
, A_ATTACKUP
:
524 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
525 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
527 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
529 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
530 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 4);
535 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
537 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, D_LEFT
,
538 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
539 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
541 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
543 WeaponPoints
[aa
, bb
, D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
;
544 WeaponPoints
[aa
, bb
, D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
;
547 if not ok
then Break
;
549 {if ok then g_Console_Add(Info.Name+' weapon points ok')
550 else g_Console_Add(Info.Name+' weapon points fail');}
551 Info
.HaveWeapon
:= ok
;
553 s
:= config
.ReadStr('Model', 'flag_point', '');
554 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
556 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
565 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
573 if PlayerModelsArray
= nil then Exit
;
575 for a
:= 0 to High(PlayerModelsArray
) do
576 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
578 Result
:= TPlayerModel
.Create
;
580 with PlayerModelsArray
[a
] do
582 Result
.FName
:= Info
.Name
;
584 for b
:= A_STAND
to A_LAST
do
586 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
587 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
594 Result
.FAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
596 Result
.FMaskAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
598 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
599 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
600 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
601 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
603 Result
.FAnim
[D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
605 Result
.FMaskAnim
[D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
609 Result
.FPainSounds
:= PainSounds
;
610 Result
.FDieSounds
:= DieSounds
;
611 Result
.FSlopSound
:= SlopSound
;
612 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
613 Result
.FWeaponPoints
:= WeaponPoints
;
615 Result
.FFlagPoint
:= FlagPoint
;
616 Result
.FFlagAngle
:= FlagAngle
;
623 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
631 if PlayerModelsArray
= nil then Exit
;
632 for a
:= 0 to High(PlayerModelsArray
) do
633 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
634 with PlayerModelsArray
[a
] do
636 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
638 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
639 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
641 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
642 _Anim
.Speed
:= ModelSpeed
[Anim
];
644 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
645 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
647 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
648 _Mask
.Speed
:= ModelSpeed
[Anim
];
656 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
663 if PlayerModelsArray
= nil then Exit
;
664 if gGibsCount
= 0 then Exit
;
668 SetLength(Gibs
, gGibsCount
);
670 for a
:= 0 to High(PlayerModelsArray
) do
671 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
673 for i
:= 0 to High(Gibs
) do
675 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
682 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
683 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
685 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
687 if Gibs
[i
].OnlyOne
then c
:= True;
695 function g_PlayerModel_GetNames(): SArray
;
701 if PlayerModelsArray
= nil then Exit
;
703 for i
:= 0 to High(PlayerModelsArray
) do
705 SetLength(Result
, Length(Result
)+1);
706 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
710 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
714 FillChar(Result
, SizeOf(Result
), 0);
715 if PlayerModelsArray
= nil then Exit
;
717 for a
:= 0 to High(PlayerModelsArray
) do
718 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
720 Result
:= PlayerModelsArray
[a
].Info
;
725 procedure g_PlayerModel_FreeData();
730 for a
:= WP_FIRST
+ 1 to WP_LAST
do
731 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
732 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
733 e_DeleteTexture(WeaponID
[a
][b
][c
]);
735 e_WriteLog('Releasing models...', MSG_NOTIFY
);
737 if PlayerModelsArray
= nil then Exit
;
739 for i
:= 0 to High(PlayerModelsArray
) do
740 with PlayerModelsArray
[i
] do
742 for a
:= A_STAND
to A_LAST
do
744 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
745 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
746 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
747 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
750 if PainSounds
<> nil then
751 for b
:= 0 to High(PainSounds
) do
752 e_DeleteSound(PainSounds
[b
].ID
);
754 if DieSounds
<> nil then
755 for b
:= 0 to High(DieSounds
) do
756 e_DeleteSound(DieSounds
[b
].ID
);
759 for b
:= 0 to High(Gibs
) do
761 e_DeleteTexture(Gibs
[b
].ID
);
762 e_DeleteTexture(Gibs
[b
].MaskID
);
766 PlayerModelsArray
:= nil;
771 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
773 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
775 FCurrentAnimation
:= Animation
;
777 if (FDirection
= D_LEFT
) and
778 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) and
779 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
781 FAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
782 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
786 FAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
787 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
791 destructor TPlayerModel
.Destroy();
795 for a
:= A_STAND
to A_LAST
do
797 FAnim
[D_LEFT
][a
].Free();
798 FMaskAnim
[D_LEFT
][a
].Free();
799 FAnim
[D_RIGHT
][a
].Free();
800 FMaskAnim
[D_RIGHT
][a
].Free();
806 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
813 if Direction
= D_LEFT
then
816 Mirror
:= M_HORIZONTAL
;
818 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
819 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
821 p
.X
:= IfThen(Direction
= D_LEFT
,
823 64-FLAG_BASEPOINT
.X
);
824 p
.Y
:= FLAG_BASEPOINT
.Y
;
826 FFlagAnim
.DrawEx(X
+IfThen(Direction
= D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
827 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
828 IfThen(FDirection
= D_RIGHT
, FFlagAngle
, -FFlagAngle
));
832 if Direction
= D_RIGHT
then
835 Mirror
:= M_HORIZONTAL
;
838 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
839 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
841 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
844 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
849 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
856 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
857 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
858 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
859 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
860 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
861 0, True, False, Mirror
);
865 if (FDirection
= D_LEFT
) and
866 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
868 FAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
869 FAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
873 FAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
874 FAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
880 if (FDirection
= D_LEFT
) and
881 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
883 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
884 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
888 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
889 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
897 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
899 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
900 Result
:= FAnim
[D_LEFT
][FCurrentAnimation
]
902 Result
:= FAnim
[D_RIGHT
][FCurrentAnimation
];
905 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
907 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
908 Result
:= FMaskAnim
[D_LEFT
][FCurrentAnimation
]
910 Result
:= FMaskAnim
[D_RIGHT
][FCurrentAnimation
];
913 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
915 TempArray
: array of DWORD
;
919 SetLength(TempArray
, 0);
921 if SoundType
= MODELSOUND_PAIN
then
923 if FPainSounds
= nil then Exit
;
925 for a
:= 0 to High(FPainSounds
) do
926 if FPainSounds
[a
].Level
= Level
then
928 SetLength(TempArray
, Length(TempArray
)+1);
929 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
934 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
936 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
937 if FSlopSound
= 1 then
943 if FDieSounds
= nil then Exit
;
945 for a
:= 0 to High(FDieSounds
) do
946 if FDieSounds
[a
].Level
= Level
then
948 SetLength(TempArray
, Length(TempArray
)+1);
949 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
951 if (TempArray
= nil) and (Level
= 5) then
953 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
959 if TempArray
= nil then Exit
;
961 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
966 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
973 procedure TPlayerModel
.SetFire(Fire
: Boolean);
977 if FFire
then FFireCounter
:= FAnim
[D_RIGHT
, A_ATTACK
].Speed
*FAnim
[D_RIGHT
, A_ATTACK
].TotalFrames
978 else FFireCounter
:= 0;
981 procedure TPlayerModel
.SetFlag(Flag
: Byte);
991 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
992 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
996 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
999 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
1001 FCurrentWeapon
:= Weapon
;
1004 procedure TPlayerModel
.Update();
1006 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
1007 FAnim
[D_LEFT
][FCurrentAnimation
].Update
else FAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
1009 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
1010 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
1012 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1014 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;