From 665917e0434a567d910de1c3e9b39495fce5ef29 Mon Sep 17 00:00:00 2001 From: Flugente Date: Sun, 16 Sep 2012 15:13:05 +0000 Subject: [PATCH] fix: sometimes, wrong clothes were taken off git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5568 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Items.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 2c857f209..da6bd4ebf 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -14652,6 +14652,11 @@ BOOLEAN GetFirstClothesItemWithSpecificData( UINT16* pusItem, PaletteRepID aPalV if ( !GetPaletteRepIndexFromID(aPalPants, &filler) ) pantsok = TRUE; + // getting the best item isn't straightforward. As combo clothes can be found first, we will search for each item whose clothestype matches, and retreive the loest item that has + // the lowest clothestype + UINT32 bestclothestype = 999999; + UINT16 bestitem = 0; + register UINT16 i; for (i = 1; i < MAXITEMS; ++i) { @@ -14682,12 +14687,21 @@ BOOLEAN GetFirstClothesItemWithSpecificData( UINT16* pusItem, PaletteRepID aPalV } if ( tmpvestok && tmppantsok ) - { - *pusItem = i; - return( TRUE ); + { + if ( Item[i].clothestype < bestclothestype ) + { + bestclothestype = Item[i].clothestype; + bestitem = i; + } } } } + if ( bestitem > 0 ) + { + *pusItem = bestitem; + return( TRUE ); + } + return( FALSE ); }