[MODCOMP]Professions Pedia Fix/Tutorial

Kailric

Jack of All Trades
Joined
Mar 25, 2008
Messages
3,100
Location
Marooned, Y'isrumgone
When you create a lot of new Professions the game can get confused about which Unit to display in the Professions Pedia, and so this little modcomp aims to fix that. The problem stems from the fact that Professions don't have a Graphic of their own but rather they must be attached to a unit. I'll explain how the Vanilla CVProfessionsPedia.py works below as well. But first I'll explain my additions:

DOWNLOAD V 0.3

I have added a few new tags to the XML that you can use to help sort out the professions. Both the CvProfessionsInfo.xml and the CvUnitInfos.xml have been modified as the following code shows:

Note the new Tags do not have to be present in the XML and so you have to add them in and I could not get the spaceing right in the below examples.
Code:
<ProfessionInfo>
     <Type>PROFESSION_FARMER</Type>
	<Description>TXT_KEY_PROFESSION_FARMER</Description>
	<Civilopedia>TXT_KEY_UNIT_FARMER_PEDIA</Civilopedia>
	<Strategy>TXT_KEY_PROFESSION_FARMER_STRATEGY</Strategy>
	<Help/>
             [B]<bNativesInvalid>0</bNativesInvalid>[/B]
          [B]   <bEuropeInvalid>0</bEuropeInvalid>[/B]
           [B]  <bColonialInvalid>0</bColonialInvalid>[/B]
           [B]  <ArtTagUnitClass>NONE</ArtTagUnitClass>[/B]
             <Combat>NONE</Combat>


Code:
<UnitInfo>
	<Type>UNIT_COLONIST</Type>
		<Class>UNITCLASS_COLONIST</Class>
		<UniqueNames/>
		<Special>NONE</Special>
		<Capture>NONE</Capture>
		<Combat>NONE</Combat>
		<Domain>DOMAIN_LAND</Domain>
		<DefaultUnitAI>UNITAI_COLONIST</DefaultUnit>
<DefaultProfession>PROFESSION_COLONIST</DefaultProfession>
                        [B] <bNativesInvalid>0</bNativesInvalid>[/B]
                         [B]<bEuropeInvalid>0</bEuropeInvalid>[/B]
                         [B]<bColonialInvalid>0</bColonialInvalid>[/B]
              	 <Invisible>NONE</Invisible>

New Tags Explained:

<ArtTagUnitClass> What ever Unit you want to display the Profession simply add in the UnitClass between those tags or you can put "NONE" in between the tags to work as default.

The problem with this is it only works if the Unit has its own unique Class. So for example, for the Natives they are just unqiue units so they don't have a class of their own so this tag does no good for them.

<bNativesInvalid>0</bNativesInvalid>
<bEuropeInvalid>0</bEuropeInvalid>
<bColonialInvalid>0</bColonialInvalid>

The above tags work the same for both CvUnit and CvProfessions. And are used for example, if you create a Unit or Profession and do not want the Natives to use it simply add in the Tag for bNativesInvalid and set it to 1. Not only will the Natives not use the Unit or Professions in the Pedia but they will not use the Unit or Profession while in the game. This removes the need to edit the CvCivilizatioinInfos to allow or disallow Units and Professions.

I also added in a little Extra for the Fun of it. With this mod if you have a Veteran Unit or some kind of Elite unit like the Seasoned scout and a normal Unit Both units will be displayed in the Professions Pedia so you can see what your units will look like as either. See the Screen shots below:


Explanation of the Vanilla Python Code:

First it makes several checks to find a Unit Graphic suitable for the Profession. The code stops and selects the first unit that completes the check:

1. It checks to see if any Unit has the Profession as Default Profession

2. It checks if the Profession produces a Yield then it searches for a Unit that has the Highest bonus to that yield

3. It checks if there is a Combat change with this Profession if so it searches for the Unit with the most number of Free Promotions, by defualt this is the Veteran Unit.

4. If the Profession is Student it then searches for the Unit with the highest Student Weight, by defualt this is the Free Colonist.

If a Unit is found the Unit will aquire the Profession and that graphic will be displayed. If no unit is found no unit will be shown.


