Code not working as it should

j_mie6

Deity
Joined
Dec 20, 2009
Messages
2,963
Location
Bristol (uni)/Swindon (home)
Hello!

If been working on some tech enhancements for the Babylon 5 mod, and I have some code that doesn't work, and I can't figure out why, I was hoping somebody could shed some light on the logic here:

Code:
//Babylon 5 Mod - Tech Enhancements - Start
	
	if (GC.getTechInfo(eTech).isDisable())
	{
		if (GC.getTechInfo(eTech).isRequiresMetCiv())
		{
			for (int i = 0; i < GC.getGameINLINE().countCivTeamsEverAlive(); i++)
			{
				if (getTeam() == (TeamTypes) i ||
					GET_TEAM((TeamTypes) i).isMinorCiv() ||
					GET_TEAM((TeamTypes) i).isBarbarian()) 
				{
					continue;
				}
				if (GET_TEAM(getTeam()).isHasMet((TeamTypes) i)) 
				{
					break;
				}
			}
		}
                /* snip */
		else
		{
			return false;
		}
	}
	//Babylon 5 Mod - Tech Enhancements - End

Above code placed at the start of CvPlayer::canEverResearch(). if the tech is disabled, it should check to see if the tech requires a civ to be met (that isn't minor, barbarian or player). If there is a place met allow them to research the tech.

the problem is, the tech is available even if you haven't found anybody yet!

here is some code from the snip section which is similar and does work, but it is enabled having discovered ALL other civs

Code:
else if (GC.getTechInfo(eTech).isRequiresMetAllCivs())
		{
			for (int i = 0; i < GC.getGameINLINE().countCivTeamsEverAlive(); i++)
			{
				if (getTeam() == (TeamTypes) i ||
					GET_TEAM((TeamTypes) i).isMinorCiv() ||
					GET_TEAM((TeamTypes) i).isBarbarian() ||
					!GET_TEAM((TeamTypes) i).isAlive()) 
				{
					continue;
				}
				if (!GET_TEAM(getTeam()).isHasMet((TeamTypes) i)) 
				{
					return false;
				}
			}
		}

can anybody tell me what I am doing wrong here? I have to have the tech disabled by the way...

Thanks,
Jamie
 
Edit:
Nvm, didn't see the first or statement :D

Anyway, False is returned only when if (GC.getTechInfo(eTech).isRequiresMetCiv()) is False due to the else statement...
So naturally, if the tech requires it to meet civ, it will return True regardless of the loop

BTW...
There is a danger of using countCivTeamsEverAlive() for the max range of the loop since there are ways to add teams with specific team number, thus making gaps between alive teams and screwing up your code...

And if you are using that range, then why bother to check for barbies
 
it was really a precaution with barbs in case it caused the problem.

well, it may not return false but it DOES break. which should cause it to carry on in the function (ie, if the player has met somebody, ignore the disable and check the normal other stuff.

ahhhh but breaking doesn't mean it will continue into else.... you are right... that was a stupid oversight on my part! Thank you!

the countTeamsEverAlive shouldn't be a problem for B5 as there is nothing like that being used in the Mod but I will keep that in mind for the future (and if ever I need to change it).

how that I know what was wrong, how do you think it can be changed, because if a player has been met we can't assume the tech should be researchable, because it might not have prereqs etc, so we cannot say return true, we have to leave the whole structure and continue with the code... I could probably use a dummy variable hasMet. and if the player !hasMet somebody, return false. Should work, not very elegant though...
 
Depends where it is coded.
In python, there is both canresearch and cannotresearch.
If it is done in cannotresearch, just return false if you met someone and done.
If done in canresearch, then you are asking for it
 
Code:
bool CvPlayer::canEverResearch(TechTypes eTech)
{
	if (GC.getCivilizationInfo(getCivilizationType()).isCivilizationDisableTechs(eTech))
	{
		return false;
	}

	CyArgsList argsList;
	argsList.add(getID());
	argsList.add(eTech);
	argsList.add(false);
	long lResult=0;
	gDLL->getPythonIFace()->callFunction(PYGameModule, "cannotResearch", argsList.makeFunctionArgs(), &lResult);
	if (lResult == 1)
	{
		return false;
	}

	if (GC.getTechInfo(eTech).isDisable())
	{
		if (GC.getTechInfo(eTech).isRequiresMetCiv())
		{
			for (int i = 0; i < GC.getGameINLINE().countCivTeamsEverAlive(); i++)
			{
				if (getTeam() == (TeamTypes) i || GET_TEAM((TeamTypes) i).isMinorCiv())
				{
					continue;
				}
				if (GET_TEAM(getTeam()).isHasMet((TeamTypes) i)) 
				{
					return true;
				}
			}
		}
		return false;
	}

	return true;
}
 
Back
Top Bottom