7 g_textures
, g_basic
, g_weapons
, e_graphics
, wadreader
;
44 TModelSoundArray
= Array of TModelSound
;
45 TGibsArray
= Array of TGibSprite
;
46 TWeaponPoints
= Array [WEAPON_SAW
..WEAPON_SUPERPULEMET
] of
47 Array [A_STAND
..A_PAIN
] of
48 Array [D_LEFT
..D_RIGHT
] of Array of TPoint
;
50 TPlayerModel
= class (TObject
)
53 FDirection
: TDirection
;
55 FCurrentAnimation
: Byte;
56 FAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_PAIN
] of TAnimation
;
57 FMaskAnim
: Array [D_LEFT
..D_RIGHT
] of Array [A_STAND
..A_PAIN
] of TAnimation
;
58 FWeaponPoints
: TWeaponPoints
;
59 FPainSounds
: TModelSoundArray
;
60 FDieSounds
: TModelSoundArray
;
67 FFlagAnim
: TAnimation
;
72 destructor Destroy(); override;
73 procedure ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
74 function GetCurrentAnimation
: TAnimation
;
75 function GetCurrentAnimationMask
: TAnimation
;
76 procedure SetColor(Red
, Green
, Blue
: Byte);
77 procedure SetWeapon(Weapon
: Byte);
78 procedure SetFlag(Flag
: Byte);
79 procedure SetFire(Fire
: Boolean);
80 function PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
82 procedure Draw(X
, Y
: Integer; Alpha
: Byte = 0);
84 property Fire
: Boolean read FFire
;
85 property Direction
: TDirection read FDirection write FDirection
;
86 property Animation
: Byte read FCurrentAnimation
;
87 property Weapon
: Byte read FCurrentWeapon
;
88 property Name
: String read FName
;
89 property Color
: TRGB read FColor write FColor
;
92 procedure g_PlayerModel_LoadData();
93 procedure g_PlayerModel_FreeData();
94 function g_PlayerModel_Load(FileName
: String): Boolean;
95 function g_PlayerModel_GetNames(): SArray
;
96 function g_PlayerModel_GetInfo(ModelName
: String): TModelInfo
;
97 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
98 function g_PlayerModel_GetAnim(ModelName
: String; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
99 function g_PlayerModel_GetGibs(ModelName
: String; var Gibs
: TGibsArray
): Boolean;
104 g_main
, g_sound
, g_console
, SysUtils
, g_player
, CONFIG
,
105 GL
, GLExt
, e_sound
, g_options
, g_map
, Math
, e_log
;
108 TPlayerModelInfo
= record
110 ModelSpeed
: Array [A_STAND
..A_PAIN
] of Byte;
113 WeaponPoints
: TWeaponPoints
;
115 PainSounds
: TModelSoundArray
;
116 DieSounds
: TModelSoundArray
;
128 FLAG_BASEPOINT
: TPoint
= (X
:16; Y
:43);
129 FLAG_DEFPOINT
: TPoint
= (X
:32; Y
:16);
131 WEAPONBASE
: Array [WEAPON_SAW
..WEAPON_SUPERPULEMET
] of TPoint
=
132 ((X
:8; Y
:4), (X
:8; Y
:8), (X
:16; Y
:16), (X
:16; Y
:24),
133 (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16), (X
:24; Y
:24), (X
:16; Y
:16));
135 AnimNames
: Array [A_STAND
..A_PAIN
] of String =
136 ('StandAnim','WalkAnim','Die1Anim','Die2Anim','AttackAnim',
137 'SeeUpAnim','SeeDownAnim','AttackUpAnim','AttackDownAnim','PainAnim');
138 WeapNames
: Array [WEAPON_SAW
..WEAPON_SUPERPULEMET
] of String =
139 ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl');
142 WeaponID
: Array [WEAPON_SAW
..WEAPON_SUPERPULEMET
] of
143 Array [W_POS_NORMAL
..W_POS_DOWN
] of
144 Array [W_ACT_NORMAL
..W_ACT_FIRE
] of DWORD
;
145 PlayerModelsArray
: Array of TPlayerModelInfo
;
147 procedure g_PlayerModel_LoadData();
151 for a
:= WEAPON_SAW
to WEAPON_SUPERPULEMET
do
153 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
]));
154 g_Texture_CreateWAD(WeaponID
[a
][W_POS_NORMAL
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_FIRE');
155 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP');
156 g_Texture_CreateWAD(WeaponID
[a
][W_POS_UP
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_UP_FIRE');
157 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_NORMAL
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN');
158 g_Texture_CreateWAD(WeaponID
[a
][W_POS_DOWN
][W_ACT_FIRE
], GameWAD
+':WEAPONS\'+UpperCase(WeapNames
[a
])+'_DN_FIRE');
162 function GetPoint(var str
: String; var point
: TPoint
): Boolean;
172 if Length(str
) < 3 then
175 for a
:= 1 to Length(str
) do
176 if (str
[a
] = ',') or (a
= Length(str
)) then
178 s
:= Copy(str
, 1, a
);
179 if s
[Length(s
)] = ',' then
180 SetLength(s
, Length(s
)-1);
183 if (Sscanf(s
, '%d:%d', [@x
, @y
]) < 2) or
184 (x
< -64) or (x
> 128) or
185 (y
< -64) or (y
> 128) then
197 function GetWeapPoints(str
: String; weapon
: Byte; anim
: Byte; dir
: TDirection
;
198 frames
: Word; backanim
: Boolean; var wpoints
: TWeaponPoints
): Boolean;
207 backanim
:= backanim
and (frames
> 2);
209 for a
:= 1 to frames
do
211 if not GetPoint(str
, wpoints
[weapon
, anim
, dir
, a
-1]) then
214 with wpoints
[weapon
, anim
, dir
, a
-1] do
216 X
:= X
- WEAPONBASE
[weapon
].X
;
217 Y
:= Y
- WEAPONBASE
[weapon
].Y
;
223 h
:= High(wpoints
[weapon
, anim
, dir
]);
225 for b
:= h
downto frames
do
226 wpoints
[weapon
, anim
, dir
, b
] := wpoints
[weapon
, anim
, dir
, h
-b
+1];
231 function g_PlayerModel_Load(FileName
: string): Boolean;
234 a
, b
, len
, aa
, bb
, f
: Integer;
237 pData
, pData2
: Pointer;
243 e_WriteLog(Format('Loading player model: %s', [ExtractFileName(FileName
)]), MSG_NOTIFY
);
247 WAD
:= TWADFile
.Create
;
248 WAD
.ReadFile(FileName
);
250 if {WAD.GetLastError <> DFWAD_NOERROR} not WAD
.isOpen
then
256 if not WAD
.GetResource('TEXT', 'MODEL', pData
, len
) then
262 config
:= TConfig
.CreateMem(pData
, len
);
265 s
:= config
.ReadStr('Model', 'name', '');
273 SetLength(PlayerModelsArray
, Length(PlayerModelsArray
)+1);
274 ID
:= High(PlayerModelsArray
);
276 prefix
:= FileName
+':TEXTURES\';
278 with PlayerModelsArray
[ID
].Info
do
281 Author
:= config
.ReadStr('Model', 'author', '');
282 Description
:= config
.ReadStr('Model', 'description', '');
285 for b
:= A_STAND
to A_PAIN
do
287 if not (g_Frames_CreateWAD(nil, s
+'_RIGHTANIM'+IntToStr(b
),
288 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
289 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
290 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
291 g_Frames_CreateWAD(nil, s
+'_RIGHTANIM'+IntToStr(b
)+'_MASK',
292 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
293 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
294 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
301 for aa
:= WEAPON_SAW
to WEAPON_SUPERPULEMET
do
302 for bb
:= A_STAND
to A_PAIN
do
303 for cc
:= D_LEFT
to D_RIGHT
do
305 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
306 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
307 if f
> 2 then f
:= 2*f
-2;
308 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
311 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
312 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
314 g_Frames_CreateWAD(nil, s
+'_LEFTANIM'+IntToStr(b
),
315 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
316 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
317 config
.ReadBool(AnimNames
[b
], 'backanim', False));
319 g_Frames_CreateWAD(nil, s
+'_LEFTANIM'+IntToStr(b
)+'_MASK',
320 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
321 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
322 config
.ReadBool(AnimNames
[b
], 'backanim', False));
325 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
328 with PlayerModelsArray
[ID
], config
do
330 prefix
:= FileName
+':SOUNDS\';
334 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
337 SetLength(PainSounds
, Length(PainSounds
)+1);
338 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
339 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
346 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
349 SetLength(DieSounds
, Length(DieSounds
)+1);
350 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
351 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
356 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
358 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
361 (WAD
.GetResource('TEXTURES', config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, len
)) and
362 (WAD
.GetResource('TEXTURES', config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, len
)) then
364 for a
:= 0 to High(Gibs
) do
365 if e_CreateTextureMemEx(pData
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
366 e_CreateTextureMemEx(pData2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
368 Gibs
[a
].Rect
:= e_GetTextureSize2(Gibs
[a
].ID
);
370 if Height
> 3 then Height
:= Height
-1-Random(2);
371 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
379 for aa
:= WEAPON_SAW
to WEAPON_SUPERPULEMET
do
380 for bb
:= A_STAND
to A_PAIN
do
381 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
383 ok
:= ok
and GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, D_RIGHT
,
384 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
385 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
388 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, D_LEFT
,
389 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
390 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
392 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
394 WeaponPoints
[aa
, bb
, D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
;
395 WeaponPoints
[aa
, bb
, D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
;
398 if not ok
then Break
;
400 {if ok then g_Console_Add(Info.Name+' weapon points ok')
401 else g_Console_Add(Info.Name+' weapon points fail');}
402 Info
.HaveWeapon
:= ok
;
404 s
:= config
.ReadStr('Model', 'flag_point', '');
405 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
407 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
416 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
424 if PlayerModelsArray
= nil then Exit
;
426 for a
:= 0 to High(PlayerModelsArray
) do
427 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
429 Result
:= TPlayerModel
.Create
;
431 with PlayerModelsArray
[a
] do
433 Result
.FName
:= Info
.Name
;
435 for b
:= A_STAND
to A_PAIN
do
437 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
438 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
445 Result
.FAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
447 Result
.FMaskAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
449 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
450 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
451 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
452 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
454 Result
.FAnim
[D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
456 Result
.FMaskAnim
[D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
459 Result
.FPainSounds
:= PainSounds
;
460 Result
.FDieSounds
:= DieSounds
;
461 Result
.FSlopSound
:= SlopSound
;
464 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
465 Result
.FWeaponPoints
:= WeaponPoints
;
467 Result
.FFlagPoint
:= FlagPoint
;
468 Result
.FFlagAngle
:= FlagAngle
;
475 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
483 if PlayerModelsArray
= nil then Exit
;
484 for a
:= 0 to High(PlayerModelsArray
) do
485 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
486 with PlayerModelsArray
[a
] do
488 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
490 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
491 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
493 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
494 _Anim
.Speed
:= ModelSpeed
[Anim
];
496 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
497 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
499 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
500 _Mask
.Speed
:= ModelSpeed
[Anim
];
508 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
515 if PlayerModelsArray
= nil then Exit
;
516 if gGibsCount
= 0 then Exit
;
520 SetLength(Gibs
, gGibsCount
);
522 for a
:= 0 to High(PlayerModelsArray
) do
523 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
525 for i
:= 0 to High(Gibs
) do
527 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
534 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
535 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
537 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
539 if Gibs
[i
].OnlyOne
then c
:= True;
547 function g_PlayerModel_GetNames(): SArray
;
553 if PlayerModelsArray
= nil then Exit
;
555 for i
:= 0 to High(PlayerModelsArray
) do
557 SetLength(Result
, Length(Result
)+1);
558 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
562 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
566 FillChar(Result
, SizeOf(Result
), 0);
567 if PlayerModelsArray
= nil then Exit
;
569 for a
:= 0 to High(PlayerModelsArray
) do
570 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
572 Result
:= PlayerModelsArray
[a
].Info
;
577 procedure g_PlayerModel_FreeData();
582 for a
:= WEAPON_SAW
to WEAPON_SUPERPULEMET
do
583 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
584 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
585 e_DeleteTexture(WeaponID
[a
][b
][c
]);
587 e_WriteLog('Releasing models...', MSG_NOTIFY
);
589 if PlayerModelsArray
= nil then Exit
;
591 for i
:= 0 to High(PlayerModelsArray
) do
592 with PlayerModelsArray
[i
] do
594 for a
:= A_STAND
to A_PAIN
do
596 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
597 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
598 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
599 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
602 if PainSounds
<> nil then
603 for b
:= 0 to High(PainSounds
) do
604 e_DeleteSound(PainSounds
[b
].ID
);
606 if DieSounds
<> nil then
607 for b
:= 0 to High(DieSounds
) do
608 e_DeleteSound(DieSounds
[b
].ID
);
611 for b
:= 0 to High(Gibs
) do
613 e_DeleteTexture(Gibs
[b
].ID
);
614 e_DeleteTexture(Gibs
[b
].MaskID
);
618 PlayerModelsArray
:= nil;
623 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
625 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
627 FCurrentAnimation
:= Animation
;
629 if (FDirection
= D_LEFT
) and
630 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) and
631 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
633 FAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
634 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
638 FAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
639 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
643 destructor TPlayerModel
.Destroy();
647 for a
:= A_STAND
to A_PAIN
do
649 FAnim
[D_LEFT
][a
].Free();
650 FMaskAnim
[D_LEFT
][a
].Free();
651 FAnim
[D_RIGHT
][a
].Free();
652 FMaskAnim
[D_RIGHT
][a
].Free();
658 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
665 if Direction
= D_LEFT
then
668 Mirror
:= M_HORIZONTAL
;
670 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
671 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
673 p
.X
:= IfThen(Direction
= D_LEFT
,
675 64-FLAG_BASEPOINT
.X
);
676 p
.Y
:= FLAG_BASEPOINT
.Y
;
678 FFlagAnim
.DrawEx(X
+IfThen(Direction
= D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
679 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
680 IfThen(FDirection
= D_RIGHT
, FFlagAngle
, -FFlagAngle
));
684 if Direction
= D_RIGHT
then
687 Mirror
:= M_HORIZONTAL
;
690 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
691 (FCurrentWeapon
in [WEAPON_SAW
..WEAPON_SUPERPULEMET
]) then
693 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
696 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
701 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
708 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
709 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
710 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
711 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
712 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
713 0, True, False, Mirror
);
717 if (FDirection
= D_LEFT
) and
718 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
720 FAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
721 FAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
725 FAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
726 FAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
732 if (FDirection
= D_LEFT
) and
733 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
735 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
736 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
740 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
741 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
749 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
751 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
752 Result
:= FAnim
[D_LEFT
][FCurrentAnimation
]
754 Result
:= FAnim
[D_RIGHT
][FCurrentAnimation
];
757 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
759 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
760 Result
:= FMaskAnim
[D_LEFT
][FCurrentAnimation
]
762 Result
:= FMaskAnim
[D_RIGHT
][FCurrentAnimation
];
765 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
767 TempArray
: array of DWORD
;
771 SetLength(TempArray
, 0);
773 if SoundType
= MODELSOUND_PAIN
then
775 if FPainSounds
= nil then Exit
;
777 for a
:= 0 to High(FPainSounds
) do
778 if FPainSounds
[a
].Level
= Level
then
780 SetLength(TempArray
, Length(TempArray
)+1);
781 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
786 if (Level
in [2, 3]) and (FSlopSound
> 0) then
788 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
789 if FSlopSound
= 1 then
795 if FDieSounds
= nil then Exit
;
797 for a
:= 0 to High(FDieSounds
) do
798 if FDieSounds
[a
].Level
= Level
then
800 SetLength(TempArray
, Length(TempArray
)+1);
801 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
805 if TempArray
= nil then Exit
;
807 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
812 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
819 procedure TPlayerModel
.SetFire(Fire
: Boolean);
823 if FFire
then FFireCounter
:= FAnim
[D_RIGHT
, A_ATTACK
].Speed
*FAnim
[D_RIGHT
, A_ATTACK
].TotalFrames
824 else FFireCounter
:= 0;
827 procedure TPlayerModel
.SetFlag(Flag
: Byte);
837 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
838 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
842 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
845 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
847 FCurrentWeapon
:= Weapon
;
850 procedure TPlayerModel
.Update();
852 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
853 FAnim
[D_LEFT
][FCurrentAnimation
].Update
else FAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
855 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
856 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
858 if FFlagAnim
<> nil then FFlagAnim
.Update
;
860 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;