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 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 TPoint
;
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
: TPoint
= (X
:16; Y
:43);
162 FLAG_DEFPOINT
: TPoint
= (X
:32; Y
:16);
164 WEAPONBASE
: Array [WP_FIRST
+ 1..WP_LAST
] of TPoint
=
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
: TPoint
): 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 if not (g_Frames_CreateWAD(nil, aname
,
372 prefix
+config
.ReadStr(AnimNames
[b
], 'resource', ''),
373 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
374 config
.ReadBool(AnimNames
[b
], 'backanim', False)) and
375 g_Frames_CreateWAD(nil, aname
+'_MASK',
376 prefix
+config
.ReadStr(AnimNames
[b
], 'mask', ''),
377 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
378 config
.ReadBool(AnimNames
[b
], 'backanim', False))) then
380 if b
<= A_LASTBASE
then
388 ExtAnimFromBaseAnim(s
, b
);
393 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
394 for bb
:= A_STAND
to A_LAST
do
395 for cc
:= D_LEFT
to D_RIGHT
do
397 f
:= config
.ReadInt(AnimNames
[bb
], 'frames', 1);
398 if config
.ReadBool(AnimNames
[bb
], 'backanim', False) then
399 if f
> 2 then f
:= 2*f
-2;
400 SetLength(PlayerModelsArray
[ID
].WeaponPoints
[aa
, bb
, cc
], f
);
403 if (config
.ReadStr(AnimNames
[b
], 'resource2', '') <> '') and
404 (config
.ReadStr(AnimNames
[b
], 'mask2', '') <> '') then
406 aname
:= s
+'_LEFTANIM'+IntToStr(b
);
407 g_Frames_CreateWAD(nil, aname
,
408 prefix
+config
.ReadStr(AnimNames
[b
], 'resource2', ''),
409 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
410 config
.ReadBool(AnimNames
[b
], 'backanim', False));
412 g_Frames_CreateWAD(nil, aname
+'_MASK',
413 prefix
+config
.ReadStr(AnimNames
[b
], 'mask2', ''),
414 64, 64, config
.ReadInt(AnimNames
[b
], 'frames', 1),
415 config
.ReadBool(AnimNames
[b
], 'backanim', False));
418 PlayerModelsArray
[ID
].ModelSpeed
[b
] := Max(1, config
.ReadInt(AnimNames
[b
], 'waitcount', 1) div 3);
421 with PlayerModelsArray
[ID
], config
do
423 prefix
:= FileName
+':SOUNDS\';
427 s
:= config
.ReadStr('Sound', 'pain'+IntToStr(a
), '');
430 SetLength(PainSounds
, Length(PainSounds
)+1);
431 g_Sound_CreateWAD(PainSounds
[High(PainSounds
)].ID
, prefix
+s
);
432 PainSounds
[High(PainSounds
)].Level
:= config
.ReadInt('Sound', 'painlevel'+IntToStr(a
), 1);
439 s
:= config
.ReadStr('Sound', 'die'+IntToStr(a
), '');
442 SetLength(DieSounds
, Length(DieSounds
)+1);
443 g_Sound_CreateWAD(DieSounds
[High(DieSounds
)].ID
, prefix
+s
);
444 DieSounds
[High(DieSounds
)].Level
:= config
.ReadInt('Sound', 'dielevel'+IntToStr(a
), 1);
449 SlopSound
:= Min(Max(config
.ReadInt('Sound', 'slop', 0), 0), 2);
451 SetLength(Gibs
, ReadInt('Gibs', 'count', 0));
454 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'resource', 'GIBS'), pData
, lenpd
)) and
455 (WAD
.GetResource('TEXTURES/'+config
.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2
, lenpd2
)) then
457 for a
:= 0 to High(Gibs
) do
458 if e_CreateTextureMemEx(pData
, lenpd
, Gibs
[a
].ID
, a
*32, 0, 32, 32) and
459 e_CreateTextureMemEx(pData2
, lenpd2
, Gibs
[a
].MaskID
, a
*32, 0, 32, 32) then
461 Gibs
[a
].Rect
:= e_GetTextureSize2(Gibs
[a
].ID
);
463 if Height
> 3 then Height
:= Height
-1-Random(2);
464 Gibs
[a
].OnlyOne
:= config
.ReadInt('Gibs', 'once', -1) = a
+1;
472 for aa
:= WP_FIRST
+ 1 to WP_LAST
do
473 for bb
:= A_STAND
to A_LAST
do
474 if not (bb
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
476 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'_points', ''), aa
, bb
, D_RIGHT
,
477 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
478 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
480 if ok
and (not chk
) and (aa
= WEAPON_FLAMETHROWER
) then
482 // workaround for flamethrower
483 chk
:= GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[WEAPON_PLASMA
]+'_points', ''), aa
, bb
, D_RIGHT
,
484 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
485 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
488 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
493 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
494 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
496 A_WALKATTACK
, A_WALK
:
498 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 9);
499 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 9);
503 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
504 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 8);
506 A_WALKSEEUP
, A_SEEUP
:
508 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
509 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
511 A_WALKSEEDOWN
, A_SEEDOWN
:
513 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
514 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 5);
516 A_WALKATTACKUP
, A_ATTACKUP
:
518 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 5);
519 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 16);
521 A_WALKATTACKDOWN
, A_ATTACKDOWN
:
523 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
, 6);
524 Dec(WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
, 4);
529 ok
:= ok
and (chk
or (bb
> A_LASTBASE
));
531 if not GetWeapPoints(config
.ReadStr(AnimNames
[bb
], WeapNames
[aa
]+'2_points', ''), aa
, bb
, D_LEFT
,
532 config
.ReadInt(AnimNames
[bb
], 'frames', 0),
533 config
.ReadBool(AnimNames
[bb
], 'backanim', False),
535 for f
:= 0 to High(WeaponPoints
[aa
, bb
, D_RIGHT
]) do
537 WeaponPoints
[aa
, bb
, D_LEFT
, f
].X
:= -WeaponPoints
[aa
, bb
, D_RIGHT
, f
].X
;
538 WeaponPoints
[aa
, bb
, D_LEFT
, f
].Y
:= WeaponPoints
[aa
, bb
, D_RIGHT
, f
].Y
;
541 if not ok
then Break
;
543 {if ok then g_Console_Add(Info.Name+' weapon points ok')
544 else g_Console_Add(Info.Name+' weapon points fail');}
545 Info
.HaveWeapon
:= ok
;
547 s
:= config
.ReadStr('Model', 'flag_point', '');
548 if not GetPoint(s
, FlagPoint
) then FlagPoint
:= FLAG_DEFPOINT
;
550 FlagAngle
:= config
.ReadInt('Model', 'flag_angle', FLAG_DEFANGLE
);
559 function g_PlayerModel_Get(ModelName
: String): TPlayerModel
;
567 if PlayerModelsArray
= nil then Exit
;
569 for a
:= 0 to High(PlayerModelsArray
) do
570 if AnsiLowerCase(PlayerModelsArray
[a
].Info
.Name
) = AnsiLowerCase(ModelName
) then
572 Result
:= TPlayerModel
.Create
;
574 with PlayerModelsArray
[a
] do
576 Result
.FName
:= Info
.Name
;
578 for b
:= A_STAND
to A_LAST
do
580 if not (g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)) and
581 g_Frames_Get(ID2
, Info
.Name
+'_RIGHTANIM'+IntToStr(b
)+'_MASK')) then
588 Result
.FAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
590 Result
.FMaskAnim
[D_RIGHT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
592 if g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
593 g_Frames_Exists(Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
594 if g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)) and
595 g_Frames_Get(ID2
, Info
.Name
+'_LEFTANIM'+IntToStr(b
)+'_MASK') then
597 Result
.FAnim
[D_LEFT
][b
] := TAnimation
.Create(ID
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
599 Result
.FMaskAnim
[D_LEFT
][b
] := TAnimation
.Create(ID2
, b
in [A_STAND
, A_WALK
], ModelSpeed
[b
]);
603 Result
.FPainSounds
:= PainSounds
;
604 Result
.FDieSounds
:= DieSounds
;
605 Result
.FSlopSound
:= SlopSound
;
606 Result
.FDrawWeapon
:= Info
.HaveWeapon
;
607 Result
.FWeaponPoints
:= WeaponPoints
;
609 Result
.FFlagPoint
:= FlagPoint
;
610 Result
.FFlagAngle
:= FlagAngle
;
617 function g_PlayerModel_GetAnim(ModelName
: string; Anim
: Byte; var _Anim
, _Mask
: TAnimation
): Boolean;
625 if PlayerModelsArray
= nil then Exit
;
626 for a
:= 0 to High(PlayerModelsArray
) do
627 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
628 with PlayerModelsArray
[a
] do
630 if Anim
in [A_STAND
, A_WALK
] then c
:= True else c
:= False;
632 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)) then
633 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)) then Exit
;
635 _Anim
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
636 _Anim
.Speed
:= ModelSpeed
[Anim
];
638 if not g_Frames_Get(ID
, Info
.Name
+'_RIGHTANIM'+IntToStr(Anim
)+'_MASK') then
639 if not g_Frames_Get(ID
, Info
.Name
+'_LEFTANIM'+IntToStr(Anim
)+'_MASK') then Exit
;
641 _Mask
:= TAnimation
.Create(ID
, c
, ModelSpeed
[Anim
]);
642 _Mask
.Speed
:= ModelSpeed
[Anim
];
650 function g_PlayerModel_GetGibs(ModelName
: string; var Gibs
: TGibsArray
): Boolean;
657 if PlayerModelsArray
= nil then Exit
;
658 if gGibsCount
= 0 then Exit
;
662 SetLength(Gibs
, gGibsCount
);
664 for a
:= 0 to High(PlayerModelsArray
) do
665 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
667 for i
:= 0 to High(Gibs
) do
669 if c
and (Length(PlayerModelsArray
[a
].Gibs
) = 1) then
676 b
:= Random(Length(PlayerModelsArray
[a
].Gibs
));
677 until not (PlayerModelsArray
[a
].Gibs
[b
].OnlyOne
and c
);
679 Gibs
[i
] := PlayerModelsArray
[a
].Gibs
[b
];
681 if Gibs
[i
].OnlyOne
then c
:= True;
689 function g_PlayerModel_GetNames(): SArray
;
695 if PlayerModelsArray
= nil then Exit
;
697 for i
:= 0 to High(PlayerModelsArray
) do
699 SetLength(Result
, Length(Result
)+1);
700 Result
[High(Result
)] := PlayerModelsArray
[i
].Info
.Name
;
704 function g_PlayerModel_GetInfo(ModelName
: string): TModelInfo
;
708 FillChar(Result
, SizeOf(Result
), 0);
709 if PlayerModelsArray
= nil then Exit
;
711 for a
:= 0 to High(PlayerModelsArray
) do
712 if PlayerModelsArray
[a
].Info
.Name
= ModelName
then
714 Result
:= PlayerModelsArray
[a
].Info
;
719 procedure g_PlayerModel_FreeData();
724 for a
:= WP_FIRST
+ 1 to WP_LAST
do
725 for b
:= W_POS_NORMAL
to W_POS_DOWN
do
726 for c
:= W_ACT_NORMAL
to W_ACT_FIRE
do
727 e_DeleteTexture(WeaponID
[a
][b
][c
]);
729 e_WriteLog('Releasing models...', MSG_NOTIFY
);
731 if PlayerModelsArray
= nil then Exit
;
733 for i
:= 0 to High(PlayerModelsArray
) do
734 with PlayerModelsArray
[i
] do
736 for a
:= A_STAND
to A_LAST
do
738 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
));
739 g_Frames_DeleteByName(Info
.Name
+'_LEFTANIM'+IntToStr(a
)+'_MASK');
740 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
));
741 g_Frames_DeleteByName(Info
.Name
+'_RIGHTANIM'+IntToStr(a
)+'_MASK');
744 if PainSounds
<> nil then
745 for b
:= 0 to High(PainSounds
) do
746 e_DeleteSound(PainSounds
[b
].ID
);
748 if DieSounds
<> nil then
749 for b
:= 0 to High(DieSounds
) do
750 e_DeleteSound(DieSounds
[b
].ID
);
753 for b
:= 0 to High(Gibs
) do
755 e_DeleteTexture(Gibs
[b
].ID
);
756 e_DeleteTexture(Gibs
[b
].MaskID
);
760 PlayerModelsArray
:= nil;
765 procedure TPlayerModel
.ChangeAnimation(Animation
: Byte; Force
: Boolean = False);
767 if not Force
then if FCurrentAnimation
= Animation
then Exit
;
769 FCurrentAnimation
:= Animation
;
771 if (FDirection
= D_LEFT
) and
772 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) and
773 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
775 FAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
776 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Reset
;
780 FAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
781 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Reset
;
785 destructor TPlayerModel
.Destroy();
789 for a
:= A_STAND
to A_LAST
do
791 FAnim
[D_LEFT
][a
].Free();
792 FMaskAnim
[D_LEFT
][a
].Free();
793 FAnim
[D_RIGHT
][a
].Free();
794 FMaskAnim
[D_RIGHT
][a
].Free();
800 procedure TPlayerModel
.Draw(X
, Y
: Integer; Alpha
: Byte = 0);
807 if Direction
= D_LEFT
then
810 Mirror
:= M_HORIZONTAL
;
812 if (FFlag
<> FLAG_NONE
) and (FFlagAnim
<> nil) and
813 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
])) then
815 p
.X
:= IfThen(Direction
= D_LEFT
,
817 64-FLAG_BASEPOINT
.X
);
818 p
.Y
:= FLAG_BASEPOINT
.Y
;
820 FFlagAnim
.DrawEx(X
+IfThen(Direction
= D_LEFT
, FFlagPoint
.X
-1, 2*FLAG_BASEPOINT
.X
-FFlagPoint
.X
+1)-FLAG_BASEPOINT
.X
,
821 Y
+FFlagPoint
.Y
-FLAG_BASEPOINT
.Y
+1, Mirror
, p
,
822 IfThen(FDirection
= D_RIGHT
, FFlagAngle
, -FFlagAngle
));
826 if Direction
= D_RIGHT
then
829 Mirror
:= M_HORIZONTAL
;
832 (not (FCurrentAnimation
in [A_DIE1
, A_DIE2
, A_PAIN
])) and
833 (FCurrentWeapon
in [WP_FIRST
+ 1..WP_LAST
]) then
835 if FCurrentAnimation
in [A_SEEUP
, A_ATTACKUP
] then
838 if FCurrentAnimation
in [A_SEEDOWN
, A_ATTACKDOWN
] then
843 if (FCurrentAnimation
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or
850 e_Draw(WeaponID
[FCurrentWeapon
][pos
][act
],
851 X
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
852 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].X
,
853 Y
+FWeaponPoints
[FCurrentWeapon
, FCurrentAnimation
, FDirection
,
854 FAnim
[D_RIGHT
][FCurrentAnimation
].CurrentFrame
].Y
,
855 0, True, False, Mirror
);
859 if (FDirection
= D_LEFT
) and
860 (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
862 FAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
863 FAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
867 FAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
868 FAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
874 if (FDirection
= D_LEFT
) and
875 (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
877 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Alpha
:= Alpha
;
878 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Draw(X
, Y
, M_NONE
);
882 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Alpha
:= Alpha
;
883 FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Draw(X
, Y
, Mirror
);
891 function TPlayerModel
.GetCurrentAnimation
: TAnimation
;
893 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
894 Result
:= FAnim
[D_LEFT
][FCurrentAnimation
]
896 Result
:= FAnim
[D_RIGHT
][FCurrentAnimation
];
899 function TPlayerModel
.GetCurrentAnimationMask
: TAnimation
;
901 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
902 Result
:= FMaskAnim
[D_LEFT
][FCurrentAnimation
]
904 Result
:= FMaskAnim
[D_RIGHT
][FCurrentAnimation
];
907 function TPlayerModel
.PlaySound(SoundType
, Level
: Byte; X
, Y
: Integer): Boolean;
909 TempArray
: array of DWORD
;
913 SetLength(TempArray
, 0);
915 if SoundType
= MODELSOUND_PAIN
then
917 if FPainSounds
= nil then Exit
;
919 for a
:= 0 to High(FPainSounds
) do
920 if FPainSounds
[a
].Level
= Level
then
922 SetLength(TempArray
, Length(TempArray
)+1);
923 TempArray
[High(TempArray
)] := FPainSounds
[a
].ID
;
928 if (Level
in [2, 3, 5]) and (FSlopSound
> 0) then
930 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
931 if FSlopSound
= 1 then
937 if FDieSounds
= nil then Exit
;
939 for a
:= 0 to High(FDieSounds
) do
940 if FDieSounds
[a
].Level
= Level
then
942 SetLength(TempArray
, Length(TempArray
)+1);
943 TempArray
[High(TempArray
)] := FDieSounds
[a
].ID
;
945 if (TempArray
= nil) and (Level
= 5) then
947 g_Sound_PlayExAt('SOUND_MONSTER_SLOP', X
, Y
);
953 if TempArray
= nil then Exit
;
955 g_Sound_PlayAt(TempArray
[Random(Length(TempArray
))], X
, Y
);
960 procedure TPlayerModel
.SetColor(Red
, Green
, Blue
: Byte);
967 procedure TPlayerModel
.SetFire(Fire
: Boolean);
971 if FFire
then FFireCounter
:= FAnim
[D_RIGHT
, A_ATTACK
].Speed
*FAnim
[D_RIGHT
, A_ATTACK
].TotalFrames
972 else FFireCounter
:= 0;
975 procedure TPlayerModel
.SetFlag(Flag
: Byte);
985 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
986 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
990 FFlagAnim
:= TAnimation
.Create(id
, True, 8);
993 procedure TPlayerModel
.SetWeapon(Weapon
: Byte);
995 FCurrentWeapon
:= Weapon
;
998 procedure TPlayerModel
.Update();
1000 if (FDirection
= D_LEFT
) and (FAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
1001 FAnim
[D_LEFT
][FCurrentAnimation
].Update
else FAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
1003 if (FDirection
= D_LEFT
) and (FMaskAnim
[D_LEFT
][FCurrentAnimation
] <> nil) then
1004 FMaskAnim
[D_LEFT
][FCurrentAnimation
].Update
else FMaskAnim
[D_RIGHT
][FCurrentAnimation
].Update
;
1006 if FFlagAnim
<> nil then FFlagAnim
.Update
;
1008 if FFireCounter
> 0 then Dec(FFireCounter
) else FFire
:= False;