City-State Settlers

CivOasis

Ahuizotl
Joined
Jun 22, 2011
Messages
3,005
Location
Sawaiki
Ok, so I would like to make a mod that brings City-States more in line with what I think they should be, "minor civilizations" (as the xml calls them). For this purpose, I would like to enable settler unit (probably a unique one for CS's only). So, I have a few questions.
Is it even possible to give CS's settlers? (If so, how, I haven't beenable to find how that was disabled)
Is it possible to restrict the number of units each civ can build? I know its possible by world, but I see flaws with my plan in that regard...
The goal would be a way to add in civilizations that don't have enough information (leaders, units, cities, etc.) to make a full civ out them.

Unrelated to the above posts, but still on the subject of CS's and settlers, I recently saw a bizarre incident in which a CS built a settler, then tried to attack a pikeman with it. Any idea how that happened?
 
Is it even possible to give CS's settlers? (If so, how, I haven't beenable to find how that was disabled)

You can't gift them settlers, but that's only because the unit gift system excludes noncombat units. If you're writing a Lua function, there's no problem giving them settlers that way.

Technically, the only reasons the minor civs don't build settlers of their own:
1> the FLAVOR_EXPANSION is set to 0 for all minor civs.
2> In the City AI Strategies table, the "Capital Need Settler" strategy has the <NoMinorCivs> flag set to true. The same is true for many entries in the Economic AI table, things like ECONOMICAISTRATEGY_FOUND_CITY. So the Minor civs never execute the AI algorithms that trigger city founding, but that'd be really easy to change.

Now, there's probably some other override in the engine, something that explains their tendency to raze conquered cities, since I didn't see that in any of the files I looked through.

Is it possible to restrict the number of units each civ can build? I know its possible by world, but I see flaws with my plan in that regard...

It's possible to restrict the number of units of a type that a civ has AT THE MOMENT, by adjusting the MaxTeamInstances and MaxPlayerInstances variables in the unit class definition. In my own mod, I have two "Hero"-type units that you can only have one of per empire, and the spaceship parts also work this way.
Unfortunately, that's a function of unit class, not unit, so you'd need to create an entirely new unit class, excluded from all non-minor civs, and an entirely new unit type. It's not a small amount of work.

If you're trying to restrict the number that a civ can EVER build, that's a lot harder. I suppose you could create a Lua function that counts them, and if the AI produces more than a certain number you award that AI a certain custom-made tech. Then you set the ObsoleteTech for the unit to that tech, so that awarding the tech removes the unit from the build list.

Or, if you don't want to be that exact, just make the minor-civ Settler unit type (mentioned above) go obsolete at, say, Navigation. Better yet, also make its PrereqTech be something in the Classical Era, so that the players will be settling their second and third cities well before the minor civs do.

Now, let's talk downsides:
1> The minor civs get a large production, gold, and research bonus to compensate for the fact that they'll only ever have 1 city, no railroads to get production boosts, etc.
2> Minor civs and barbarians gain techs through a "stealing" mechanism, where the more major civs that have a tech, the higher chance a minor gets it. So if you try to turn them into a real empire, they'll get a huge bonus on this.
3> Minor civs don't have city name lists, so you'll have a lot of writing to do.
4> Minor civs don't get Policies, ever.
5> Minor civs don't use the resources they harvest; those are placed into a pool for their allies to claim. City-states can only ever produce resourceless units, and don't ever get the benefit of luxuries.
6> Minors can't build Wonders, including National Wonders, although this is a by-type override so you could re-enable those easily enough if you wanted.

Minors also can't make nukes or Carriers (and I mean that even if #5 above wasn't a problem, these types are explicitly banned), and have the usual diplomacy issues.

Unrelated to the above posts, but still on the subject of CS's and settlers, I recently saw a bizarre incident in which a CS built a settler, then tried to attack a pikeman with it. Any idea how that happened?

Well, since the AI doesn't have access to the usual settler-based AI strategies (see above), it might have fallen back on the ones that it DID have... like the attack AI. Other than that, no idea.
 
About units restriction for each civilization there are the "new" game events :
GameEvents.PlayerCanTrain(playerID, unitTypeID)
GameEvents.CityCanTrain(ownerID, cityID, unitTypeID)
 
True, there is that. I haven't looked into those new Lua events in much detail, but if they work like I think they should then they'd be just fine for this, as long as you could come up with a coherent set of logical checks to do what you want.

