Restricting goodies by improvement type

TC01

Deity
Joined
Jun 28, 2009
Messages
2,216
Location
Irregularly Online
I want to add an XML tag to goodies that will allow me to set a required improvement for that goody. So I could, say, make the barbarian spawning goodies only occur on a "Barbarian Village" improvement, and make the others only occur on the regular Goody Hut. (that's not actually what I want to do, it's just an example.

I added this code to CvPlayer::canReceiveGoody:

Code:
	if (GC.getGoodyInfo(eGoody).getRequiredImprovement() != NO_IMPROVEMENT)
	{
		if (pPlot->getImprovementType() != GC.getGoodyInfo(eGoody).getRequiredImprovement())
		{
			return false;
		}
	}

The problem is, now no goodies are received at all, no matter which improvement I move on to. I tried increasing the "NUM_DO_GOODY_ATTEMPTS" global define from 10 to 100, but that didn't fix the issue.

I then tried removing all the RequiredImprovement tags from all goodies (they default to NO_IMPROVEMENT), and things worked again. So the problem is the comparison against the plot's improvement type. For some reason it doesn't think that the plot improvement type equals the required improvement... even when it does.

Maybe it's just my relative inexperience in the DLL, but I have no idea why. So... any ideas?
 
How about testing the opposite. If the plot has the required improvement, return true. You should get a goody hut on every improvement of that type.

If that doesn't work, you've got an underlying problem that I am not seeing...
 
Aren't Goody Huts improvements themselves? How can they require an improvement be on the same tile? :confused:
 
How about testing the opposite. If the plot has the required improvement, return true. You should get a goody hut on every improvement of that type.

If that doesn't work, you've got an underlying problem that I am not seeing...

Well, if I do that, goodies work again. But there's no restriction (of course, there wouldn't be).

So then I tried adding an "else return false" statement to the end of that. Goodies stop working. Which means that the RequiredImprovement does not equal the plot's improvement... even when it does, which is what I thought was the case.

To make sure of that, I wrote a loop in Python that prints out the RequiredImprovement for each goody, and they match the correct improvements in the XML.
 
Okay, I've done some more testing.

First, I realized I was comparing an ImprovementTypes enumerator against an integer. I don't know if that would be an issue, but I fixed it.

Then, I discovered that if I compared the required improvement against "(ImprovementTypes)7" or "(ImprovementTypes)3" (3 and 7 being the two goody hut improvements) things worked. At least, the goodies that required those two improvements worked.

But, if I compared "pPlot->getImprovementType()" against that, things didn't work.

And then I discovered why.

canReceiveGoody is called by doGoody, and part of doGoody, which occurs directly before the check to see if a goody can be received, is this:

Code:
pPlot->removeGoody();

Which does this:

Code:
void CvPlot::removeGoody()
{
	setImprovementType(NO_IMPROVEMENT);
}

So, by the time the code gets to canReceiveGoody (and where I added my code), there is no improvement on the plot.

Would it mess things up if I moved the call to removeGoody after a goody is picked, validated, and received? And if it would, how else could I do this so that canReceiveGoody has access to the plot's (former) improvement type?
 
Things seem to work with pPlot->removeGoody(); moved to the end of the doGoody function.

That is, it's fixed my problem, and it doesn't appear to have broken anything else.

er...why do you not just make the "barbarian village improvement" upgrade to your new, second type of goody hut?

In the example, that was the second goody hut.

What I am actually trying to do is set up two different "sets" of goodies for Final Frontier Plus (well, I'm making it as a modcomp for Star Trek first). The first set is only receivable at the normal Space Wreckage (Final Frontier's goody huts). The second set is receivable at "alien planets"- systems inhabited by minor alien races.
 
Top Bottom