From b7ee1b89790239542fcca017e25d36b976ac3864 Mon Sep 17 00:00:00 2001 From: Wanne Date: Tue, 3 Dec 2013 21:14:58 +0000 Subject: [PATCH] Bugfix: "Merc Random Stats Feature" (by Jenilee) - Fixed crash on initializing armor when starting a new game git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6679 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/RandomMerc.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tactical/RandomMerc.cpp b/Tactical/RandomMerc.cpp index e6f8f27a4..1e04f4298 100644 --- a/Tactical/RandomMerc.cpp +++ b/Tactical/RandomMerc.cpp @@ -486,6 +486,10 @@ INVTYPE* GearGetRandomArmor(std::vector* pointer, INT8 min_coolness = if (pointer == NULL) return NULL; + //safety net for low LBE counts (including 1.13 vanilla!) + if (pointer->size() < 20) + return pointer->at(Random(pointer->size())); + std::vector candidates; for (std::vector::iterator it = pointer->begin(); it != pointer->end(); it++) @@ -516,9 +520,9 @@ INVTYPE* GearGetRandomArmor(std::vector* pointer, INT8 min_coolness = } if (candidates.size() < 1) - return GearGetRandomArmor(pointer, -1, 1); //get some random, basic armor instead. + return NULL; - return candidates[Random(candidates.size())]; + return candidates[ Random( candidates.size() ) ]; } //generate a random weapon of requested type, class and BR coolness