[BtS] JUnitTileLimit

Jeckel

Great Reverend
Joined
Nov 16, 2005
Messages
1,637
Location
Peoria, IL
This mod allows you to set the max number of units that can be on a single Tile.
One Max Units per Tile can be set for Land Tiles and another can be set for water Tiles.
Cities can be configured to allow a higher max number of units then other Tiles.
Building in Cities can also be configered to raise the max units for the city's Tile.
Bonuses, Features, and Improvements can also be configured to modify the max number of units allowed per Tile.
In addition, Units not have a configurable Size allowing larger Units to take up more room on the Tile.
The amount a Feature, Building, Improvement, ect modifies the Tile Unit Limit is displayed in their Pedia pages.
The Mod can be configured to ignore Land, Sea, and/or Air Units.

A Popup with Tile Space Data can be shown by hovering the pointer over a plot and pressing SHIFT + L keys.

Download: JUnitTileLimit Mod v0.520bts3.02

This mod is abandoned as I have done all this and much more in SDK with none of the lag this mod can suffer.
To find the current incarnation based on this mod go to this thread.
JUnitSpace Mod Thread
 
Nice one :). Was thinking that I wanted this mod even yesterday. Will AI know how to handle it? Could it be configured to allow larger armies on larger cities? Configures to have less armies in forrest/jungel?

Edit: Btw, maybe update your Thread Library?
 
Thanx Zuul. I didn't code in any extra AI intelligence, but I don't think it should break the AI at all as it should just see full tiles as impassable and pick another tile unless its attacking into it. I haven't had much time for testing, but I'll see if I can't run some autoplay games.

As for the extra features, I was planning to do the more troops on larger cities and I'm also planning to add some INI options that will let you designate buildings as and improvements to raise the max units on a tile.

But I hadn't thought of useing features to raise/decrease the allowed units in a tile. I will add that in to sense you brought it to my attention. :goodjob:

I have this on my todo list for this weekend, so look for the next update some time next week. :)
 
New version uploaded: v0.200

I removed the options for Forts as it is handled in the new features.

I added ini options that allow you to assign modifiers to Features and Improvements. For example, forts give a +5 to the tile max and fallout gives a -6.
 
I am working on the next version of the mod and it is going to upgrade the way cities modfy the max units per tile.

I am up in the air on how want to accomplish that and am looking for some input.

Here are some preliminary ideas I've had so far.
1) Take the amount of extra food the city is producing and make that the max units on the tile.

2) Same as above, but, instead of making the extra food the max units on the tile, I could add the extra food to the max units allowed on that tile.

3) The city's population is the max units allowed.

4) The city's population is added to the max units allowed.

5) The city's population is divided/multiplyed and set as the tiles max units.

6) The city's population is divided/multiplyed and added to the tiles max units.

7) An ini option system where you can list a population level and its unit max, ie LEVEL_1 = 2 and LEVEL_6 = 9, and will default to something when a level isn't listed in the ini file.

8) umm.. you have a suggestion? ;)

So what do yall think? :)
 
Good work :)

Maybe some unit, like a great commander could add to total allowed (better formations). Maybe not just have one unit allowed on a 1 city. Think on what happens when you take over a small city. Maybe the rest of the units will not have the citys bonuses or have someting like 3+citysize/2.

You should do some AI testing (easiest to lower the max alot). Maybe they just wait outside city trying to get in?
 
Hehe, I got inspired this morning and have coded up the next version and one of the main new features is the units have a configurable size so when totaling the number of units on a tile, a unit can cost just 1, more then 1, 0, or even a negative number. Units that have a negative size increase the total allowed units for that tile. Guess I must have been reading your mind Zuul. :lol:

I also got the City Building Limit Modifiers working, so, as it is in the default settings, Barracks gives +1 to the Max Units and Castle gives a +2.

I also broke the main config.ini file up into a few different files so it would be to much info in one file. It makes it a little cluttered in the Mod directory, but I am going to move the Modifier Config files into their own directory under the mod directory in the next version.

