Troubles with Arrays and Arrays of Arrays...

Here is my theory.

I have this code:

Code:
		if (GC.getUnitInfo(eUnit).getPrereqOrCivics(iI))
		{
			if (isCivic((CivicTypes)iI) && (GC.getUnitInfo(eUnit).getPrereqOrCivics(iI)))
			{
				bValid = true;
			}
		}
		else
		{
			bValid = true;
		}
Now I think the else check is screwing it up and always returning true, since it is in the loop. But how can I get bValid to be true for units that don't have anything defined in the tag, but run the function and return false for units that do have something defined there, but aren't running the current civic of something defined in the array?
 
Ooh, good point, we don't account for someone who doesn't require ANY civics. That one is pretty easily handled though:


Code:
	//phungus civic canTrain
	bool bValid = false;
	bool bNoReq = true
	for (iI = 0; iI < GC.getNumCivicInfos(); iI++)
	{
		if (GC.getUnitInfo(eUnit).getPrereqOrCivics(iI))
		{
			bNoReq = false;
			if (isCivic(CivicTypes(iI)))
			{
				bValid = true;
			}
		}
	}
	if (!bNoReq && !bValid)
	{
		return false;
	}
	//phungus -end

The else case shouldn't have been in there at all. Not sure why I hadn't noticed that was around earlier.

Anyway, bNoReq now acts as a tracker for us. If this unit has ANY Civic requirement, it flags off so that we know validation is required. If the player is following any of the civics we needed, then the other flag pops so we know it is allowed.
 
:woohoo: it works!
 
You are going to release this is some form, to RevDCM, correct? This code seems very useful.
I will release it for RevDCM, and it will be included, probably in 2.7 (at least it's on the 2.7 to do list, but since I've gotten it working now, it may make it in 2.61). I have one more tag I need to add, but it's a simple boolean (bPrereqStateReligion). Currently the state religion prereq tags require you to define the specific religion, which means we'd have to create 7 different inquisitors for default BtS, and would need to add others for mergers that change religions, so I think just a simple "does the city have the state religion" check in CvCity::canTrain is also necessary to finish the goal of removing the hardcoding of inquistors from RevDCM.
Now, I just need to port it over the CvBuildingInfo.
I've already ported the GameOption code. The civics and state religion prereq will be harder (the canConstruct porting will be trivial, but I don't know how to make the building go "dead"-ie cease to function- when civics or the state religion is changed), and also not needed from my perspective; so I'll let you handle those.
 
but I don't know how to make the building go "dead"-ie cease to function- when civics or the state religion is changed), and also not needed from my perspective; so I'll let you handle those.


Just a stab here, but wouldn't you loop over each turn, and check that the prereq civic is still in place, and if not, subtract the very modifiers that the building adds?
 
@phungus420 - You get -10 points for hijacking a thread about arrays of arrays with a question about normal arrays. :nono: :p This is getting difficult to follow.

Code:
	//phungus civic canTrain
	bool bValid = false;
	for (iI = 0; iI < GC.getNumCivicInfos(); iI++)
	{
		if (GC.getUnitInfo(eUnit).getPrereqOrCivics(iI) && isCivic(CivicTypes(iI))
		{
			// player is running a requisite civic --> can train the unit
			bValid = true;
			break;
		}
	}
	if (!bValid)
	{
		return false;
	}
	//phungus -end

Edit: Ignore that code, looks like you got it working, and I didn't handle the no civics required case either.

The array is holding booleans because each element says whether or not the civic for the element grants the ability to train the unit. There are NumCivicTypes slots, one for each civic. So the array maps CivicTypes -> trainability.

@Afforess - Another display option would be to combine the happiness and healthiness for for a single tech per line:

+100:), +100:health: with Crop Rotation
+1000:(, +1000:yuck: with Metal Casting​

To do this you loop over techs as you are doing now and check for happiness and healthiness as you are doing and set a boolean if either is detected as you add them to the line with setListHelp(). After, if that boolean is true add the tech description:

Code:
for each tech
    bool bHasEffect = false;
    if tech has happiness
        setListHelp( +X :) / :( )
        bHasEffect = true;
    if tech has health
        setListHelp( +Y + / :p )
        bHasEffect = true;
    if bHasEffect
        append "with <tech-link>"
 
Does anyone know where the setListHelp() function is? I can't figure out what parameters it takes. And what does the L in mean?

If you're using Visual Studio (even Code::Blocks should have a similar feature), right-click the name and select Go to Definition. I think it's in CvGameTextMgr itself because it is called without any object in front.

An L in front of a string literal means it's a wide string for Unicode purposes. Use them with CvWStrings.
 
@Afforess - Another display option would be to combine the happiness and healthiness for for a single tech per line:
+100:), +100:health: with Crop Rotation
+1000:(, +1000:yuck: with Metal Casting​
To do this you loop over techs as you are doing now and check for happiness and healthiness as you are doing and set a boolean if either is detected as you add them to the line with setListHelp(). After, if that boolean is true add the tech description:

I actually have the building text working 100% now. I just need to get the tech text working.
 
If you're using Visual Studio (even Code::Blocks should have a similar feature), right-click the name and select Go to Definition. I think it's in CvGameTextMgr itself because it is called without any object in front.

An L in front of a string literal means it's a wide string for Unicode purposes. Use them with CvWStrings.

Thanks. I use VS 2008 nowadays, because BULL CxImage code refuses to compile with Codeblocks. It's okay, i've gotten used to the change.
 
I've got the tech text working. Thanks for all your help EmperorFool, and Xienwolf.
 
One question.

When the AI researches a tech that gives a building extra :health: or ;), will they take that new health and happiness into account, or am I going to have to code some AI logic for CvCityAI?
 