The real question is, what do you want? Do you want to limit how many Settlers the minor civs EVER make, or just how fast they expand once they do unlock their settler unit? Do you want these minor civs to be a serious competitor for the major civs, or just a bit less of a speed bump than they are now? Why does Hawaii have Interstate highways? And what other limits would you want to put on these minor civs to keep them from taking over the world?
 
Basically, I want to make the minor civs to range from the small, current city-state style, to the relatively large (~4-5 cities, which might make them a threat to weaker, neighboring civs, if attacked). So I would like to limit the number of settlers they ever make, so that they cannot possibly attempt to expand past their list of cities. I would probably obsolete their settlers after a certain point (navigation?), so that they couldn't expand over oceans. At the moment, if you're not going for a diplo win, they're good allies for the benefits they provide, but they aren't exactly anything that you could consider a threat, or a tool for war, regardless of the size of your civ.

In summary, the mod would make city-states into smaller civs, actually feasibly capable of taking a city without help, and be slightly more of a pain to conquer. Outside of the military and resource applications, I think it might actually affect the patronage policy branch (one of the policies gives a science percentage, which might be slightly higher with more cities).

"Does this appear unbalanced?" and "would the AI know how to deal with it?" are what the major questions are, of course, as with any mod.
 
Ok, so, I plan on actually making this mod, from scratch.
For the beta, I would like to disable all existing CS's, and replace them with custom ones, which would all have the same number of max settlers/cities (5).
How would I go about doing this?
 
Ok, so, I plan on actually making this mod, from scratch.
For the beta, I would like to disable all existing CS's, and replace them with custom ones, which would all have the same number of max settlers/cities (5).
How would I go about doing this?

Delete the existing city-states, and then add new ones using the old code as a template.
 
Perhaps I should be more clear.
1) How do I disable city-states, when using this mod?
2) How do I enable settlers for city-states?
 
Perhaps I should be more clear.
1) How do I disable city-states, when using this mod?
2) How do I enable settlers for city-states?

Code:
<MinorCivilizations>
   <Delete Type="MINOR_CIV_CITYSTATENAME"/>
   <Row>
       <Type>MINOR_CIV_NEWCITYSTATE</Type>
       <Description></Description>
       <OtherTagsHere>....
   </Row>
</MinorCivilizations>

To enable settlers, I'd go and delete the UnitClassOverride for CIVILIZATION_MINOR for settlers in the Unit_ClassOverrides part of the Civilizations.xml file.
 
Code:
To enable settlers, I'd go and delete the UnitClassOverride for CIVILIZATION_MINOR for settlers in the Unit_ClassOverrides part of the Civilizations.xml file.[/QUOTE]

Without going into the source, how's that possible?
Sorry for my cluelessness, data on how to remove things is a little vague..
 
It's not actually in there? These are the four overrides for minor civs:
Code:
<CivilizationType>CIVILIZATION_MINOR</CivilizationType> 
  <UnitClassType>UNITCLASS_SCOUT</UnitClassType> 
  <UnitType /> 
  </Row>
- <Row>
  <CivilizationType>CIVILIZATION_MINOR</CivilizationType> 
  <UnitClassType>UNITCLASS_ATOMIC_BOMB</UnitClassType> 
  <UnitType /> 
  </Row>
- <Row>
  <CivilizationType>CIVILIZATION_MINOR</CivilizationType> 
  <UnitClassType>UNITCLASS_NUCLEAR_MISSILE</UnitClassType> 
  <UnitType /> 
  </Row>
- <Row>
  <CivilizationType>CIVILIZATION_MINOR</CivilizationType> 
  <UnitClassType>UNITCLASS_CARRIER</UnitClassType> 
  <UnitType /> 
  </Row>
 
Putmalk said:
To enable settlers, I'd go and delete the UnitClassOverride for CIVILIZATION_MINOR for settlers in the Unit_ClassOverrides part of the Civilizations.xml file.

As I mentioned above, Settlers aren't banned from the city-state civ, so there's no override to delete. They're banned through the AIs available to the Minor civiization; it simply thinks it has no valid paths to building a Settler, so it doesn't.

The problem is that if you give it those AIs, then the question becomes, how exactly can this work? If Geneva builds a Settler and places it somewhere, it'll create, say, Copenhagen. Since all city-states share a single civilization type, it'd create all sorts of screwiness if they could add new cities. So that's something you'd have to figure out.
 
