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/>.
22 g_textures
, g_basic
, g_weapons
, e_graphics
, wadreader
;
59 TModelSoundArray
= Array of TModelSound
;
60 TGibsArray
= Array of TGibSprite
;
61 TWeaponPoints
= Array [WP_FIRST
+ 1..WP_LAST
] of
62 Array [A_STAND
..A_PAIN
] of
63 Array [D_LEFT
..D_RIGHT
] of Array of TPoint
;
65 TPlayerModel
= class (TObject
)
68 FDirection
: TDirection
;
70 FCurrentAnimation
: Byte;
71 FAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_PAIN
] of TAnimation
;
72 FMaskAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_PAIN
] of TAnimation
;
73 FWeaponPoints
: TWeaponPoints
;
74 FPainSounds
: TModelSoundArray
;
75 FDieSounds
: TModelSoundArray
;
82 FFlagAnim
: TAnimation
;
87 destructor Destroy(); override;
88 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
89 function GetCurrentAnimation
: TAnimation
;
90 function GetCurrentAnimationMask
: TAnimation
;
91 procedure SetColor(Red
, Green
, Blue
: Byte);
92 procedure SetWeapon(Weapon
: Byte);
93 procedure SetFlag(Flag
: Byte);
94 procedure SetFire(Fire
: Boolean);
95 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
97 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
99 property Fire
: Boolean read FFire
;
100 property Direction
: TDirection read FDirection write FDirection
;
101 property Animation
: Byte read FCurrentAnimation
;
102 property Weapon
: Byte read FCurrentWeapon
;
103 property Name
: String read FName
;
104 property Color
: TRGB read FColor write FColor
;
107 procedure g_PlayerModel_LoadData();
108 procedure g_PlayerModel_FreeData();
109 function g_PlayerModel_Load(FileName
: String): Boolean;
110 function g_PlayerModel_GetNames(): SArray
;
111 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
112 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
113 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
114 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
119 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
120 GL
, GLExt
, e_sound
, g_options
, g_map
, Math
, e_log
;
123 TPlayerModelInfo
= record
125 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
128 WeaponPoints
: TWeaponPoints
;
130 PainSounds
: TModelSoundArray
;
131 DieSounds
: TModelSoundArray
;
143 FLAG_BASEPOINT
: TPoint
= (X
:16; Y
:43);
144 FLAG_DEFPOINT
: TPoint
= (X
:32; Y
:16);
146 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TPoint
=
147 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
148 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24),
149 (X
:16; Y
:16), (X
:8; Y
:8));
151 AnimNames
: Array [A_STAND
..A_PAIN
] of String =
152 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
153 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim');
154 WeapNames
: Array [WP_FIRST
+ 1..WP_LAST
] of String =
155 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
158 WeaponID
: Array [WP_FIRST
+ 1..WP_LAST
] of
159 Array [W_POS_NORMAL
..W_POS_DOWN
] of
160 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
161 PlayerModelsArray
: Array of TPlayerModelInfo
;
163 procedure g_PlayerModel_LoadData();
167 for a
:= WP_FIRST
+ 1 to WP_LAST
do
169 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
170 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
171 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
172 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
173 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
174 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
178 function GetPoint(var str
: String; var point
: TPoint
): Boolean;
188 if Length(str
) < 3 then
191 for a
:= 1 to Length(str
) do
192 if (str
[a
] = ',') or (a
= Length(str
)) then
194 s
:= Copy(str
, 1, a
);
195 if s
[Length(s
)] = ',' then
196 SetLength(s
, Length(s
)-1);
199 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
200 (x
< -64) or (x
> 128) or
201 (y
< -64) or (y
> 128) then
213 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
214 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
223 backanim
:= backanim
and (frames
> 2);
225 for a
:= 1 to frames
do
227 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
230 with wpoints
[weapon
, anim
, dir
, a
-1] do
232 X
:= X
- WEAPONBASE
[weapon
].X
;
233 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
239 h
:= High(wpoints
[weapon
, anim
, dir
]);
241 for b
:= h
downto frames
do
242 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
247 function g_PlayerModel_Load(FileName
: string): Boolean;
250 a
, b
, len
, lenpd
, lenpd2
, aa
, bb
, f
: Integer;
253 pData
, pData2
: Pointer;
259 e_WriteLog(Format('Loading player model: %s', [ExtractFileName(FileName
)]), MSG_NOTIFY
);
263 WAD
:= TWADFile
.Create
;
264 WAD
.ReadFile(FileName
);
266 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
272 if not WAD
.GetResource('TEXT/MODEL', pData
, len
) then
278 config
:= TConfig
.CreateMem(pData
, len
);
281 s
:= config
.ReadStr('Model', 'name', '');
289 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
290 ID
:= High(PlayerModelsArray
);
292 prefix
:= FileName
+':TEXTURES\';
294 with PlayerModelsArray
[ID
].Info
do
297 Author
:= config
.ReadStr('Model', 'author', '');
298 Description
:= config
.ReadStr('Model', 'description', '');
301 for b
:= A_STAND
to A_PAIN
do
303 if not (g_Frames_CreateWAD(nil, s
+'_RIGHTANIM'+IntToStr(b
),
304 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
305 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
306 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
307 g_Frames_CreateWAD(nil, s
+'_RIGHTANIM'+IntToStr(b
)+'_MASK',
308 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
309 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
310 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
317 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
318 for bb
:= A_STAND
to A_PAIN
do
319 for cc
:= D_LEFT
to D_RIGHT
do
321 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
322 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
323 if f
> 2 then f
:= 2*f
-2;
324 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
327 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
328 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
330 g_Frames_CreateWAD(nil, s
+'_LEFTANIM'+IntToStr(b
),
331 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
332 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
333 config
.ReadBool(AnimNames
[b
], 'backanim', False));
335 g_Frames_CreateWAD(nil, s
+'_LEFTANIM'+IntToStr(b
)+'_MASK',
336 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
337 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
338 config
.ReadBool(AnimNames
[b
], 'backanim', False));
341 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
344 with PlayerModelsArray
[ID
], config
do
346 prefix
:= FileName
+':SOUNDS\';
350 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
353 SetLength(PainSounds
, Length(PainSounds
)+1);
354 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
355 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
362 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
365 SetLength(DieSounds
, Length(DieSounds
)+1);
366 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
367 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
372 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
374 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
377 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
378 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
380 for a
:= 0 to High(Gibs
) do
381 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
382 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
384 Gibs
[a
].Rect
:= e_GetTextureSize2(Gibs
[a
].ID
);
386 if Height
> 3 then Height
:= Height
-1-Random(2);
387 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
395 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
396 for bb
:= A_STAND
to A_PAIN
do
397 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
399 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, D_RIGHT
,
400 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
401 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
403 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
405 // workaround for flamethrower
406 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, D_RIGHT
,
407 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
408 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
411 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
416 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
417 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
421 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 9);
422 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 9);
426 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
427 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
431 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
432 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
436 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
437 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 5);
441 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
442 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
446 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
447 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 4);
454 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, D_LEFT
,
455 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
456 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
458 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
460 WeaponPoints
[aa
, bb
, D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
;
461 WeaponPoints
[aa
, bb
, D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
;
464 if not ok
then Break
;
466 {if ok then g_Console_Add(Info.Name+' weapon points ok')
467 else g_Console_Add(Info.Name+' weapon points fail');}
468 Info
.HaveWeapon
:= ok
;
470 s
:= config
.ReadStr('Model', 'flag_point', '');
471 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
473 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
482 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
490 if PlayerModelsArray
= nil then Exit
;
492 for a
:= 0 to High(PlayerModelsArray
) do
493 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
495 Result
:= TPlayerModel
.Create
;
497 with PlayerModelsArray
[a
] do
499 Result
.FName
:= Info
.Name
;
501 for b
:= A_STAND
to A_PAIN
do
503 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
504 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
511 Result
.FAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
513 Result
.FMaskAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
515 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
516 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
517 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
518 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
520 Result
.FAnim
[D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
522 Result
.FMaskAnim
[D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
525 Result
.FPainSounds
:= PainSounds
;
526 Result
.FDieSounds
:= DieSounds
;
527 Result
.FSlopSound
:= SlopSound
;
530 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
531 Result
.FWeaponPoints
:= WeaponPoints
;
533 Result
.FFlagPoint
:= FlagPoint
;
534 Result
.FFlagAngle
:= FlagAngle
;
541 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
549 if PlayerModelsArray
= nil then Exit
;
550 for a
:= 0 to High(PlayerModelsArray
) do
551 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
552 with PlayerModelsArray
[a
] do
554 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
556 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
557 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
559 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
560 _Anim
.Speed
:= ModelSpeed
[Anim
];
562 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
563 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
565 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
566 _Mask
.Speed
:= ModelSpeed
[Anim
];
574 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
581 if PlayerModelsArray
= nil then Exit
;
582 if gGibsCount
= 0 then Exit
;
586 SetLength(Gibs
, gGibsCount
);
588 for a
:= 0 to High(PlayerModelsArray
) do
589 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
591 for i
:= 0 to High(Gibs
) do
593 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
600 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
601 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
603 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
605 if Gibs
[i
].OnlyOne
then c
:= True;
613 function g_PlayerModel_GetNames(): SArray
;
619 if PlayerModelsArray
= nil then Exit
;
621 for i
:= 0 to High(PlayerModelsArray
) do
623 SetLength(Result
, Length(Result
)+1);
624 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
628 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
632 FillChar(Result
, SizeOf(Result
), 0);
633 if PlayerModelsArray
= nil then Exit
;
635 for a
:= 0 to High(PlayerModelsArray
) do
636 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
638 Result
:= PlayerModelsArray
[a
].Info
;
643 procedure g_PlayerModel_FreeData();
648 for a
:= WP_FIRST
+ 1 to WP_LAST
do
649 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
650 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
651 e_DeleteTexture(WeaponID
[a
][b
][c
]);
653 e_WriteLog('Releasing models...', MSG_NOTIFY
);
655 if PlayerModelsArray
= nil then Exit
;
657 for i
:= 0 to High(PlayerModelsArray
) do
658 with PlayerModelsArray
[i
] do
660 for a
:= A_STAND
to A_PAIN
do
662 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
663 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
664 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
665 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
668 if PainSounds
<> nil then
669 for b
:= 0 to High(PainSounds
) do
670 e_DeleteSound(PainSounds
[b
].ID
);
672 if DieSounds
<> nil then
673 for b
:= 0 to High(DieSounds
) do
674 e_DeleteSound(DieSounds
[b
].ID
);
677 for b
:= 0 to High(Gibs
) do
679 e_DeleteTexture(Gibs
[b
].ID
);
680 e_DeleteTexture(Gibs
[b
].MaskID
);
684 PlayerModelsArray
:= nil;
689 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
691 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
693 FCurrentAnimation
:= Animation
;
695 if (FDirection
= D_LEFT
) and
696 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) and
697 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
699 FAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
700 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
704 FAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
705 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
709 destructor TPlayerModel
.Destroy();
713 for a
:= A_STAND
to A_PAIN
do
715 FAnim
[D_LEFT
][a
].Free();
716 FMaskAnim
[D_LEFT
][a
].Free();
717 FAnim
[D_RIGHT
][a
].Free();
718 FMaskAnim
[D_RIGHT
][a
].Free();
724 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
731 if Direction
= D_LEFT
then
734 Mirror
:= M_HORIZONTAL
;
736 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
737 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
739 p
.X
:= IfThen(Direction
= D_LEFT
,
741 64-FLAG_BASEPOINT
.X
);
742 p
.Y
:= FLAG_BASEPOINT
.Y
;
744 FFlagAnim
.DrawEx(X
+IfThen(Direction
= D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
745 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
746 IfThen(FDirection
= D_RIGHT
, FFlagAngle
, -FFlagAngle
));
750 if Direction
= D_RIGHT
then
753 Mirror
:= M_HORIZONTAL
;
756 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
757 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
759 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
762 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
767 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
774 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
775 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
776 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
777 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
778 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
779 0, True, False, Mirror
);
783 if (FDirection
= D_LEFT
) and
784 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
786 FAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
787 FAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
791 FAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
792 FAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
798 if (FDirection
= D_LEFT
) and
799 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
801 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
802 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
806 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
807 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
815 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
817 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
818 Result
:= FAnim
[D_LEFT
][FCurrentAnimation
]
820 Result
:= FAnim
[D_RIGHT
][FCurrentAnimation
];
823 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
825 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
826 Result
:= FMaskAnim
[D_LEFT
][FCurrentAnimation
]
828 Result
:= FMaskAnim
[D_RIGHT
][FCurrentAnimation
];
831 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
833 TempArray
: array of DWORD
;
837 SetLength(TempArray
, 0);
839 if SoundType
= MODELSOUND_PAIN
then
841 if FPainSounds
= nil then Exit
;
843 for a
:= 0 to High(FPainSounds
) do
844 if FPainSounds
[a
].Level
= Level
then
846 SetLength(TempArray
, Length(TempArray
)+1);
847 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
852 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
854 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
855 if FSlopSound
= 1 then
861 if FDieSounds
= nil then Exit
;
863 for a
:= 0 to High(FDieSounds
) do
864 if FDieSounds
[a
].Level
= Level
then
866 SetLength(TempArray
, Length(TempArray
)+1);
867 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
869 if (TempArray
= nil) and (Level
= 5) then
871 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
877 if TempArray
= nil then Exit
;
879 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
884 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
891 procedure TPlayerModel
.SetFire(Fire
: Boolean);
895 if FFire
then FFireCounter
:= FAnim
[D_RIGHT
, A_ATTACK
].Speed
*FAnim
[D_RIGHT
, A_ATTACK
].TotalFrames
896 else FFireCounter
:= 0;
899 procedure TPlayerModel
.SetFlag(Flag
: Byte);
909 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
910 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
914 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
917 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
919 FCurrentWeapon
:= Weapon
;
922 procedure TPlayerModel
.Update();
924 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
925 FAnim
[D_LEFT
][FCurrentAnimation
].Update
else FAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
927 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
928 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
930 if FFlagAnim
<> nil then FFlagAnim
.Update
;
932 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;