Intro
The GovernmentsModified concept was an idea to allow for flexibility in the structure of the text file databases (for units, buildings, etc.)
Specifically it was an idea that the syntax of these be extended to allow for modifications to the individual records, based on government... so for a particular City Improvement, say a Granary, you might have another modified record (of the same improvement) for the Tyranny government... maybe making it cheaper, perhaps.
Using this system, you could make Factories more productive, but more polluting under Communism, or Tanks more powerful under Fascism, all without any SLIC, additional identifiers, or code.
I altered the db creation code, lexer definitions, and the base template class to achieve this.
Caveat... one small issue remains... I was having issues with dynamic resizing (growth) of a pointerlist array, using an optimized algorithm. I used a workaround, since I was so close to completion, but it needs to be sorted to avoid a limited memory leak. Fixed.
Tracing code also needs to be removed. Fixed.
---
What is the syntax?
The following would be the standard defintion of the courthouse.
If you wished to have a courthouse that operated slightly differently under monarchy you'd do the following:
You should note that this is a modification to an existing record. There must be an record with the same name to allow for a modified record.
The syntax using the '>' character allows for multiple government types, separated by commas.
It also allows for alpha-numeric (no space) descriptions, which are ignored for purposes of parsing... so
is perfectly valid, and modifies the courthouse record, for the Monarchy and Theocracy govs. Invalid Governments are also ignored, at parsing.
There is an additional syntax that can be used within the record structure, that can be used instead of, or as well as, the above syntax...
It has been mentioned that there are only 64 buildings and 64 wonders. This is actually unrelated to the parser, and has to do with their storage and use within the city data.
The GovernmentsModified system ignores this limitation for the modified records. You can still only have 65 buildings, but each of those buildings can have as many modified governments as you need. Essentially the system increases the number of buildings available.
There was a suggestion for another syntax suggested a while back, but from my investigations, its impossible given the current lex definitions, would require a pretty thorough rewrite of the parser, plus would be much more costly in terms of access... something I wanted to avoid... however if a bison/flex pro would like to take a shot...
---
Code access
This whole system is only half the issue. The database records are accessed via 2 member functions... Get and Access. Get returns a const record, Access the record.
While it would be nice to just rewrite the existing Get and Access functions to access the government subrecords, we don't have the context of what government is applicable to do that.
I therefore made two overloaded functions...
which work alongside the existing
Notice the extra govIndex parameter. These are overloaded functions, so the existing functions can still be used.
Work we (or maybe just I ) need to do
None of the existing record access in the code (1700 hundred instances of ->Get( and ->Access(, not all of which are applicable,) use the new method... so they need to be changed...
This, however, isn't complicated... just a lot of repetition.
Here's an example of a couple of changes, that I used to test that the system was working fine...
The GovernmentsModified concept was an idea to allow for flexibility in the structure of the text file databases (for units, buildings, etc.)
Specifically it was an idea that the syntax of these be extended to allow for modifications to the individual records, based on government... so for a particular City Improvement, say a Granary, you might have another modified record (of the same improvement) for the Tyranny government... maybe making it cheaper, perhaps.
Using this system, you could make Factories more productive, but more polluting under Communism, or Tanks more powerful under Fascism, all without any SLIC, additional identifiers, or code.
I altered the db creation code, lexer definitions, and the base template class to achieve this.
---
What is the syntax?
The following would be the standard defintion of the courthouse.
Code:
IMPROVE_COURTHOUSE { DefaultIcon ICON_IMPROVE_COURTHOUSE Description DESCRIPTION_IMPROVE_COURTHOUSE EnableAdvance ADVANCE_JURISPRUDENCE ProductionCost 330 Upkeep 1 LowerCrime -0.1 }
Code:
IMPROVE_COURTHOUSE { DefaultIcon ICON_IMPROVE_COURTHOUSE Description DESCRIPTION_IMPROVE_COURTHOUSE EnableAdvance ADVANCE_JURISPRUDENCE ProductionCost 330 Upkeep 1 LowerCrime -0.1 } IMPROVE_COURTHOUSE > GOVERNMENT_MONARCHY { DefaultIcon ICON_IMPROVE_COURTHOUSE Description DESCRIPTION_IMPROVE_COURTHOUSE EnableAdvance ADVANCE_JURISPRUDENCE ProductionCost 330 Upkeep 3 LowerCrime -0.3 HappyInc -1 }
The syntax using the '>' character allows for multiple government types, separated by commas.
It also allows for alpha-numeric (no space) descriptions, which are ignored for purposes of parsing... so
Code:
IMPROVE_COURTHOUSE > DecreasedCrime_and_Happy_HarshGovs , GOVERNMENT_MONARCHY, GOVERNMENT_THEOCRACY {
There is an additional syntax that can be used within the record structure, that can be used instead of, or as well as, the above syntax...
Code:
IMPROVE_COURTHOUSE { DefaultIcon ICON_IMPROVE_COURTHOUSE Description DESCRIPTION_IMPROVE_COURTHOUSE EnableAdvance ADVANCE_JURISPRUDENCE ProductionCost 330 Upkeep 1 LowerCrime -0.1 } IMPROVE_COURTHOUSE > Monarchy { DefaultIcon ICON_IMPROVE_COURTHOUSE Description DESCRIPTION_IMPROVE_COURTHOUSE EnableAdvance ADVANCE_JURISPRUDENCE [B][U]GovernmentsModified GOVERNMENT_MONARCHY[/U][/B] ProductionCost 330 Upkeep 3 LowerCrime -0.3 HappyInc -1 }
The GovernmentsModified system ignores this limitation for the modified records. You can still only have 65 buildings, but each of those buildings can have as many modified governments as you need. Essentially the system increases the number of buildings available.
There was a suggestion for another syntax suggested a while back, but from my investigations, its impossible given the current lex definitions, would require a pretty thorough rewrite of the parser, plus would be much more costly in terms of access... something I wanted to avoid... however if a bison/flex pro would like to take a shot...
---
Code access
This whole system is only half the issue. The database records are accessed via 2 member functions... Get and Access. Get returns a const record, Access the record.
While it would be nice to just rewrite the existing Get and Access functions to access the government subrecords, we don't have the context of what government is applicable to do that.
I therefore made two overloaded functions...
Code:
templateconst T *CTPDatabase ::Get(sint32 index,sint32 govIndex) and template T *CTPDatabase ::Access(sint32 index,sint32 govIndex)
Code:
templateconst T *CTPDatabase ::Get(sint32 index) and template T *CTPDatabase ::Access(sint32 index)
Work we (or maybe just I ) need to do
None of the existing record access in the code (1700 hundred instances of ->Get( and ->Access(, not all of which are applicable,) use the new method... so they need to be changed...
This, however, isn't complicated... just a lot of repetition.
Here's an example of a couple of changes, that I used to test that the system was working fine...
Code:
[B]Original (from CityData::CanBuildBuilding):[/B] const BuildingRecord* irec = g_theBuildingDB->Get(type); [B]New:[/B] const BuildingRecord* irec = g_theBuildingDB->Get(type,g_player[m_owner]->GetGovernmentType()); [i]and, from CityData::CanBuildUnit[/i] const UnitRecord *rec = g_theUnitDB->Get(type); [B]becomes[/B] const UnitRecord *rec = g_theUnitDB->Get(type,g_player[m_owner]->GetGovernmentType());
Comment