Example 1:

I created a new unit called Explorer. The Code runs through all the Civilizations starting with England. If it finds a Civilization that allows the Unit it choses that Civilization to select the Units from as you have to have a unit to attach to the displayed Profession. It this case it finds England. After it finds a Civilization it then runs through the list of that Civilizations Units checking for the one unit with the Highest number of Free Promotions, which in England's case will be the Veteran Unit. The code then gets a Veteran Unit from England and gives it the Explorer Profession.

Now you will have errors if Veteran Unit does not have an art file assigned for Explorer.


Example 2:

Ok, now we are Looking for a unit to display the "Mounted Brave" Profession. As before the code checks to see if there is a valid Civilization which will be the first Civilization it comes to that allows this profession namely, "CIVILIZATION_TUPI". If then runs through the list of all the Units that the Tupi's can have. In our above example if the Explorer had more Free Promotions than the UNIT_NATIVE (the only unit a native is allowed to have basically) or the Explorer is the last Unit it checks then the Explorer unit will be the Unit the Code selects. In this case it will cause an error cause the Explorer unit has no Mounted Brave profession art assigned to it.

In order to fix this you have to make it so that the Explorer either has Mounted Brave art assigned to it or you make it so the Natives can not use the Explorer.


If your New Profession is not displayed correctly under the default code, you can use this mod to fix that.

~Cheers
 

Attachments

  • 1aUploadImage.jpg
    1aUploadImage.jpg
    20.4 KB · Views: 508
  • 1aUploadImage2.jpg
    1aUploadImage2.jpg
    98.3 KB · Views: 484
I hope that this is really a solution of the Professions Pedia problem.

This bug is not critical, but very unpleasant. I had a similar problem in the Professions Pedia section of the "1492: Global Colonization. Resource Pack" mod. I could fix this bug when made the modular loading for "1492: GC. RC." The Profession's Graphic for all professions was absolutely correct. However, when I added in the modular-loading mod just one new profession with a new graphic, as this bug appeared again.

I will check your fix on the weekend.
 
I hope that this is really a solution of the Professions Pedia problem.

This bug is not critical, but very unpleasant. I had a similar problem in the Professions Pedia section of the "1492: Global Colonization. Resource Pack" mod. I could fix this bug when made the modular loading for "1492: GC. RC." The Profession's Graphic for all professions was absolutely correct. However, when I added in the modular-loading mod just one new profession with a new graphic, as this bug appeared again.

I will check your fix on the weekend.

It will definately fix any issues you have with Professions Pedia as you can directly command the Pedia code what Unit to use for any given profession. It could however eventually mutate to have a mind of its own and then decide what it feels is the best unit, for that I have no solution except to unplug the system and slowly walk away. :lol:
 
I tested your fix some hours first with one of my mods (I combined two mods and compiled a new dll file), then with your mod included in the pro_pedia_fix.rar.

Conclusion: this fix does not work in both cases.

First of all, your example with Colonist is not correct because you have the same number of units/professions.

I added one new unit/profession in your Professions Pedia Fix/Tutorial mod and immediately had the same Profession Pedia error. New unit looks correct in the game and in Unit Pedia. However, in the Profession Pedia section I have a wrong image.

This error is appear if I use this tag
Code:
<ArtTagUnitClass>NONE</ArtTagUnitClass>
or this one
Code:
          <ArtTagUnitClass>UNITCLASS_VETERAN</ArtTagUnitClass>

The images I have here are different but they are wrong in both cases.

Probably this information could help you somehow:
I found that the image in the Profession Pedia section is depend on order of my unit in the Civ4UnitClassInfo.xml. I mean where I added my new unit: in the beginning or in the end of the Civ4UnitClassInfo.xml file. I observed this feature some months ago and sometimes successfully could catch correct position for my new UNITCLASS. But only sometimes.

However, now we are testing the fix that could prevent such graphics bug. Unfortunately, this Profession Pedia problem is much more complicated....

Additional remark:

Very often "Armed Brave" and "Armed Mounted Brave" have the same Profession Pedia error. Both this professions are absent in the Civ4UnitClassInfo.xml file. However, the data from this file is used in your tag

