From 1252675d7ef3c8bc65b1bfc6aa55cdb13832336d Mon Sep 17 00:00:00 2001 From: Wanne Date: Tue, 21 Jun 2011 13:18:58 +0000 Subject: [PATCH] BUGZILLA #535: Fixed CTD that could occur every day on strategy screen at 08:58 when initializing the inventory for the arms dealer git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@4512 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/ArmsDealerInvInit.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Tactical/ArmsDealerInvInit.cpp b/Tactical/ArmsDealerInvInit.cpp index 307d87af..c9561b54 100644 --- a/Tactical/ArmsDealerInvInit.cpp +++ b/Tactical/ArmsDealerInvInit.cpp @@ -1226,22 +1226,26 @@ UINT8 HowManyItemsAreSold( INT8 bArmsDealerID, UINT16 usItemIndex, UINT8 ubNumIn UINT8 HowManyItemsToReorder(UINT8 ubWanted, UINT8 ubStillHave) { - UINT8 ubNumReordered; + UINT8 ubNumReordered = 0; DebugMsg(TOPIC_JA2, DBG_LEVEL_3,String("HowManyItemsToReorder: wanted = %d, still have = %d",ubWanted, ubStillHave)); - Assert(ubStillHave <= ubWanted); + // WANNE: Disabled assertion and fixed possibly problem + //Assert(ubStillHave <= ubWanted); - ubNumReordered = ubWanted - ubStillHave; - - //randomize the amount. 33% of the time we add to it, 33% we subtract from it, rest leave it alone - switch (Random(3)) + if (ubWanted > ubStillHave) { - case 0: - ubNumReordered += ubNumReordered / 2; - break; - case 1: - ubNumReordered -= ubNumReordered / 2; - break; + ubNumReordered = ubWanted - ubStillHave; + + //randomize the amount. 33% of the time we add to it, 33% we subtract from it, rest leave it alone + switch (Random(3)) + { + case 0: + ubNumReordered += ubNumReordered / 2; + break; + case 1: + ubNumReordered -= ubNumReordered / 2; + break; + } } DebugMsg(TOPIC_JA2, DBG_LEVEL_3,String("HowManyBRItemsToOrder: reordered = %d",ubNumReordered));