Weird python error with the flag/TeamAI.h

Many of those things on the list depend on the first half of the second item: "let players have ideologies". Display which one each player has is a separate item. Thus, I would add this first. Once players can have ideologies, add Python functions that allow you to force a player to change ideology a la CyPlayer.convert(). They won't have any effects, but this is the first step in my mind; everything will build from there.

I assume each player will have a single ideology, just like religion? Actually, even before this step you need to define ideologies:

  1. CvEnum.h:
    • IdeologyTypes
    • IDEOLOGY_NONE
  2. Create CvIdeologyInfo
  3. Define getNumIdeologyInfos()
  4. Create XML schema
  5. Create CIV4IdeologyInfos.xml
  6. Load the infos from CvXMLLoadUtilitySet.cpp
While you could hard-code a few ideologies at the start (like domains), you'll need an info class to do any of the other things on your list, so you may as well start here.
 
Many of those things on the list depend on the first half of the second item: "let players have ideologies". Display which one each player has is a separate item. Thus, I would add this first. Once players can have ideologies, add Python functions that allow you to force a player to change ideology a la CyPlayer.convert(). They won't have any effects, but this is the first step in my mind; everything will build from there.

I assume each player will have a single ideology, just like religion? Actually, even before this step you need to define ideologies:

  1. CvEnum.h:
    • IdeologyTypes
    • IDEOLOGY_NONE
  2. Create CvIdeologyInfo
  3. Define getNumIdeologyInfos()
  4. Create XML schema
  5. Create CIV4IdeologyInfos.xml
  6. Load the infos from CvXMLLoadUtilitySet.cpp
While you could hard-code a few ideologies at the start (like domains), you'll need an info class to do any of the other things on your list, so you may as well start here.

So are you saying that I should start allowing players to have ideologies, because I've already defined them? And yes, each player can have only one ideology.
 
If you've already done the things I listed to allow the game to parse the XML file to create CvIdeologyInfo objects, then yes the next step is to add a field (m_eIdeology?) to CvPlayer. You'll want getIdeology() and setIdeology() functions on CvPlayer and CyPlayer, and in CyPlayerInterface so you can use them from the Python console in the game to make sure they work.

Eventually setIdeology() would not be available via CyPlayer as it will be replaced by some sort of convertIdeology() function that works like convert(religion). But for now it will help for testing to be able to directly set the value for a player.

After you have that you need to pick which thing makes the most sense to add: having effects will be more fun, showing it in the hover should be easy, and having a screen that allows you to view the differences and change ideology like the CvCivicAdvisor screen would be helpful as well.

But most importantly, make backups of working versions along the way. If you don't want to use Subversion or some other code repository that allows tracking revisions of files and branching and tagging, at least ZIP up the files when it works (just the .cpp and .h files and maybe the compiled DLL but no need to archive the .obj files as you can just compile again). This will allow you to rollback one step when things go awry instead of all the way to ground zero.
 
Nope, that's all you need to do. Check, does hitting CTRL + W bring up WorldBuilder? If not, you haven't entered the cheat code correctly. Hitting ` brings up one console and ~ (SHIFT + `) brings up the Python console.
 
Nope, that's all you need to do. Check, does hitting CTRL + W bring up WorldBuilder? If not, you haven't entered the cheat code correctly. Hitting ` brings up one console and ~ (SHIFT + `) brings up the Python console.

Do I need the cheat code to use worldbuilder? I've used it since the begining without changing the cheat code. :confused:
So you're saying that I need to hit SHIFT + `? This is getting problematic, because I have slightly different keyboard. I need to hit CTRL ALT to get ~ and SHIFT + ´ to get `. Damn these laptops. :mad:
 
I still haven't got the python console work, but i have found many interesting things. Do you know any quides that tells you what happens when you hit this and that?

EDIT: I found it! I need to hit SHIFT + ö.
Now what I have to do to make it run the code I added?
 
Okay, first the two consoles look very similar. The Python console definitely says "Python" and the version # while the other one will be blank. To test it, hit F1 and you should see some code pop up, I think to get player 0:

Code:
p = gc.getPlayer(0)

There's a hint on how to use the console: just like the normal game code you'd write in an event or game-utils callback or any screen.

Code:
p = gc.getPlayer(0)
print p.getName()
print gc.getCivilizationInfo(p.getCivilizationType()).getDescription()
print p.getCity(0).getName()

print p.getIdeology()
eIdeology = gc.getInfoTypeForString("IDEOLOGY_ALTRUISM")
print eIdeology
p.setIdeology(eIdeology)
print p.getIdeology()
 
Okay, first the two consoles look very similar. The Python console definitely says "Python" and the version # while the other one will be blank. To test it, hit F1 and you should see some code pop up, I think to get player 0:

Code:
p = gc.getPlayer(0)

There's a hint on how to use the console: just like the normal game code you'd write in an event or game-utils callback or any screen.

