int Force_GetShipType(int maxclass, int minclass, string type, int nat)
{
//these are JUST IN CASE...
if(maxclass > minclass) {int tmp = maxclass; maxclass = minclass; minclass = tmp; } // NK to swap min/max if needed 05-04-15
// 04-09-09 NK-PRS3
if(type == "pirate")
{
if(PIRATES_USE_BOTH_TYPES) { type = ""; }
else { type = "war"; }
}
// NK <--
switch(type) // add this 05-05-01 for just in case.
{
case "trade":
maxclass = iclamp(MAXMERCHANTCLASS, MIN_CLASS, maxclass);
minclass = iclamp(MAXMERCHANTCLASS, MIN_CLASS, minclass);
break;
case "pirate":
maxclass = iclamp(MAXPIRATECLASS, MIN_CLASS, maxclass);
minclass = iclamp(MAXPIRATECLASS, MIN_CLASS, minclass);
break;
// default, war, where max class is MAX_CLASS
maxclass = iclamp(MAX_CLASS, MIN_CLASS, maxclass);
minclass = iclamp(MAX_CLASS, MIN_CLASS, minclass);
}
// Screwface
bool finish = false;
int end = 0; // Security to avoid infinite loop
while(!finish && end < 100) // maximum of 100 loop should be enough
{
int iShipType = Fantom_GetShipType(maxclass, minclass, type, nat);
if(iShipType < SHIP_TYPES_QUANTITY && iShipType >= 0)
{
finish = true;
}
else
{
end++;
}
}
if(finish){return iShipType;}
else{return GetCharacterShipType(GetMainCharacter());}
// old section outcommented
/*int iShipType = Fantom_GetShipType(maxclass, minclass, type, nat);
if(iShipType < SHIP_TYPES_QUANTITY && iShipType >= 0) { return iShipType; }
trace("oh no, we didn't find a ship the first go!");
iShipType = Fantom_GetShipType(maxclass, minclass, type, nat); // try again, for randomness
if(iShipType < SHIP_TYPES_QUANTITY && iShipType >= 0) { return iShipType; }
iShipType = Fantom_GetShipType(maxclass, minclass, type, -1); // clear nation
if(iShipType < SHIP_TYPES_QUANTITY && iShipType >= 0) { return iShipType; }
iShipType = Fantom_GetShipType(maxclass, minclass, "none", -1); // clear type too
if(iShipType < SHIP_TYPES_QUANTITY && iShipType >= 0) { return iShipType; }
iShipType = GetCharacterShipType(GetMainCharacter());
return iShipType;*/
}