From fc49b33398736ba7d19b92a9bd3a21c464cde7d2 Mon Sep 17 00:00:00 2001 From: Flugente Date: Mon, 1 Oct 2012 20:42:55 +0000 Subject: [PATCH] - random items can also be results of merges and item transformations - removed a few instances of incorrect random item spawning git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5598 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Inventory Choosing.cpp | 8 ++++++++ Tactical/Item Types.cpp | 5 ++++- Tactical/Items.cpp | 29 ++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Tactical/Inventory Choosing.cpp b/Tactical/Inventory Choosing.cpp index cd051ba3..ec54f1f7 100644 --- a/Tactical/Inventory Choosing.cpp +++ b/Tactical/Inventory Choosing.cpp @@ -1042,6 +1042,10 @@ void ChooseWeaponForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bWeaponC if ( GetItemFromRandomItem(usGunIndex, &newitemfromrandom) ) usGunIndex = newitemfromrandom; + // if item is still radnom, use default gun -> GLOCK 17 + if ( Item[usGunIndex].randomitem > 0 ) + usGunIndex = GLOCK_17; + //WarmSteel - Removed the attachment check here. why check twice anyway? //Now, we have chosen all of the correct items. Now, we will assign them into the slots. //Because we are dealing with enemies, automatically give them full ammo in their weapon. @@ -3471,6 +3475,10 @@ UINT16 PickARandomItem(UINT8 typeIndex, UINT8 maxCoolness, BOOLEAN getMatchingCo pickItem = TRUE; } } + + // Flugente: if item is still random, don't pick it + if ( Item[usItem].randomitem > 0 ) + pickItem = FALSE; } diff --git a/Tactical/Item Types.cpp b/Tactical/Item Types.cpp index b9661109..4400af8e 100644 --- a/Tactical/Item Types.cpp +++ b/Tactical/Item Types.cpp @@ -1328,10 +1328,13 @@ OBJECTTYPE& OBJECTTYPE::operator=(const OLD_OBJECTTYPE_101& src) } // Flugente: random items - UINT16 newitemfromrandom = 0; + UINT16 newitemfromrandom = NONE; if ( GetItemFromRandomItem(src.usItem, &newitemfromrandom) ) this->usItem = newitemfromrandom; + if ( Item[this->usItem].randomitem > 0 ) + this->usItem = NONE; + //and now the big change, the union //copy the old data, making sure not to write over, since the old size is actually 9 bytes if (ubNumberOfObjects == 1) { diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 37633c69..dd3d73c9 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -2783,13 +2783,24 @@ BOOLEAN EvaluateValidMerge( UINT16 usMerge, UINT16 usItem, UINT16 * pusResult, U } } + // Flugente: for random items, we have to do the resolution here + UINT16 result1 = Merge[iLoop][2]; + UINT16 rdresult1 = 0; + if ( GetItemFromRandomItem(result1, &rdresult1) ) + result1 = rdresult1; + + UINT16 result2 = Merge[iLoop][3]; + UINT16 rdresult2 = 0; + if ( GetItemFromRandomItem(result2, &rdresult2) ) + result2 = rdresult2; + //WarmSteel - Return false if the results aren't valid. - if( !ItemIsLegal(Merge[iLoop][2], TRUE) && !ItemIsLegal(Merge[iLoop][3], TRUE) ){ + if( !ItemIsLegal(result1, TRUE) && !ItemIsLegal(result2, TRUE) ){ return( FALSE ); } - *pusResult = Merge[iLoop][2]; - *pusResult2 = Merge[iLoop][3]; + *pusResult = result1; + *pusResult2 = result2; *pubType = (UINT8) Merge[iLoop][4]; *pubAPCost = (UINT8) Merge[iLoop][5]; return( TRUE ); @@ -7655,6 +7666,12 @@ BOOLEAN CreateItem( UINT16 usItem, INT16 bStatus, OBJECTTYPE * pObj ) if ( GetItemFromRandomItem(usItem, &newitemfromrandom) ) usItem = newitemfromrandom; + if (usItem == 0) + { + DebugBreakpoint(); + return( FALSE ); + } + if (Item[ usItem ].usItemClass == IC_GUN) { fRet = CreateGun( usItem, bStatus, pObj ); @@ -14031,6 +14048,12 @@ BOOLEAN OBJECTTYPE::TransformObject( SOLDIERTYPE * pSoldier, UINT8 ubStatusIndex if (Transform->usResult[curResult] > 0) { usResult[curResult] = Transform->usResult[curResult]; + + // Flugente: resolution of random items + UINT16 rdresult = 0; + if ( GetItemFromRandomItem(usResult[curResult], &rdresult) ) + usResult[curResult] = rdresult; + // Count the number of valid result items iNumResults++; }