New feature: Getting and using intel allows for more spy-related roleplay.

For more info, see http://thepit.ja-galaxy-forum.com/index.php?t=msg&th=23643&goto=352475&#msg_352475

Requires GameDir >= r2401.

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8522 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Flugente
2018-02-18 23:17:34 +00:00
parent ee73811cfe
commit e55b480996
83 changed files with 3784 additions and 937 deletions
+115 -5
View File
@@ -18,6 +18,7 @@
#include "Scheduling.h"
#include "GameSettings.h"
#include "Overhead.h" // added by Flugente for MercPtrs[]
#include "LuaInitNPCs.h" // added by Flugente
#endif
#ifdef JA2UB
@@ -42,6 +43,9 @@
void ConvertCreatureBloodToElixir( void );
// Flugente: if we are a lua-based merchant, stop selling items we didn't explicitly want to be sold
void RemoveNonIntelItems();
UINT8 gubLastSpecialItemAddedAtElement = 255;
// Flugente 2012-12-19: merchant data has been externalised - see XML_Merchants.cpp
@@ -237,6 +241,64 @@ void ShutDownArmsDealers()
gArmsDealersInventory.clear();
}
typedef struct
{
UINT16 usItem;
INT16 sIntelPrice;
INT16 sOptimalNumber;
} ARMS_DEALER_ITEM_INTEL;
std::map<UINT16, std::vector<ARMS_DEALER_ITEM_INTEL> > gArmsDealerAdditionalIntelData;
void AddArmsDealerAdditionalIntelData( UINT16 ausDealer, UINT16 usItem, INT16 sIntelPrice, INT16 sOptimalNumber )
{
ARMS_DEALER_ITEM_INTEL data;
data.usItem = usItem;
data.sIntelPrice = sIntelPrice;
data.sOptimalNumber = sOptimalNumber;
gArmsDealerAdditionalIntelData[ausDealer].push_back( data );
}
void ArmsDealers_ReadIntelData()
{
gArmsDealerAdditionalIntelData.clear();
// ask lua on what to use
LuaAddArmsDealerAdditionalIntelData();
}
void HandlePossibleArmsDealerIntelRefresh( BOOLEAN aForceReread )
{
if ( gArmsDealerAdditionalIntelData.empty() || aForceReread )
{
ArmsDealers_ReadIntelData();
// replace xml-based possible inventory with what lua gave us
for ( std::map<UINT16, std::vector<ARMS_DEALER_ITEM_INTEL> >::iterator it = gArmsDealerAdditionalIntelData.begin(); it != gArmsDealerAdditionalIntelData.end(); ++it)
{
UINT16 dealerid = ( *it ).first;
DEALER_POSSIBLE_INV* pDealerInv = GetPointerToDealersPossibleInventory( dealerid );
memset( pDealerInv, 0, sizeof( DEALER_POSSIBLE_INV )*MAXITEMS );
int cnt = 0;
for ( std::vector<ARMS_DEALER_ITEM_INTEL>::iterator it2 = (*it).second.begin(); it2 != ( *it ).second.end(); ++it2 )
{
ARMS_DEALER_ITEM_INTEL data = ( *it2 );
pDealerInv[cnt].uiIndex = cnt;
pDealerInv[cnt].sItemIndex = data.usItem;
pDealerInv[cnt].ubOptimalNumber = data.sOptimalNumber;
++cnt;
}
}
}
}
BOOLEAN SaveArmsDealerInventoryToSaveGameFile( HWFILE hFile )
{
UINT32 uiNumBytesWritten;
@@ -313,7 +375,7 @@ void DailyUpdateOfArmsDealersInventory()
{
// if Gabby has creature blood, start turning it into extra elixir
ConvertCreatureBloodToElixir();
//Simulate other customers buying inventory from the dealer
SimulateArmsDealerCustomer();
@@ -323,6 +385,10 @@ void DailyUpdateOfArmsDealersInventory()
#else
DailyCheckOnItemQuantities();
#endif
// Flugente: if we are a lua-based merchant, stop selling items we didn't explicitly want to be sold
RemoveNonIntelItems();
//make sure certain items are in stock and certain limits are respected
AdjustCertainDealersInventory( );
}
@@ -423,6 +489,8 @@ void DailyCheckOnItemQuantities()
UINT32 uiArrivalDay;
UINT8 ubReorderDays;
HandlePossibleArmsDealerIntelRefresh(TRUE);
//loop through all the arms dealers
for( ubArmsDealer=0;ubArmsDealer<NUM_ARMS_DEALERS; ++ubArmsDealer )
{
@@ -603,6 +671,32 @@ void ConvertCreatureBloodToElixir( void )
}
}
// Flugente: if we are a lua-based merchant, stop selling items we didn't explicitly want to be sold
void RemoveNonIntelItems()
{
for ( UINT8 ubArmsDealer = 0; ubArmsDealer<NUM_ARMS_DEALERS; ++ubArmsDealer )
{
if ( gArmsDealerStatus[ubArmsDealer].fOutOfBusiness )
continue;
if ( armsDealerInfo[ubArmsDealer].uiFlags & ARMS_DEALER_DEALWITHINTEL )
{
std::vector<UINT16> baditemsvector;
for ( DealerItemList::iterator iter = gArmsDealersInventory[ubArmsDealer].begin(); iter != gArmsDealersInventory[ubArmsDealer].end(); ++iter )
{
if ( iter->ItemIsInInventory() == true && CalcValueOfItemToDealer( ubArmsDealer, iter->object.usItem, TRUE ) < 1 )
baditemsvector.push_back( iter->object.usItem );
}
for ( std::vector<UINT16>::iterator it2 = baditemsvector.begin(); it2 != baditemsvector.end(); ++it2 )
{
RemoveItemFromArmsDealerInventory( ubArmsDealer, (*it2), 100 );
}
}
}
}
BOOLEAN AdjustCertainDealersInventory( )
{
//Adjust Tony's items (this restocks *instantly* 1/day, doesn't use the reorder system)
@@ -2083,15 +2177,15 @@ UINT32 CalculateSimpleItemRepairCost( UINT8 ubArmsDealer, UINT16 usItemIndex, IN
BOOLEAN DoesItemAppearInDealerInventoryList( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN fPurchaseFromPlayer )
{
DEALER_POSSIBLE_INV *pDealerInv=NULL;
UINT16 usCnt;
// Flugente: a dealer's inventory is defined in lua if they deal in intel
HandlePossibleArmsDealerIntelRefresh(FALSE);
// the others will buy only things that appear in their own "for sale" inventory lists
pDealerInv = GetPointerToDealersPossibleInventory( ubArmsDealer );
DEALER_POSSIBLE_INV* pDealerInv = GetPointerToDealersPossibleInventory( ubArmsDealer );
Assert( pDealerInv != NULL );
// loop through the dealers' possible inventory and see if the item exists there
usCnt = 0;
UINT16 usCnt = 0;
while( pDealerInv[ usCnt ].sItemIndex != LAST_DEALER_ITEM )
{
//if the initial dealer inv contains the required item, the dealer can sell the item
@@ -2119,6 +2213,22 @@ UINT16 CalcValueOfItemToDealer( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN
usBasePrice = Item[ usItemIndex ].usPrice;
// Flugente: if we deal with intel, get the price of an item straight from LUA
if ( ( armsDealerInfo[ubArmsDealer].uiFlags & ARMS_DEALER_DEALWITHINTEL ) )
{
if ( !gArmsDealerAdditionalIntelData[ubArmsDealer].empty() )
{
for ( std::vector<ARMS_DEALER_ITEM_INTEL>::iterator it = gArmsDealerAdditionalIntelData[ubArmsDealer].begin(); it != gArmsDealerAdditionalIntelData[ubArmsDealer].end(); ++it )
{
if ( ( *it ).usItem == usItemIndex )
return ( *it ).sIntelPrice;
}
}
return 0;
}
if ( usBasePrice == 0 )
{
// worthless to any dealer