I've basicly got all the features I wanted, well except for the city stuff mentioned in my post above. I'm going to do some testing as Zuul suggests and get an idea how the AI handles these changes and I'm going to add the appropriate info the the right pedia pages and find an easy way to display the Tile Limit data on the mainscreen.

After that I'll package it up real nice and release a stable version. :)
 
And just to clarify, my current working version, v0.400, is linked in the OP. Don't know how long to the next beta version, but may be a few days. :)
 
I got some free time last night.. and this morning it seems.. so I made myself a busy little beaver and set to work coding the next few versions of the mod.

I am now at working v0.480, which is now linked in the OP.
The Change Log from last version v0.400 to this version v0.480 is in the following spoiler for those that are interested.
Spoiler :


v0.400
Added Unit Size.
Removed code and ini options to specificly exclude Workers and Settlers.

v0.410
Fixed glitch that didn't default to Default Unit Size if Size Modifiers equaled nothing.
Fixed glitch that check for City Buildings Modifiers on every Tile even if there was no City.
Fixed glitch that allowed Units with Size 0 or less to move into Tiles that had a Limit less then 1.
Reworked code to be more efficient for tiles with no units.
Added new ini option that controls if City Building Modifiers are cumulative or not.
Created a CvJUnitTileLimitUtils.py file.
Move all work code to CvJUnitTileLimitUtils.py file.
Reworked GameUtils.py code to use CvJUnitTileLimitUtils methods.

v0.420
Moved Modifier Config - Blah files to the Modifier Config Files directory.
Modified code to call ini files from the right directory.
Added UNITCLASS_TANK and UNITCLASS_MODERN_ARMOR to default Unit Sizes with Size 2.
Fixed glitch that used the Size of the moving Unit for all the Units on the MoveTo Tile.

v0.430
Added code and ini options for Terrain modifiers.

v0.440
Added Crowded and Uncrowded Promotion Buttons.
Modded Buildings Pedia Page code to show Tile Unit Limit Modifier data.
Modded Features Pedia Page code to show Tile Unit Limit Modifier data.
Modded Improvements Pedia Page code to show Tile Unit Limit Modifier data.
Modded Terrain Pedia Page code to show Tile Unit Limit Modifier data.
Modded Units Pedia Page code to show Size data.

v0.450
Fixed glitch sea movement mod now ignores Units loaded as Cargo.
Added 3 new ini options that allow Land, Sea, and/or Air Units to be ignored by the Mod's rules.
Changed ini option 'Default Max Units Per Tile' to 'Default Max Units Per Land Tile'.
Added new ini option 'Default Max Units Per Water Tile'.
Updated code to have seperate Tile Unit Limits for Land and Sea Tiles.
Added a simple example Scenario called JUnitTileLimit Test Map.
Added a TextInfos.xml to hold the TXT_KEY for the Test Map's description.

v0.460
Added code and ini options for Bonus modifiers.
Modded Bonus Pedia Page code to show Tile Unit Limit Modifier data.
Updated Test Map to have an example of Bonus Modifier.

v0.470
Added a Popup to display Tile Space Data.
Added Dr. Elmer Jiggle's CustomEventManger to activate the Tile Space Data Popup with the SHIFT-L keys.

v0.480
Added new ini option 'City Needs Free Space To Train Units'.
Updated code to stop or allow training of Units if the Unit Size is larger then the City Tile's Free Space.

Fixed a few glitches, modded the Pedia files to show Tile Unit Limit Modifiers, added Tile Unit Limit Modifier Config INI File for the Bonus Types, added a popup (SHIFT + L with cursor over a plot) to show the data for that plot, and many other features. :cool:

I also have noticed, and noted in the OP, a growing lag the first time you drag the move cursor over a plot. It seems the lag is gone when I drag the move cursor back over that plot until I select another Unit, then the new unit has the lag the first time its move cursor is dragged over a plot. I'm not all that surprised as 90 percent of the mod's code is ran in the cannotMove GameUtils method. I will do what I can to knock this lag down as I clean up and streamline the code. :D

