Ich habe mal eine ganz generelle Frage:
Wie springt man aus einer if-Anweisung heraus?
Beispiel:
Code:
void CvUnit::findFood()
{
int iFoodAvailable = 0;
int iCityId = -1;
CvCity* pBestCity = NULL;
CvPlayer& kUnitPlayer = GET_PLAYER(getOwnerINLINE());
if (!kUnitPlayer.isNative() || !kUnitPlayer.isEurope() || !GC.getGameINLINE().isBarbarianPlayer(getOwnerINLINE()))
// CBM this should exclude all players without own cities, no?
{
iCityId = kUnitPlayer.getHighestStoredYieldCityId(YIELD_FOOD);
FAssertMsg(iCityId != -1, "Couldn't get city for food");
pBestCity = kUnitPlayer.getCity(iCityId);
FAssertMsg(pBestCity != NULL, "No BestCity found");
if (pBestCity == NULL)
{
return;
}
...
...
Zu Beginn des Spiels kann es vorkommen, dass noch keine Stadt gegründet worden ist. Die beiden Asserts schlagen auch korrekt an. Ich habe mich nun damit beholfen, für diesen Fall ein "return" zu setzen, was in diesem Fall auch logisch richtig ist.
Allerdings verlasse ich damit die Funktion void CvUnit::findFood(), was theoretisch nicht in jedem Fall wünschenswert ist. Es soll nur die hier aufgezeigte if-Anweisung abgebrochen, und dann innerhalb von void CvUnit::findFood() nach dem if weitergemacht werden.
Wie müsste der dafür notwendige Befehl lauten?