diff --git a/Tactical/Inventory Choosing.cpp b/Tactical/Inventory Choosing.cpp
index c2bf87176..fb74dee9a 100644
--- a/Tactical/Inventory Choosing.cpp
+++ b/Tactical/Inventory Choosing.cpp
@@ -3326,6 +3326,8 @@ UINT16 SelectStandardArmyGun( UINT8 uiGunLevel, INT8 bSoldierClass )
// choose one the of the possible gun choices
usGunIndex = -1;
+ BOOLEAN isnight = NightTime();
+
while (usGunIndex == -1)
{
uiChoice = Random(pGunChoiceTable[ uiGunLevel ].ubChoices);
@@ -3357,6 +3359,10 @@ UINT16 SelectStandardArmyGun( UINT8 uiGunLevel, INT8 bSoldierClass )
{
usGunIndex = pGunChoiceTable[ uiGunLevel ].bItemNo[ i ];
+ // Flugente: ignore this item if we aren't allowed to pick it at this time of day
+ if ( ( isnight && Item[usGunIndex].usItemChoiceTimeSetting == 1 ) || ( !isnight && Item[usGunIndex].usItemChoiceTimeSetting == 2 ) )
+ continue;
+
if (!ItemIsLegal(usGunIndex))
usGunIndex = -1;
else
@@ -3440,6 +3446,8 @@ UINT16 PickARandomItem(UINT8 typeIndex, INT8 bSoldierClass, UINT8 maxCoolness, B
if ( gArmyItemChoices[bSoldierClass][ typeIndex ].ubChoices <= 0 )
return 0;
+ BOOLEAN isnight = NightTime();
+
// check up to 10 times for an item with a matching coolness
for (int i=0; i < 10;i++)
{
@@ -3459,6 +3467,10 @@ UINT16 PickARandomItem(UINT8 typeIndex, INT8 bSoldierClass, UINT8 maxCoolness, B
}
usItem = gArmyItemChoices[bSoldierClass][ typeIndex ].bItemNo[ uiChoice ];
+ // Flugente: ignore this item if we aren't allowed to pick it at this time of day
+ if ( ( isnight && Item[usItem].usItemChoiceTimeSetting == 1 ) || ( !isnight && Item[usItem].usItemChoiceTimeSetting == 2 ) )
+ continue;
+
// Flugente: random items
UINT16 newitemfromrandom = 0;
if ( GetItemFromRandomItem(usItem, &newitemfromrandom) )
@@ -3532,6 +3544,8 @@ UINT16 PickARandomAttachment(UINT8 typeIndex, INT8 bSoldierClass, UINT16 usBaseI
if ( gArmyItemChoices[bSoldierClass][ typeIndex ].ubChoices <= 0 )
return 0;
+ BOOLEAN isnight = NightTime();
+
// check up to 10 times for an item with a matching coolness
for (int i=0; i < 50; i++)
{
@@ -3542,6 +3556,10 @@ UINT16 PickARandomAttachment(UINT8 typeIndex, INT8 bSoldierClass, UINT16 usBaseI
uiChoice = Random(gArmyItemChoices[bSoldierClass][ typeIndex ].ubChoices);
usItem = gArmyItemChoices[bSoldierClass][ typeIndex ].bItemNo[ uiChoice ];
+ // Flugente: ignore this item if we aren't allowed to pick it at this time of day
+ if ( ( isnight && Item[usItem].usItemChoiceTimeSetting == 1 ) || ( !isnight && Item[usItem].usItemChoiceTimeSetting == 2 ) )
+ continue;
+
BOOLEAN fDefaultAttachment = FALSE;
for(UINT8 cnt = 0; cnt < MAX_DEFAULT_ATTACHMENTS; cnt++){
if(Item[usBaseItem].defaultattachments[cnt] == 0)
diff --git a/Tactical/Item Types.h b/Tactical/Item Types.h
index fb20038fe..f84306b7a 100644
--- a/Tactical/Item Types.h
+++ b/Tactical/Item Types.h
@@ -1104,7 +1104,7 @@ typedef struct
FLOAT projectionfactor;
BOOLEAN speeddot;
- // Flugente FTW 1.2
+ // Flugente
BOOLEAN barrel; // item can be used on some guns as an exchange barrel
FLOAT usOverheatingCooldownFactor; // every turn/5 seconds, a gun's temperature is lowered by this amount
FLOAT overheatTemperatureModificator; // percentage modifier of heat a shot generates (read from attachments)
@@ -1153,6 +1153,9 @@ typedef struct
// Flugente: range of a flashlight (an item with usFlashLightRange > 0 is deemed a flashlight)
UINT8 usFlashLightRange;
+ // Flugente: determine wether the AI should pick this item for its choices only at certain times
+ UINT8 usItemChoiceTimeSetting;
+
} INVTYPE;
diff --git a/Utils/XML_Items.cpp b/Utils/XML_Items.cpp
index 6e839aded..185b493e7 100644
--- a/Utils/XML_Items.cpp
+++ b/Utils/XML_Items.cpp
@@ -273,7 +273,8 @@ itemStartElementHandle(void *userData, const XML_Char *name, const XML_Char **at
strcmp(name, "clothestype") == 0 ||
strcmp(name, "randomitem") == 0 ||
strcmp(name, "randomitemcoolnessmodificator") == 0 ||
- strcmp(name, "FlashLightRange") == 0 ))
+ strcmp(name, "FlashLightRange") == 0 ||
+ strcmp(name, "ItemChoiceTimeSetting") == 0 ))
{
pData->curElement = ELEMENT_PROPERTY;
//DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("itemStartElementHandle: going into element, name = %s",name) );
@@ -1412,6 +1413,12 @@ itemEndElementHandle(void *userData, const XML_Char *name)
pData->curElement = ELEMENT;
pData->curItem.usFlashLightRange = (UINT8) atol(pData->szCharData);
}
+ else if(strcmp(name, "ItemChoiceTimeSetting") == 0)
+ {
+ pData->curElement = ELEMENT;
+ // no nonsense, only values between 0 and + 2
+ pData->curItem.usItemChoiceTimeSetting = min(2, max(0, (UINT8) atol(pData->szCharData) ) );
+ }
pData->maxReadDepth--;
}
@@ -2050,6 +2057,7 @@ BOOLEAN WriteItemStats()
FilePrintf(hFile,"\t\t%d\r\n", Item[cnt].randomitem );
FilePrintf(hFile,"\t\t%d\r\n", Item[cnt].randomitemcoolnessmodificator );
FilePrintf(hFile,"\t\t%d\r\n", Item[cnt].usFlashLightRange );
+ FilePrintf(hFile,"\t\t%d\r\n", Item[cnt].usItemChoiceTimeSetting );
FilePrintf(hFile,"\t\r\n");
}