Code:
          <ArtTagUnitClass>[B]UNITCLASS_[/B]VETERAN</ArtTagUnitClass>
 
Ahh, the problem is it only works if the Unit has its own unique Class. As for the Natives they are just unqiue units so they don't have a class of their own. I'll see if I can find a work around. One way to work around this for sure is to create a new unit with the base art being the art of your New Profession, make it <bGraphicalOnly>1</bGraphicalOnly> then make sure its <DefaultProfession> is set to your New Profession.

Edit: Also, for the Natives if you create a new Unit that is not allowed by the natives make sure you disallow the Unit in the CvCivilizationinfos.
 
Ahh, the problem is it only works if the Unit has its own unique Class. As for the Natives they are just unqiue units so they don't have a class of their own. I'll see if I can find a work around. One way to work around this for sure is to create a new unit with the base art being the art of your New Profession, make it <bGraphicalOnly>1</bGraphicalOnly> then make sure its <DefaultProfession> is set to your New Profession.

Edit: Also, for the Natives if you create a new Unit that is not allowed by the natives make sure you disallow the Unit in the CvCivilizationinfos.

I just tested your variant in your mod.

I made a new unit:

Unit: Governor General
Profession: Governor General
UNITCLASS_GOVERNOR_GENERAL
Graphics only for this unit
<DefaultProfession>UNITCLASS_GOVERNOR_GENERAL</DefaultProfession>
<bGraphicalOnly>1</bGraphicalOnly>

Result: error on this unit (treasure instead of GG), plus three errors on Armed Brave, Armed Mounted Brave and Mounted Brave.

P.S. Looks that Natives are responsible somehow for such situation.

Addition:

Edit: Also, for the Natives if you create a new Unit that is not allowed by the natives make sure you disallow the Unit in the CvCivilizationinfos.

When I added for all Natives in the CvCivilizationinfos

Code:
<UnitClassType>UNITCLASS_GOVERNOR_GENERAL</UnitClassType>
<UnitType>NONE</UnitType>
the images of all natives in Profession Pedia section are correct. But a new unit is again wrong. The same TREASURE instead GOVERNOR_GENERAL.
 
I just tested your variant in your mod.

I made a new unit:

Unit: Governor General
Profession: Governor General
UNITCLASS_GOVERNOR_GENERAL
Graphics only for this unit
<DefaultProfession>UNITCLASS_GOVERNOR_GENERAL</DefaultProfession>
<bGraphicalOnly>1</bGraphicalOnly>

Result: error on this unit (treasure instead of GG), plus three errors on Armed Brave, Armed Mounted Brave and Mounted Brave.

P.S. Looks that Natives are responsible somehow for such situation.

<DefaultProfession>UNITCLASS_GOVERNOR_GENERAL</DefaultProfession> needs to be a Profession not a uniclass.


Also, to get Natives to Appear right in the Professions you have to edit the CvCivilizationInfos and make the New unit not allowed by the all Natives. If the New unit has a combat change it could very well over ride the Native Units.

Example 1:

I created a new unit called Explorer. The Code runs through all the Civilizations starting with England. If it finds a Civilization that allows the Unit it choses that Civilization to select the Units from as you have to have a unit to attach to the displayed Profession. It this case it finds England. After it finds a Civilization it then runs through the list of that Civilizations Units checking for the one unit with the Highest number of Free Promotions, which in England's case will be the Veteran Unit. The code then gets a Veteran Unit from England and gives it the Explorer Profession.

Now you will have errors if Veteran Unit does not have an art file assigned for Explorer.


Example 2:

Ok, now we are Looking for a unit to display the "Mounted Brave" Profession. As before the code checks to see if there is a valid Civilization which will be the first Civilization it comes to that allows this profession namely, "CIVILIZATION_TUPI". If then runs through the list of all the Units that the Tupi's can have. In our above example if the Explorer had more Free Promotions than the UNIT_NATIVE (the only unit a native is allowed to have basically) or the Explorer is the last Unit it checks then the Explorer unit will be the Unit the Code selects. In this case it will cause an error cause the Explorer unit has no Mounted Brave profession art assigned to it.

