Making a Wonder a prereq for another building

Velnik

Chieftain
Joined
Dec 29, 2014
Messages
3
I was wondering if I could get a little help. I am trying to make a Wonder as a pre-req for a different building that can be built in any/all cities once the wonder is built.

I am experiencing two problems so far.

One is, once I build the wonder, I can't seem to get the dependent building to stay in the build queue and complete building. I can force it by quick building, but I can't figure out why it won't build normally.

The second issue is, once I have built the dependent building once, I can't build it in any other cities.

Any suggestions would be appreciated.

Below is the code I'm trying to use for testing this to see if it is even possible.


Spoiler :

<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 12/29/14 21:06:32 -->
<GameData>
<BuildingClasses>
<Row>
<Type>BUILDINGCLASS_WONDER</Type>
<DefaultBuilding>BUILDING_WONDER</DefaultBuilding>
<Description>TXT_KEY_BUILDING_WONDER</Description>
<MaxGlobalInstances>1</MaxGlobalInstances>
</Row>
<Row>
<Type>BUILDINGCLASS_WONDERDEPENDENT</Type>
<DefaultBuilding>BUILDING_WONDERDEPENDENT</DefaultBuilding>
<Description>TXT_KEY_BUILDING_WONDERDEPENDENT</Description>
</Row>
</BuildingClasses>

<Buildings>
<Row>
<Type>BUILDING_WONDER</Type>
<BuildingClass>BUILDINGCLASS_WONDER</BuildingClass>
<Cost>40</Cost>
<ConquestProbability>0</ConquestProbability>
<PrereqTech>TECH_HABITATION</PrereqTech>
<EnergyMaintenance>1</EnergyMaintenance>
<Description>TXT_KEY_BUILDING_WONDER_DESC</Description>
<Civilopedia>TXT_KEY_BUILDING_WONDER_PEDIA</Civilopedia>
<ArtDefineTag>ART_DEF_BUILDING_RELIC</ArtDefineTag>
<ExtraCityHitPoints>10</ExtraCityHitPoints>
<Defense>200</Defense>
<IconAtlas>BW_ATLAS_1</IconAtlas>
<PortraitIndex>8</PortraitIndex>
<Health>5</Health>
</Row>
<Row>
<Type>BUILDING_WONDERDEPENDENT</Type>
<BuildingClass>BUILDINGCLASS_WONDERDEPENDENT</BuildingClass>
<Cost>40</Cost>
<ConquestProbability>0</ConquestProbability>
<PrereqTech>TECH_HABITATION</PrereqTech>
<EnergyMaintenance>1</EnergyMaintenance>
<Description>TXT_KEY_BUILDING_WONDERDEPENDENT_DESC</Description>
<Civilopedia>TXT_KEY_BUILDING_WONDERDEPENDENT_PEDIA</Civilopedia>
<ArtDefineTag>ART_DEF_BUILDING_RELIC</ArtDefineTag>
<IconAtlas>BW_ATLAS_1</IconAtlas>
<PortraitIndex>8</PortraitIndex>
</Row>
</Buildings>

<Building_PrereqBuildingClasses>
<Row>
<BuildingType>BUILDING_WONDERDEPENDENT</BuildingType>
<BuildingClassType>BUILDINGCLASS_WONDER</BuildingClassType>
<NumBuildingNeeded>1</NumBuildingNeeded>
</Row>
</Building_PrereqBuildingClasses>
</GameData>
 
It could be that the C code that backs building prereqs has deprecated and no longer behaves as expected. Many of the game's database tables and entries are no longer used by BE and it's hit and miss which ones still exhibit usable behaviors.

What you may want to look into is the lua GameEvent "CityCanConstruct". It's detailed here with a half decent example:

http://modiki.civfanatics.com/index.php/GameEvents.CityCanConstruct_(Civ5_API)

I can't guarantee that this hasn't deprecated either, but it maybe worth a shot if you can or want to learn how to write LUA. It gives you a lot more fine control over who and what can build which buildings.
 
I don't have access to the game files right now but there were two building prereq tables in civ5 (that were carried over to BE). One was used to link Library->University->Public School->Lab such that you couldn't build a university until you built a library. The other table was used to limit the ability to build National Wonders until every city had a specific building. For example, requiring a library in all cities before you could build the National College.

I think the table you tried was the National Wonder table because it had the entry for numBuildingNeeded (which would be -1 in the case of National Wonders and was never used in civ5 for anything other than -1).

