@@ -5153,8 +5153,10 @@ func (vi *MotifVictory) clear(m *Motif) {
51535153 vi .clearProps (& m .VictoryScreen .P8 )
51545154}
51555155
5156- func (vi * MotifVictory ) getVictoryQuote (m * Motif ) string {
5157- p := sys .chars [sys .winnerTeam ()- 1 ][0 ]
5156+ func (vi * MotifVictory ) getVictoryQuote (m * Motif , p * Char ) string {
5157+ if p == nil || p .playerNo < 0 || p .playerNo >= len (sys .cgi ) {
5158+ return m .VictoryScreen .WinQuote .Text
5159+ }
51585160 quoteIndex := int (p .winquote )
51595161 playerQuotes := sys .cgi [p .playerNo ].quotes
51605162
@@ -5377,7 +5379,11 @@ func (vi *MotifVictory) init(m *Motif) {
53775379 vi .applyEntry (m , lSlots [i ], lEntries [i ], lNames [i ])
53785380 }
53795381
5380- vi .text = vi .getVictoryQuote (m )
5382+ var leader * Char
5383+ if len (wEntries ) > 0 {
5384+ leader = wEntries [0 ].c
5385+ }
5386+ vi .text = vi .getVictoryQuote (m , leader )
53815387 m .VictoryBgDef .BGDef .Reset ()
53825388
53835389 //fmt.Printf("[Victory] init done. Winners=%d entries, Losers=%d entries. WinQuote=%q\n", len(wEntries), len(lEntries), vi.text)
@@ -5578,11 +5584,10 @@ func victoryPortraitAnim(m *Motif, sc *SelectChar, slot string,
55785584
55795585 //fmt.Printf("[Victory] buildPortrait slot=%s scNil=%v animNo=%d spr=(%d,%d) pos=(%.1f,%.1f) scale=(%.3f,%.3f) localcoord=(%d,%d) window=(%d,%d,%d,%d) applyPal=%v pal=%d\n", slot, sc == nil, animNo, spr[0], spr[1], x, y, scale[0], scale[1], localcoord[0], localcoord[1], window[0], window[1], window[2], window[3], applyPal, pal)
55805586
5581- if sc == nil {
5582- return nil
5583- }
5587+ a := NewAnim (nil , "" )
5588+
55845589 var animCopy * Animation
5585- if animNo >= 0 {
5590+ if sc != nil && animNo >= 0 {
55865591 // First: explicit animation number
55875592 animCopy = sc .anims .get (animNo , - 1 )
55885593 if animCopy == nil {
@@ -5592,7 +5597,7 @@ func victoryPortraitAnim(m *Motif, sc *SelectChar, slot string,
55925597 //fmt.Printf("[Victory] slot=%s -> fallback from anim %d to %s\n", slot, animNo/*, from*/)
55935598 }
55945599 }
5595- } else if spr [0 ] >= 0 {
5600+ } else if sc != nil && spr [0 ] >= 0 {
55965601 // Try requested (grp,idx) first (preloaded or SFF-build), then fall back to 9000,1
55975602 want := [][2 ]int32 {{spr [0 ], spr [1 ]}, {9000 , 1 } /*, {9000, 0}*/ }
55985603 if a , _ /*from*/ := tryGetPortrait (sc , ownerC , want ); a != nil {
@@ -5608,8 +5613,6 @@ func victoryPortraitAnim(m *Motif, sc *SelectChar, slot string,
56085613 }
56095614 }
56105615 }
5611- // Always return a non-nil *Anim. If we couldn't resolve a real anim, fall back to a safe dummy created by NewAnim.
5612- a := NewAnim (nil , "" )
56135616 if animCopy != nil {
56145617 a .anim = animCopy
56155618 } else {
@@ -5632,15 +5635,20 @@ func victoryPortraitAnim(m *Motif, sc *SelectChar, slot string,
56325635 // Position
56335636 a .SetPos (x , y )
56345637 // Scale: include character portraitscale and coord conversion similar to hiscore
5635- sx := scale [0 ] * sc .portraitscale * float32 (sys .motif .Info .Localcoord [0 ]) / sc .localcoord [0 ]
5636- sy := scale [1 ] * sc .portraitscale * float32 (sys .motif .Info .Localcoord [0 ]) / sc .localcoord [0 ]
5638+ sx , sy := scale [0 ], scale [1 ]
5639+ // Only apply SelectChar scaling if sc is present and has valid localcoord.
5640+ if sc != nil && sc .localcoord [0 ] > 0 {
5641+ base := float32 (sys .motif .Info .Localcoord [0 ]) / sc .localcoord [0 ]
5642+ sx = scale [0 ] * sc .portraitscale * base
5643+ sy = scale [1 ] * sc .portraitscale * base
5644+ }
56375645 a .SetScale (sx , sy )
56385646 a .facing = float32 (facing )
56395647 if sx == 0 || sy == 0 {
56405648 //fmt.Printf("[Victory] slot=%s -> WARNING: zero scale sx=%.4f sy=%.4f (check portraitscale/localcoord)\n", slot, sx, sy)
56415649 }
56425650 // Palette for non-loaded (or force-apply if requested)
5643- if applyPal && pal > 0 && a .anim .sff != nil {
5651+ if applyPal && pal > 0 && a .anim != nil && a . anim .sff != nil {
56445652 if len (a .anim .sff .palList .paletteMap ) > 0 {
56455653 a .anim .sff .palList .paletteMap [0 ] = pal - 1
56465654 }
0 commit comments