As for the next working release I have decided to base the amount of extra space on a City Tile on the City's Culture Level. This seems to be the mechanic used to represent the size of the City. :king:

As a future plan, I am knocking around the idea of making the Size of Units a new tag in either the UnitClassInfo or the UnitInfo. If/when I do this SDK work I will also be able to depreciate the Tile Space Popup in favor of displaying the Tile Space info in the standard mouseover flying help text. :)
 
O Joy and Jubulation! I have solved the lag problem almost completly!

I got the 1-3 second lag per tile checked down to just under (and on occation a few miliseconds over) the persevable threshhold.

For those that are interested, the problem was I am using the unitCannotMoveInto GameUtils.py method and whenever the move cursor is dragged over a plot or a unit trys to move into a plot the SDK calls the unitCannotMoveInto method some 8-12 times.
So the code I added may only take a few hundred miliseconds to run, but you multiply that by 10 or so and that adds up to some noticable lag.
How I solved the problem is I store unitCannotMoveInto's argsList and the value that the method returns. Then the next time unitCannotMoveInto runs the first thing I do is see if argsList is the same as the argsList from the last time it ran. If it is the same I just return the same value. That way none of the mods acual code has to be run and there is no noticable lag. :cool:

I am going to finish up some last code clean up and then I will release a stable beta version for testing and value tweaking before I call the mod finished. :)
 
Ok, I got the code cleaned up and did a little more optimizing and to avoid lag on long drag and moves. I am now at Beta v0.520 from v0.480 as the last uploaded version.

The Change Log from last version to this one is in the following spoiler.
Spoiler :
v0.490
Changed ini option default for 'Enable Bonus Limit Modifiers' from True to False.
Changed ini option default for 'Enable Terrain Limit Modifiers' from True to False.
Added code, file, and ini options for City Culture Level modifiers.

v0.500
Fixed lagged caused by multiple SDK calls to unitCannotMoveInto.
Updated Test Map to better show examples of Culture Level Modifiers.

v0.510
Moved Pedia text to TextInfos.xml files.
Updated Pedia pages to call new TXT_KEYs.
Updated Pedia pages to use FontSymbols.MAP_CHAR as the Space Symbol.
Updated Pedia pages to only show Modifier data if Modifiers for the Page's Type are Enabled.
Fixed some glitches in the new Pedia pages code.
Moved the Size stat on the Unit Pedia page from placeSpecial to placeStats.
Updated the Tile Space Data popup to show data only for Types that are Enabled.

v0.520
Further decreased lag for multi-plot drag and move actions.


I have updated the OP link and the download page to have the latest v0.520. I really have all the features in that I think will be useful, and am going to start a round of AI testing to see how the changes are handled. In the few turns I have clicked through, the auto move seems to handle my units movements alright.

I know it is kinda flustrating to have to keep downloading new versions of a mod every couple of days as it gets changed and writen. But you can feel safe downloading this version. I won't be releasing any updates for atleast 3 or 4 weeks as I am going to do alot of testing before I set about writing any extra AI code, if I'll even have to. :cool:
 
I've found a small problem with lag when you click on a city. It is the check to see if cities can build units when their tile is full. To solve this lag, go to the \Beyond the Sword\Mods\JAAMyMod\Assets\XML directory and open the PythonCallbackDefines.xml file.

Find this part
Code:
	<Define>
		<DefineName>USE_CANNOT_TRAIN_CALLBACK</DefineName>
		<iDefineIntVal>1</iDefineIntVal>
	</Define>
and change it to
Code:
	<Define>
		<DefineName>USE_CANNOT_TRAIN_CALLBACK</DefineName>
		<iDefineIntVal>0</iDefineIntVal>
	</Define>
Cities will be able to build units no matter what, but you will be able to access your city builds like normal.
I'm not running that much code in the cannot train method. I can only guess that it is called multiple times in a single action. I will have to do something like I did with the unitCannotMoveInto method and store the return value for successive calls with the same argsList.