CS's aren't all the same civ type, just checked the XML on that one.
How would you give a civ the AI, though?
 
5> Minor civs don't use the resources they harvest; those are placed into a pool for their allies to claim. City-states can only ever produce resourceless units, and don't ever get the benefit of luxuries.

That's not true, I've seen them building units that require strategic resources - Swordsmen, Chariots etc. It seems they can use the resources for themselves and at the same time give them to their allies.
 
My mistake then, I apologize.
 
I wanted to achieve the same result in my mod - city-states as minor civs with multiple cities, and I found a solution. I couldn't find a way to force them to use settlers, so I just made a LUA script that creates additional cities for them. It checks for the best (in AI's opinion) spot to found a city, and then places a city there. Here is a fragment of my script that creates these cities (player is the ID of a minor civ):

Code:
local iW, iH = Map.GetGridSize();
local max = 0;
local max_x = -1;
local max_y = -1;

for y = 0, iH - 1 do
	for x = 0, iW - 1 do
		local v = player:AI_foundValue (x,y);
		if v > max then
			max = v;
			max_x = x;
			max_y = y;
		end
	end
end

if max_x > -1 then
	player:Found (max_x,max_y);
end

It's not a complete LUA function, only the fragment that creates the cities. I haven't posted my entire LUA function because it does other things too, which would be confusing. Contact me if you have problems with implementing it into your mod.

Notes:

1. Usually the new city appears close to the existing ones of that civ, but sometimes it's quite far. If you want to avoid this, you need to create additional checks if the tile is not too far away. It also allows them to found on another continent before Optics.

2. Since they don't have names defined for additional cities, they are called simply 'City'. Adding more city names to the XML (MinorCivilization_CityNames) solves this problem.
 
Like this attachment?
It's just a work in progress, wanted to make sure I was doing the right thing so far.
By the way, what're the limits to that lua code? How frequent, how many, etc?
Also, how do you add the lua code so that it works? (I.E., onmodactivated for xml)
 

Attachments

Like this attachment?
It's just a work in progress, wanted to make sure I was doing the right thing so far.
By the way, what're the limits to that lua code? How frequent, how many, etc?

The fragment that I posted earlier doesn't contain the conditions under which it will happen, also for this code to work you need to create a function and add it to an event. Here is a complete version (It differs from my own version and I haven't checked if it works, I could make a mistake). Of course you should set your own conditions, it's just an example.

Code:
function CreateCities ()
	for lnum=0, GameDefines.MAX_CIV_PLAYERS-1, 1 do
		local player=Players [lnum];
		if player:IsAlive () and player:IsMinorCiv () then
			-- the conditions for adding a city are set here
			if player:GetExcessHappiness () >= 5 and player:GetNumCities () > 0 and player:GetNumCities () < 4 then
				local iW, iH = Map.GetGridSize ();
				local max = 0;
				local max_x = -1;
				local max_y = -1;

				for y = 0, iH - 1 do
					for x = 0, iW - 1 do
						local v = player:AI_foundValue (x,y);
						if v > max then
							max = v;
							max_x = x;
							max_y = y;
						end
					end
				end

				if max_x > -1 then
					player:Found (max_x,max_y);
				end
			end
		end
	end
end
Events.ActivePlayerTurnStart.Add (CreateCities);

Also, how do you add the lua code so that it works? (I.E., onmodactivated for xml)

Go to the Content tab of the mod properties, click on "Add...", select the file, set type to "InGameUIAddin" (for LUA scripts that change the city view or diplomacy screen, or maps, you need to select the other types), enter a name, click on OK.
 
Two things:

1. I got this idea only yesterday, and it should be tested if it works properly. So far I've seen a barbarian unit standing inside a newly added minor civ city, but nothing bad happened - the barbarian left the city after several turns, and then got killed by the city's ranged attack.

2. The code above needs some additional conditions to prevent situations like a minor civ being at war with you, you capture a city from them, and a new city pops up immediately elsewhere. So it should create cities only at specific turns, or use some other conditions, like not working when the minor civ is at war. I haven't yet decided how I'll do it in my mod.
 
Well, I don't know anything about lua, so I can't set conditions atm. I'll test it, and see what happens.
 
Back
Top Bottom