[UNIT] One TYPE of unit per tile

arcvoodal

Chieftain
Joined
Jan 14, 2009
Messages
61
So it looks like one unit per tile has been tackled in many ways. But it seems to use "support limits" like things. I was thinking to create code that simply says

"If this tile has a unit with same unit type then make it an impassable tile for this unit"

of course this only applies to the active civ. different civs can share a tile with same unit types.

I could not find anything in the other attempts at one-unit-per-tile mods to figure out for myself how to make this.

This forum had some code but it does not help me for this idea:
https://forums.civfanatics.com/threads/any-coding-idea-how-to-limit-units-on-a-tile.170189/

could someone please help me make this?
 
I tried adding

if (pSelectionGroup->getUnitCombatType() == getUnitCombatType())
{
return false;
}
to the CvUnit.cpp under

bool CvUnit::canJoinGroup(const CvPlot* pPlot, CvSelectionGroup* pSelectionGroup) const
but it did not work for some reason.
 
the

if (pSelectionGroup->getNumUnits() >= 10) // Dale: Max of 10 units per stack
{
return false;
}​

from the thread I linked also does not work
 
Have you re-compiled the DLL after making those changes?

Ah okay that was it. So that was one hell of a lot of setting up to be able to compile (never done it before), but unfortunatly it says:

CvUnit.cpp(8876): error C2039: 'getUnitCombatType' : is not a member of 'CvSelectionGroup'​

when trying to use:

if (pSelectionGroup->getNumUnits() >= 10) // Dale: Max of 10 units per stack
{
return false;
}​

It compiles successfully, but when launching the game I get the errors :Assert Failed
and then the game crashes

an example of some are:


File: .\.\CvGlobals.cpp
Line: 3493
Expression: strcmp(szType, "NONE")==0 || strcmp(szType, "")==0
Message: info type TECH_BIONICS not found, Current XML file is: modules\next war\technologies\cybernetics\_civ4techinfos.xm​

and

Assert Failed

File: .\.\CvInfos.cpp
Line: 4032
Expression: i < getGroupDefinitions()
Message: Index out of bounds
I am using the Neoteric world mod.

Could you help me fix this?
 
Last edited:
Ah okay that was it. So that was one hell of a lot of setting up to be able to compile (never done it before) [...]
Didn't expect you to go through with it tbh. Great that you've gotten the compiler to work though.

I take it that you've edited and compiled the source code for the original BtS DLL? I don't see any trace of the DLL source code in the Neoteric World thread. I'm guessing that it uses the DLL from RevDCM:
I wont ever do an update for this, I cant think of anything else I would like to add. This mod uses RevDCM core, all credit goes to the guy called Jdog [...].
Doesn't sound like BobeBrown has made DLL changes of his own, but Neoteric World doesn't seem to use the latest version of RevDCM. The RevDCM DLL that I have on my PC (v2.9) was last modified in Jan 2011; the Neoteric World DLL on moddb was last modified in June 2010. RevDCM code from around that time is available on SourceForge; maybe a later or the latest version would also be compatible with Neoteric World. Either way, compilation could be a bit difficult because RevDCM has its own (ancient) makefile; not sure if that'll work straight away with the Visual Studio project file in Leoreth's thread.

If you just want to experiment (and not necessarily play) with a units-per-tile limit, it would be easier to do that without modifications beyond your own or with a mod that doesn't have its own DLL.

getUnitCombatType is a CvUnit function. Something like
pSelectionGroup->getHeadUnit()->getUnitCombatType()
might work (i.e. compile – whether it'll have the result that you want is difficult to say).

Failed assertions aren't necessarily a problem (if you eventually compile a release build, those popups won't appear), but the ones you've posted look like they're the result of the XML loading code in your DLL being incompatible with the Neoteric World XML files.
 
I take it that you've edited and compiled the source code for the original BtS DLL?

No I copied the CvGameCoreDLL from the beyond-the-sword-sdk-develop download into the neoteric world folder.

But I tried a clean install and compiling the original bts dll now and got this error:

1>CvTextScreens.cpp(5): fatal error C1083: Cannot open include file: 'CvTextMgr.h': No such file or directory
1>NMAKE : fatal error U1077: '"C:\Program Files (x86)\Civ4SDK\Microsoft Visual C++ Toolkit 2003\bin\cl.exe"' : return code '0x2'
1> Stop.

Im not sure how the 'makefile' thing works. I will have to end this here today and continue during the week some time.
 
No I copied the CvGameCoreDLL from the beyond-the-sword-sdk-develop download into the neoteric world folder.
Right, that's the same as the source code that comes with BtS (with the CD version anyway; not sure about digital). The resulting DLL should work fine in any mod that doesn't come with its own (game core) DLL.

CvTextMgr.h: Apparently, Visual Studio is trying to compile CvTextScreens.cpp. Firaxis seem to have released that file by accident. Deleting it may fix that particular error – but you probably should simply go back to using the setup that you had already gotten to compile successfully (neither will work with Neoteric World).
 
That is a shame. I don't know enough to be able to figure it out then. I don't like giving up but this is beyond me to do without neoteric world having DLL folder of its own for me to change and recompile

edit: It appears doing it for original civ only makes that amount of units selected when trying to select all. It does not prevent more than 10 units from being on a square. I thought the code looked strange.

it works with the other code posted there. Ill report if I figure out how to make it for combat type of unit rather than number

okay but trying to use

if (getHeadUnit()->getUnitCombatType() == getUnitCombatType())
{
return false;
}
it says 'getHeadUnit' is undefined in the Cvunits.cpp. and getUnitCombatType is undefined in the Cvselectiongroup.cpp.
 
Last edited:
That thread you've linked to pre-dates the expansions. Dale's code may have worked in Vanilla Civ 4, but, I agree, that it looks like it
[...] only makes that amount of units selected when trying to select all.
Modifying CvUnit::canMoveInfo should work, but, as Dale points out, won't e.g. prevent units produced in a city from stacking up there. To check unit combat types in canMoveInto, you'd arguably have to write a loop that goes through all units in pPlot.

I think the VIP mod has a hard movement limit. The changelog for v1.5 says
vincentz said:
The MAXUPT is now based on Era. STARTUP is basenumber (altGlobalDefines.xml)
so... in neolithic the maxupt is now 3 (STARTUP) and increases by 3 per era (MAXUPT)
Neo = 3 , Anc = 6, Cla = 9, Med = 12, Ren = 15, Ind = 18, Mod = 21, Tra = 24, Fut = 27
But I don't know how practicable it would be to adopt code from that mod, which, as the list of eras already suggests, is quite expansive. Its source code, in any case, is on GitHub.
 
hmmm. Thing is that won't lead to my goal of unit type per tile. But I guess I may as well experiment with it anyway since I don't know what else to do
 
Well, this would be the aforementioned loop for CvUnit::canMoveInto:
Code:
for (CLLNode<IDInfo>* pNode = pPlot->headUnitNode();
   pNode != NULL; pNode = pPlot->nextUnitNode(pNode))
{
   CvUnit const& kLoopUnit = *getUnit(pNode->m_data);
   if (kLoopUnit.getUnitCombatType() == getUnitCombatType() &&
      kLoopUnit.getOwner() == getOwner())
   {
       return false;
   }
}

To take it further than that, i.e. to deal with whatever AI problems may become apparent and with newly produced units, I think you'd have to be willing familiarize yourself a bit more with the codebase and C++.
 
Top Bottom