Ultimately, if you want to allow whoever owns the wonder to have to be able to build the special building in all cities they own, found or capture than you won't be able to achieve that with just XML. You'll need to use the player:CanConstruct event (but don't worry, it will only be 3 lines of lua tops, it is easy).

The CanConstruct event allows you to put additional restrictions on when a player is allows to build a specific building. In your case you want to limit it so only people who own the wonder can build the special building.

Try the following (untested) code:
Code:
function WonderRequiredRestriction(playerID, buildingID)
  if(buildingID ~= GameInfoTypes["BUILDING_WONDERDEPENDENT"]) then
    return true;
  end

  if(player:GetBuildingClassCount(GameInfoTypes["BUILDINGCLASS_WONDER"]) > 0) then
    return true;
  end

  return false;
end
GameEvents.PlayerCanConstruct.Add(WonderRequiredRestriction);
 
Based on what you both are saying, it looks like I will need to learn LUA in order to get what I need. If it adds that much additional fine control, it will probably make things easier in the long run for me. I have a (probably over reaching) goal in mind for a big mod, but I still have much to learn.

So, I have a couple of additional questions for you:

1. Is there a good resource for learning LUA, particularly with regards to how it is used in CivBE?

2. How do I get a LUA script to run with a mod? It doesn't seem to work the same way getting an XML file to work with the OnModActivated Action.
 
Do you have any previous coding experience?

There isn't much of a one-stop shop for Lua due to how versatile it is. Your best bet is to look for mods which do similar things and reverse-engineer them. Now there are a lot more mods for Civ5 than BE, so you'd probably need to start there. Depending on what the code is intended for, you'll have to run them in different ways as well. It's a tough nut to crack and gauging your previous experience would be helpful.
 
My coding experience is pretty much non-existent, unfortunately. I did a bit of very basic HTML and scratched the surface of PHP for a personal website a few years ago, and that was about it.

Based on the bit of code supplied by Machiavelli24, it looks almost like LUA is an if/then language. If that is the case, I just need to become familiar with the tags the game uses/recognizes. Rather, I'm hoping it is that 'simple.'

I think I will take your suggestion and start with looking at Civ5 mods to see if that might get me a better grasp on how to move forward. I might check out some retailers and see if there isn't a LUA for dummies type book as well.
 
Having done no research and I am just guessing. Cant you build a wonder that grants a free tech, This would allow you to create a new technology that would allow a new building to be built?

Just checked ... A building can grant a number of technologies not a specific technology however if you put this below your building table and place the desired wonder information then it should do the trick.

<Table name="Building_PrereqBuildingClasses">
<Column name="BuildingType" type="text" reference="Buildings(Type)"/>
<Column name="BuildingClassType" type="text" reference="BuildingClasses(Type)"/>
<Column name="NumBuildingNeeded" type="integer"/>
</Table>
 
1. Is there a good resource for learning LUA, particularly with regards to how it is used in CivBE?
The difficulty of learning to use Lua in BE modding is determined mostly by the difficulty of learning the basics of programming, which your past experience with PHP would cover.

There is not a very good BE specific lua tutorial currently that I'm aware of.

2. How do I get a LUA script to run with a mod? It doesn't seem to work the same way getting an XML file to work with the OnModActivated Action.
Lua files (that aren't replacing an existing Lua file) are added via the content tab (rather than the action tab). Lua files are added as part of InGameUIAddin (even if they aren't part of the "UI".
-----------------------
Having done no research and I am just guessing. Cant you build a wonder that grants a free tech, This would allow you to create a new technology that would allow a new building to be built?
If you use the XML freeTech than when the player gets a wonder the player will get a free technology of their choice. It is possible to use Lua to detect when a specific building is finished and assign the player a specific technology. However, doing that just to allow a player to build a different building is more roundabout than just using the playerCanConstruct event.
 
Machiavelli just repeating what I stated there ... but in a long winded way, "Just checked ... A building can grant a number of technologies not a specific technology".

the code above states a required number of buildings across your civilisation before you can build something, it is not city specific and would allow any city to build the building after the stated prerequisite building had been constructed (ie a wonder), not sure it that is what you were after, the city specific thing or not.

The code you have used looks like it should work however it is entirely possible that it is leftover code from Civ5 (as this was in Civ5 buildings.xml) and no longer has the scripts to use it ... that said I don't know why anyone would remove the scripts and not the <Building_PrereqBuildingClasses> table but that's Fraxis for you. This may allow you to find the scripts used in previous games and copy paste. luckily all of the file contents and information you need is online, a lot of it on this website.

I think Whoward69 put it best "Welcome to the wonderful world of "Firaxis didn't need it, so they didn't code it" and "Jumping through hoops"", for a game that is meant to be modder friendly this is a bad thing.



As for creating technologies, it can be done however it is complicated as the technology web makes things a little more difficult to place an object into a position (that has to be stated) without bumping into anything else or reconfiguring the rest of the technology tree.

The display representation of each technology within the web has a set size, as do the icons within it (hence why if you add buildings, units ect to a technology it may not show them on the tech web) each technology has been placed and in much the same way the technology may not appear due to the placement of the technology, I understand that it is possible to include a technology at the fringes of the tech web and have it appear or you can reorganise the entire tech web, however these methods (especially the latter) could cause conflict with other mods if they alter the tech web. I haven't looked at it much but I have seen a mod with additional technologies on steam, I didn't download it or even register the name of it, sorry.
 
Back
Top Bottom