All players will receive the effects of your changes, but AIs won't know how to value those changes when making building/tech decisions unless you put code into CvCityAI (building) and CvPlayer (tech).
 
You will have to code that logic in. They already consider health/happy with buildings, so you can slip in with those and increase their like of the building AFTER they have the tech which inflates it. Teaching them to place some value on a building which will EVENTUALLY be better is probably not worth your time.

If you meant to have them value a tech which is going to give them a ton of happiness because they already have some of the buildings constructed, then again.. probably not totally worth your time, but you might slip such consideration in with the already existing appeal for +happy which is used for Future Tech right now.


If you are using VS, another useful set of tools is if you right click, the first item in the list is for the "Caller's Graphs" expand that and you can view the Callers (functions that call this one) and the Calls (functions that this one calls to) breakdowns. VERY useful for navigating through chunks of code.
 
I'm almost done hijacking this thread. (But it is about trouble with arrays, so I think it belongs :mischief:)

I've been trying to get the civic icons to appear correctly in the sevopedia, but I'm getting tripped up by the ors. No matter what I try I can't get them to display correctly. Currently I have this:
Code:
		#phungus canTrain
		for j in range(gc.getNumCivicInfos()):
			if (gc.getUnitInfo(self.iUnit).getPrereqOrCivics(j)):
				eCivic = CivicTypes(j)
				screen.attachImageButton(panelName, "", gc.getCivicInfo(eCivic).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_CIVIC, eCivic, -1, False)
				screen.attachLabel(panelName, "", localText.getText("TXT_KEY_OR", ()))
		#phungus -end
But I've checked the API and there is no way to remove the last bit of text, at least not that I can see. Would be awesome if I could just attach a line at the end that says, "remove the last thing you added, that stupid hanging or", but I can't find a function like that in the Python API. I've also tried building a list, but I again can't figure out how to call the civics out of it properly, AND get the last thing in the list to be treated differently, ie not place an OR at the end. I've spent the last 3 hours just trying to remove one simple OR and it's driving me nuts, anyone know how to do this?
 
I'm almost done hijacking this thread. (But it is about trouble with arrays, so I think it belongs :mischief:)

I've been trying to get the civic icons to appear correctly in the sevopedia, but I'm getting tripped up by the ors. No matter what I try I can't get them to display correctly. Currently I have this:
Code:
        #phungus canTrain
        for j in range(gc.getNumCivicInfos()):
            if (gc.getUnitInfo(self.iUnit).getPrereqOrCivics(j)):
                eCivic = CivicTypes(j)
                screen.attachImageButton(panelName, "", gc.getCivicInfo(eCivic).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_CIVIC, eCivic, -1, False)
                screen.attachLabel(panelName, "", localText.getText("TXT_KEY_OR", ()))
        #phungus -end
But I've checked the API and there is no way to remove the last bit of text, at least not that I can see. Would be awesome if I could just attach a line at the end that says, "remove the last thing you added, that stupid hanging or", but I can't find a function like that in the Python API. I've also tried building a list, but I again can't figure out how to call the civics out of it properly, AND get the last thing in the list to be treated differently, ie not place an OR at the end. I've spent the last 3 hours just trying to remove one simple OR and it's driving me nuts, anyone know how to do this?

Just a stab, and I don't know python well enough to give a code example, but wouldn't you loop through the prereqs, and count them. If there is only 1 OR prereq, have one text_key show up, and a different one if there is 2 or more OR prereq's. Thta's how I would do it, anyway.
 
Yeah, except what do I do if there are more then 1 so that the last one doesn't get an Or after it?
 
Back
Top Bottom