@@ -222,6 +222,9 @@ namespace REGoth
222
222
223
223
bool CharacterAI::tryPlayTransitionAnimationTo (const bs::String& anim)
224
224
{
225
+ // Cannot play animations if the character has no model yet
226
+ if (!mVisual ->hasVisual ()) return false ;
227
+
225
228
bs::String playingNow = mVisual ->getPlayingAnimationName ();
226
229
auto clipPlayingNow = mVisual ->findAnimationClip (playingNow);
227
230
@@ -499,30 +502,45 @@ namespace REGoth
499
502
500
503
bool CharacterAI::changeWeaponMode (AI::WeaponMode mode)
501
504
{
502
- bs::String stateTarget = AnimationState::constructStateAnimationName (mode, mWalkMode , " " );
503
-
504
- bool wasAllowed = tryPlayTransitionAnimationTo (stateTarget);
505
-
506
- if (wasAllowed)
505
+ if (!mVisual ->hasVisual ())
507
506
{
507
+ // If the model hasn't been set up yet, just make it start in the target mode.
508
+ // This happens on the Stone-Guardians in Gothic 2, which call NPC_SetToFistMode() before
509
+ // calling MDL_SetVisual().
510
+
508
511
mWeaponMode = mode;
509
- }
510
512
511
- if (!wasAllowed)
513
+ return true ;
514
+ }
515
+ else
512
516
{
513
- // FIXME: We're missing some aniAliases, for example, "T_RUN_2_SNEAK" exists,
514
- // and "T_SNEAK_2_RUN" is just the same animation but in reverse. This
515
- // is defined using an aniAlias, which does not seem to be implemented.
516
- auto c = mVisual ->findAnimationClip (stateTarget);
517
+ // Model exists, check if the state transition is possible
517
518
518
- if (c)
519
+ bs::String stateTarget = AnimationState::constructStateAnimationName (mode, mWalkMode , " " );
520
+
521
+ bool wasAllowed = tryPlayTransitionAnimationTo (stateTarget);
522
+
523
+ if (wasAllowed)
519
524
{
520
- mVisual ->playAnimationClip (c);
521
525
mWeaponMode = mode;
522
526
}
523
- }
524
527
525
- return wasAllowed;
528
+ if (!wasAllowed)
529
+ {
530
+ // FIXME: We're missing some aniAliases, for example, "T_RUN_2_SNEAK" exists,
531
+ // and "T_SNEAK_2_RUN" is just the same animation but in reverse. This
532
+ // is defined using an aniAlias, which does not seem to be implemented.
533
+ auto c = mVisual ->findAnimationClip (stateTarget);
534
+
535
+ if (c)
536
+ {
537
+ mVisual ->playAnimationClip (c);
538
+ mWeaponMode = mode;
539
+ }
540
+ }
541
+
542
+ return wasAllowed;
543
+ }
526
544
}
527
545
528
546
void CharacterAI::tryToggleWalking ()
0 commit comments