In order to fix this you have to make it so that the Explorer either has Mounted Brave art assigned to it or you make it so the Natives can not use the Explorer.

I was going to explain all this in the first post but I totally forgot.
 
<DefaultProfession>UNITCLASS_GOVERNOR_GENERAL</DefaultProfession> needs to be a Profession not a uniclass.
I have exactly such line in CIV4UnitInfos.xml file in the section for UNIT_GOVERNOR_GENERAL.

Also, to get Natives to Appear right in the Professions you have to edit the CvCivilizationInfos and make the New unit not allowed by the all Natives. If the New unit has a combat change it could very well over ride the Native Units.

Example 1:

I created a new unit called Explorer. The Code runs through all the Civilizations starting with England. If it finds a Civilization that allows the Unit it choses that Civilization to select the Units from as you have to have a unit to attach to the displayed Profession. It this case it finds England. After it finds a Civilization it then runs through the list of that Civilizations Units checking for the one unit with the Highest number of Free Promotions, which in England's case will be the Veteran Unit. The code then gets a Veteran Unit from England and gives it the Explorer Profession.

Now you will have errors if Veteran Unit does not have an art file assigned for Explorer.


Example 2:

Ok, now we are Looking for a unit to display the "Mounted Brave" Profession. As before the code checks to see if there is a valid Civilization which will be the first Civilization it comes to that allows this profession namely, "CIVILIZATION_TUPI". If then runs through the list of all the Units that the Tupi's can have. In our above example if the Explorer had more Free Promotions than the UNIT_NATIVE (the only unit a native is allowed to have basically) or the Explorer is the last Unit it checks then the Explorer unit will be the Unit the Code selects. In this case it will cause an error cause the Explorer unit has no Mounted Brave profession art assigned to it.

In order to fix this you have to make it so that the Explorer either has Mounted Brave art assigned to it or you make it so the Natives can not use the Explorer.

I was going to explain all this in the first post but I totally forgot.

I tested variant with Natives. When I added for all Natives in the CvCivilizationinfos

Code:
<UnitClassType>UNITCLASS_GOVERNOR_GENERAL</UnitClassType>
<UnitType>NONE</UnitType>
the images of all natives in Profession Pedia section are correct. But a new unit is again wrong. The same TREASURE instead GOVERNOR_GENERAL.

PS. Your unit disappers from Unit Pedia section if you use this tag
Code:
<bGraphicalOnly>1</bGraphicalOnly>

Addition: Each time you have a new image for your new unit, when you change the position of your unit in the CIV4UnitClass file. I cannot catch the logic of changes...
 
I have exactly such line in CIV4UnitInfos.xml file in the section for UNIT_GOVERNOR_GENERAL.



I tested variant with Natives. When I added for all Natives in the CvCivilizationinfos

Code:
<UnitClassType>UNITCLASS_GOVERNOR_GENERAL</UnitClassType>
<UnitType>NONE</UnitType>
the images of all natives in Profession Pedia section are correct. But a new unit is again wrong. The same TREASURE instead GOVERNOR_GENERAL.

PS. Your unit disappers from Unit Pedia section if you use this tag
Code:
<bGraphicalOnly>1</bGraphicalOnly>

Right, if you set the Unit as Graphical Only it will not appear in the Units list. This is ok for units you create just to display a Profession.

I am not understanding what exactly is the "TREASURE"? Are you saying that the "TREASURE" unit is appearing instead of the "GOVERNOR_GENERAL"?

EDIT: Just run through the Code I explained for your New Unit and Profession. I am thinking of an easier way to do this. It seems that I Could add a check in the Profession and Units for "AllowNatives" and "AllowEurope" and "AllowColonial". That way when the code checks to see if a Unit or Profession is valid you can have it set so that it will automaticly skip over the Unit or Profession depending on what values you set for it in the XML. I believe this will work just fine, if so I'll update this mod with theses new Attributes in the XML that way you want have to worry about having adjust the CvCivilizationInfos every single time you add a new unit.
 
I am not understanding what exactly is the "TREASURE"? Are you saying that the "TREASURE" unit is appearing instead of the "GOVERNOR_GENERAL"?

Exactly!