Code:
p = gc.getPlayer(0)
print p.getName()
print gc.getCivilizationInfo(p.getCivilizationType()).getDescription()
print p.getCity(0).getName()

print p.getIdeology()
eIdeology = gc.getInfoTypeForString("IDEOLOGY_ALTRUISM")
print eIdeology
p.setIdeology(eIdeology)
print p.getIdeology()

Okay, that sounds fun and easy. I'll be back in a moment.
BTW, where does it print it, in the screen?

EDIT: It seems to work mostly, but I'm getting name error 'IDEOLOGY_TEST' is not defined. Why would that be?
 
Yes, you'll see the results immediately on the screen, so it's very helpful in testing and development. It will also be written to PythonDbg.log for posterity. ;)
 
A NameError means Python is treating your text as a variable instead of as a plain string. "bob" is a string but bob is a variable/function/class name.

Um, to get quote I just hit my quote key. :confused: It sounds like you have a foreign laptop, as I have never seen a laptop with the ' and " key (same key on every keyboard I've used) in different locations. You can always copy-n-paste it from outside BTS.
 
A NameError means Python is treating your text as a variable instead of as a plain string. "bob" is a string but bob is a variable/function/class name.

Um, to get quote I just hit my quote key. :confused: It sounds like you have a foreign laptop, as I have never seen a laptop with the ' and " key (same key on every keyboard I've used) in different locations. You can always copy-n-paste it from outside BTS.

I got it to work. It was because of the missing ".
Yes, I have foreign laptop that's normal in here Finland, because we have some own characters.
All the buttons are different with the python console so I have to quess everytime I try to write something. :D
I quess I'll move to convertIdeology thing.
 
Now, I've tried to add the IdeologyAdvisor, but I can't get it work. I don't understand how they work. I think that CvReligionScreen creates the Religion Advisor, but I have no idea what calls it? How do I add the new advisor?
 
The code to create the screen object and tell it to draw itself is in EntryPoints/CvScreensInterface.py. The code for the button is in CvMainInterface.py. The button has a WidgetType attached to it that tells it to open that screen that is defined in CvEnum.h and works in CvDLLWidgetData.cpp IIRC.
 
The code to create the screen object and tell it to draw itself is in EntryPoints/CvScreensInterface.py. The code for the button is in CvMainInterface.py. The button has a WidgetType attached to it that tells it to open that screen that is defined in CvEnum.h and works in CvDLLWidgetData.cpp IIRC.

I added the parts to the python files. I had to add CONTROL_IDEOLOGY_SCREEN to CvEnums.h to ControlTypes. It was used in CvMainInterFace. Then I added these to CvGameInterface.cpp
Code:
	case CONTROL_IDEOLOGY_SCREEN:
Code:
	case CONTROL_IDEOLOGY_SCREEN:
		gDLL->getPythonIFace()->callFunction(PYScreensModule, "showIdeologyScreen");
		break;
And in CyEnumsInterface.cpp
Code:
		.value("CONTROL_IDEOLOGY_SCREEN", CONTROL_IDEOLOGY_SCREEN)
I did a rebuild but when starting the game, it crashes. :confused: Why would these changes cause a crash?
I'll build a debug dll to see if I can find something.
 
Debug dll couldn't catch anything so I attached VC to my mod and found where it crashes. Last calls:
CvXMLLoadUtilitySet.cpp, SetGlobalActionInfo()
Code:
	for (i=0;i<NUM_CONTROL_TYPES;i++)
	{
		piIndexList[iTotalActionInfoCount] = i;
		[COLOR="Red"]piPriorityList[iTotalActionInfoCount] = GC.getControlInfo((ControlTypes)i).getOrderPriority();[/COLOR]
		piActionInfoTypeList[iTotalActionInfoCount] = ACTIONSUBTYPE_CONTROL;
		iTotalActionInfoCount++;
	}
CvInfos, CvHotkeyInfo::getOrderPriority()
Code:
int CvHotkeyInfo::getOrderPriority() const
{
	return m_iOrderPriority;
}
It's calling getOrderPriority() from the new CONTROL_IDEOLOGY_SCREEN. Why does it crash? Is there something I missed?
 
I had to add CONTROL_IDEOLOGY_SCREEN to CvEnums.h to ControlTypes.

Please confirm if you did a *full* rebuild (delete all the object files) after changing a header file. This is a habit you will have to pick up.

Others have reported that if you modify certain enums by adding a value in the middle, weird things happen, possibly including crashes. This is apparently because the main executable itself uses these enums and it starts suddenly using the wrong objects. I think this is less likely, but if you added your new value in the middle, try moving it to the end. (And then doing a full rebuild.)
 
Please confirm if you did a *full* rebuild (delete all the object files) after changing a header file. This is a habit you will have to pick up.
So are you saying clicking "rebuild solution" isn't enough, but I have to delete all the objects?
I added the new value to the end. I think I learned my lesson previously. ;)

EDIT: I deleted all objects and did a full rebuild, but it still crashes.
 
Top Bottom