So my guess was maybe pretty close but I dont know the game well enough to say.
from this code in CCCFunctions.c
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
int RandomEnemyNation(ref chr)
{
// check if there are any enemy nations at all
for(int i = 0; i < MAX_NATIONS; i++)
{
if(GetRMRelation(chr, i) <= REL_WAR && iNation != PIRATE)
{
// then get ANY random enemynation
int iNation = makeint(Rand(MAX_NATIONS));
while(GetRMRelation(chr, iNation) > REL_WAR || iNation == PIRATE)
{
iNation = makeint(Rand(MAX_NATIONS));
}
return iNation;
}
}
return -1;
}
<!--c2--></div><!--ec2-->
How does this even compile? your using iNation in your if check prior to its declaration. Unless PotC has some weird syntax I'm unaware of. I'm guessing this function got butchered during a find & replace or copy paste job. I think this is more along the lines of what you meant to do.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
int RandomEnemyNation(ref chr)
{
int iNationID;
// check all the nations
for ( iNationID = 0; iNationID < MAX_NATIONS; iNationID++ )
{
// but skip the bloody pirates!
if ( iNationID == PIRATE )
continue;
// is this one hostile?
if ( GetRMRelation(chr, iNationID) <= REL_WAR )
return iNationID;
}
// couldn't find a hostile so pick a random one
iNationID = rand(MAX_NATIONS);
// keep choosing 'til we get one that is not a pirate
while ( iNationID == PIRATE )
{
iNationID = rand(MAX_NATIONS);
}
return iNationID;
}
<!--c2--></div><!--ec2-->
I think it would be cooler to return the most hostile nation that isn't a pirate. Like if I'm at 0 with everyone except spain where my relation is -1, then we want to return spain. This is how im doing it now, and its working with no problems.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
int RandomEnemyNation(ref chr)
{
// the current nations ID and relation value
int iCurrID, iCurrRel;
// the Least friendly nations ID and relation value
int iLeastRel, iLeastID;
// the Most friendly nations ID and relation value
int iMostRel, iMostID;
// assume id 0 (england) 'til we run the sort
iLeastID = iMostID = 0;
// set both least and most to id 0's relation
iLeastRel = iMostRel = GetRMRelation(chr, 0);
// run through all the nations to find the real least and most friendly
for (iCurrID = 0; iCurrID < MAX_NATIONS; iCurrID++ )
{
// but skip the bloody pirates!
if ( iCurrID == PIRATE )
continue;
// get the current nations relation
iCurrRel = GetRMRelation(chr, iCurrID);
// is the current nation less friendly then the least?
if ( iCurrRel < iLeastRel )
{
// yup it is, save it as the new least
iLeastID = iCurrID;
iLeastRel = iCurrRel;
}
// or is the current relation more friendly than the most?
if ( iCurrRel > iMostRel )
{
// Curr becomes the new most
iMostID = iCurrID;
iMostRel = iCurrRel;
}
}
// now we have the most and least friendly nations. If they are different
// than the Least friendly has the greatest hostility so return that one
if ( iLeastRel != iMostRel )
return iLeastID;
// if we fall here then all relations are equal so we'll choose a random one
iLeastID = rand(MAX_NATIONS);
// keep choosing 'til we get one that is not a pirate
while(iLeastID == PIRATE)
{
iLeastID = rand(MAX_NATIONS);
}
return iLeastID;
}
<!--c2--></div><!--ec2-->
this is assuming of course im reading your code correctly in that a smaller number is more hostile. Like -20 is more hostile then -12. Obviously my way is a lot more bloated and complicated, but i like it better <img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid="
" border="0" alt="smile.gif" />
I hope this helps. Cheers!
edit:
I changed what the variable names meant a little cause this:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
if ( Current < Most )
Most = Current
<!--c2--></div><!--ec2-->
just looked funny to me.