Skip to content

Commit

Permalink
Too few tradegoods causes infinite loop
Browse files Browse the repository at this point in the history
* This pulls in the work from PR #54 to avoid an infinite loop when we
  have less than 4 trade items.
  • Loading branch information
jt-traub committed May 7, 2024
1 parent 906f132 commit 096e7a3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,10 @@ void ARegion::SetupCityMarket()
supply[i] = 0;
num--;
}

// If we don't have at least 4 trade items don't set up trade markets
if (numtrade < 4) return;

/* Set up the trade items */
int buy1 = getrandom(numtrade);
int buy2 = getrandom(numtrade);
Expand All @@ -668,8 +672,7 @@ void ARegion::SetupCityMarket()
buy1 = getrandom(numtrade);
while (buy1 == buy2) buy2 = getrandom(numtrade);
while (sell1 == buy1 || sell1 == buy2) sell1 = getrandom(numtrade);
while (sell2 == sell1 || sell2 == buy2 || sell2 == buy1)
sell2 = getrandom(numtrade);
while (sell2 == sell1 || sell2 == buy2 || sell2 == buy1) sell2 = getrandom(numtrade);

for (int i=0; i<NITEMS; i++) {
if (ItemDefs[i].flags & ItemType::DISABLED) continue;
Expand Down

0 comments on commit 096e7a3

Please sign in to comment.