I've been playing with the mod and it seems that it is still a little to laggy, especially between turn time. I think I am going to have to bite the bullet and port this all over to the SDK. It isn't my first choice, but I don't really see much of an option. At the least I am going to move Unit Size to the SDK and probably a Base Space tag to the Terrain Info xml.

I'll see what I can get done this week and post my next plans when I get them laid out.

Anyone else tryed the mod? Opinions on the speed of various things?
 
Well, I sat down last night and put a few hours in and managed to port most of the functions of this mod from python and ini files to SDK and xml files.

To see the Change Log so far up to version 0.630 look in the spoiler below.
Spoiler :

v0.521
Few minor bug and typo fixes.

v0.610
Renamed the mod JUnitSpace.
Removed all Modifier Config.ini files.
Added modded DLL v0.100.
Moved Unit Size to SDK and XML.
Included changed SDK files.
Modded CvMainInterface.py file to show new Size stat in lower left corner under Movement.

New SDK Methods: (all exposed to python)
CyUnitClassInfo
int getDefaultUnitSize()
CyUnitInfo
int getUnitSize()
bool isIgnoreTileSpaceLimit()
CyUnit
int getUnitSize()
void setUnitSize(int iNewValue)
void changeUnitSize(int iChange)
bool ignoreTileSpaceLimit()

New XML Tags:
CIV4UnitClassInfos.xml
iDefaultUnitSize
CIV4UnitClassInfos.xml
iUnitSize
bIgnoreTileSpaceLimit

v0.620

New SDK Methods: (all exposed to python)
CyBonusInfo
int getTileSpaceChange()
CyFeatureInfo
int getTileSpaceChange()
CyImprovementInfo
int getTileSpaceChange()
CyTerrainInfo
int getTileSpaceChange()
CyPlot
void setBaseTileSpace()
void changeBaseTileSpace()
int getBaseTileSpace()
int getTileSpace()
int getBonusSpaceChange()
int getFeatureSpaceChange()
int getImprovementSpaceChange()
int getTerrainSpaceChange()

New XML Tags:
CIV4BonusInfos.xml
iTileSpaceChange
CIV4FeatureInfos.xml
iTileSpaceChange
CIV4ImprovementInfos.xml
iTileSpaceChange
CIV4TerrainInfos.xml
iTileSpaceChange

v0.630

New SDK Methods: (all exposed to python)
CyPlot
int getUsedTileSpace(bCountCargo)
int getOpenTileSpace(bCountCargo)
bool isTileSpaceFull(bCountCargo)


I still have to add Tile Space Modifiers in the City Building Infos xml file and some form of Unit Size modifier for promotions.
I have also moved all the code to decide if a unit can move into a tile from python into the SDK so it now causes no more lag then the normal game.
 
Great to see you are improving you mod. How do you mod manage units that are carry other units, like transports?

Meabee it is also an idea to allow units to temporary exceed the tiles limit (like in supreme commander), when they are moving, that way, you won't suffer from the blockade effect. The idea is that if you unit want to move to a destination which is at the other side of a unit, it will be able to move through a stack which has reached it limit. If the unit would end its turn in the stack which exceedd its limit, it would automaticly have to move back to the plt it came from.
 
Great to see you are improving you mod. How do you mod manage units that are carry other units, like transports?

Meabee it is also an idea to allow units to temporary exceed the tiles limit (like in supreme commander), when they are moving, that way, you won't suffer from the blockade effect. The idea is that if you unit want to move to a destination which is at the other side of a unit, it will be able to move through a stack which has reached it limit. If the unit would end its turn in the stack which exceedd its limit, it would automaticly have to move back to the plt it came from.

Units are not restricted from moving into plots that have open cargo space, and units that are cargo do not count toward the Tiles total so are basicly ignored by the code.

Leting units move through full tiles is an interesting idea, but I think the blocking effect of full tiles is one of the main points of limiting the amount of units that can be in a tile. I might see about adding in an option you can enable to allow movement through full tiles, but will have to look into it first.