Each time I have a new image for my new unit, when I change the position of my unit in the CIV4UnitClass file. I cannot catch the logic of these changes..
 
Exactly!

Each time I have a new image for my new unit, when I change the position of my unit in the CIV4UnitClass file. I cannot catch the logic of these changes..

That is because the Code picks up the First Unit that fits what it is looking for. So, you have to set it up so that it skips over all the wrong units and choses the right one. Post the XML of the New Profession you are adding and they New Unit and I'll look it over.
 
I just posted version 0.3, please check it out and test it for me. I think this should for once and for all solve this little problem for any future mods.
Testing.....

First results are very discrepant.

I found only one combination where all Profession Pedia section is free of errors. This combination:
1. CIV4UnitClassInfos.xml
new UNITCLASS_GOVERNOR_GENERAL must be the first in the list
2. CIV4ProfessionInfos.xml
new PROFESSION_GOVERNOR_GENERAL mst be the first in the list.

All another positions in the list => error.

Such feature I used in "1492: GC. RP" when I added new professions. All was OK up to some number of new professions, then I had error. Unfortunately I lost the point, where this bug appeared for the first time.

continue testing....
 
Testing.....

First results are very discrepant.

I found only one combination where all Profession Pedia section is free of errors. This combination:
1. CIV4UnitClassInfos.xml
new UNITCLASS_GOVERNOR_GENERAL must be the first in the list
2. CIV4ProfessionInfos.xml
new PROFESSION_GOVERNOR_GENERAL mst be the first in the list.

All another positions in the list => error.

Such feature I used in "1492: GC. RP" when I added new professions. All was OK up to some number of new professions, then I had error. Unfortunately I lost the point, where this bug appeared for the first time.

continue testing....

In the CvUnitInfos for the Unit_Governor_General it should say:

<DefaultProfession>PROFESSION_GOVERNOR_GENERAL </DefaultProfession>

The code will always assign the Profession graphic to the unit that has the Profession set as its default.
 
In the CvUnitInfos for the Unit_Governor_General it should say:

<DefaultProfession>PROFESSION_GOVERNOR_GENERAL </DefaultProfession>

The code will always assign the Profession graphic to the unit that has the Profession set as its default.
I have such line in the CIV4UnitInfos.xml file for GOVERNOR_GENERAL. Plus I added similar lines for all units. After that your mod (v.0.3) is working correctly.

However, when I apply your fix to Slavery mod, for instance, I have many graphic errors in the Profession Pedia section. It's funny, but GOVERNOR_GENERAL looks correctly, but practically all other Professions have wrong images.

Maybe information about each unit/profession must be included in CIV4UnitClassInfos.xml, Civ4UnitInfos.xml and Civ4ProfessionInfos.xml files. At least Slaves are absent in Civ4ProfessionInfos.xml and they give such bug in my mod.
 
I have such line in the CIV4UnitInfos.xml file for GOVERNOR_GENERAL. Plus I added similar lines for all units. After that your mod (v.0.3) is working correctly.

However, when I apply your fix to Slavery mod, for instance, I have many graphic errors in the Profession Pedia section. It's funny, but GOVERNOR_GENERAL looks correctly, but practically all other Professions have wrong images.

Maybe information about each unit/profession must be included in CIV4UnitClassInfos.xml, Civ4UnitInfos.xml and Civ4ProfessionInfos.xml files. At least Slaves are absent in Civ4ProfessionInfos.xml and they give such bug in my mod.

Each new mod you work on with have to be setup to work with this Pedia Fix mod. You can't just plot it into a mod and have it all work correctly. You will have to adjust things regardless, but this mod gives you more tools to work with so adjusting things will be a lot easier.
 
Each new mod you work on with have to be setup to work with this Pedia Fix mod. You can't just plot it into a mod and have it all work correctly. You will have to adjust things regardless, but this mod gives you more tools to work with so adjusting things will be a lot easier.
Absolutely agree. You added here a number of additional parameters that permit to fix Profession Pedia bug for a new unit, as example in your Professions Pedia Fix/Tutorial mod. Exactly as a tool I will use these tests when new units/professions will be added.

Thank you very much for your work.
 
Top Bottom