I am planning to at some point add in a max space limit to tiles and if you are over the tile space, but under the max tile space the units would get some kind of crowded promotion. But that is a little ways down the line. :)
 
Put in a few more hours after work today and got all the origional fetures ported from python to SDK and xml files.

Here is the Change Log update.
Spoiler :


v0.630
Added new GlobalDefineAlt that allows Cities to ignore Tile Space Rules.
Added new GlobalDefineAlt that allows Domain Land Units to ignore Tile Space Rules.
Added new GlobalDefineAlt that allows Domain Sea Units to ignore Tile Space Rules.
Added new GlobalDefineAlt that allows Domain Air Units to ignore Tile Space Rules.
Added new GlobalDefineAlt that allows Domain Immobile Units to ignore Tile Space Rules.

New SDK Methods: (all exposed to python)
CyPlot
int getCityBuildingSpaceChange()
int getCityCultureLevelSpaceChange()
int getHillSpaceChange()
int getUsedTileSpace(bCountCargo)
int getOpenTileSpace(bCountCargo)
bool isTileSpaceFull(bCountCargo)
CyUnit
int getTotalUnitSize()
int getExtraUnitSize()
bool ignoreTileSpaceRules()
CyPromotionInfo
int getUnitSizeChange()
bool isIgnoreTileSpaceUnit()
CyBuildingInfo
int getTileSpaceChange()
CyCultureLevelInfo
int getTileSpaceChange()

New XML Tags:
CIV4PromotionInfos.xml
iTileSpaceChange
bIgnoreTileSpaceLimit
CIV4BuildingInfos.xml
iTileSpaceChange
CIV4CultureLevelInfos.xml
iTileSpaceChange

v0.640
Added new GlobalDefineAlt that allows Cities to ignore Tile Space Rules when Training Units.
Added new GlobalDefineAlt that controls if City Building Modifiers are Cumulative.
Added new GlobalDefineAlt that allows enabling/disabling of Bonus Tile Space Modifiers.
Added new GlobalDefineAlt that allows enabling/disabling of Feature Tile Space Modifiers.
Added new GlobalDefineAlt that allows enabling/disabling of Improvement Tile Space Modifiers.
Added new GlobalDefineAlt that allows enabling/disabling of Terrain Tile Space Modifiers.
Added new GlobalDefineAlt that allows enabling/disabling of City Building Tile Space Modifiers.
Added new GlobalDefineAlt that allows enabling/disabling of City Culture Level Tile Space Modifiers.
Added new GlobalDefineAlt that allows enabling/disabling of Unit Class Info Size Modifiers.
Added new GlobalDefineAlt that allows enabling/disabling of Unit Info Size Modifiers.

Changed SDK Methods: (unexposed to python, possibly unused by SDK)
CyPlot
void setBaseTileSpace()
void changeBaseTileSpace()
CyUnit
void setUnitSize(int iNewValue)
void changeUnitSize(int iChange)

v0.650
Updated Promotion Help to show new values.


I am working on updating all the help text strings to display space, sizes, and modifiers. Am going to be pretty busy over the next couple days, but should have this out some time next week. :)
 
Here are some other ideas:
- Not all tiles allow for the same amount of space. for example, hills, rivers and coastal water provide for less space then flat terrain or ocean.
- Larger cities should provide for more space then smaller cities.

I have already coded so you can set iTileSpaceChange for TerrainInfos, which includes hills, coastal and ocean. I hadn't really thought of rivers, but will see what I can do for that.

I have it set up so you can also add a iTileSpaceChange to each Culture level, but am planning to also add somthing that directly relates to city population. :)
 
Alright yall. I have done some testing and everything seems to be working alright. I got all the help texts updated and am just polishing up the readme file.

I'll be posting the mod sometime tonight. :)
 
Well I have finnally finished my first real SDK mod, and, I must say, I am very pleased with it.

For those that are interested see this thread. :D
 
Back
Top Bottom