• Civilization 7 has been announced. For more info please check the forum here .

AI Land Transport Usage

no there is a difference between that.

there is bHiddenNationality but there is also bAlwaysHostile. privateers have both -> invisible nationality AND can attack without declaring war. bAlwaysHostile is for fighting without declaring war.

land units which can attack without declaring war would be great (terrorists/special forces). the AI won't use this atm but with your code they could. :)
 
Very Promising, despite some setbacks. I'm not shocked it's difficult. I PM'd Koma13, who has done some work with creating transports, and he very politely sent me the following information:

Well, I barely remember what changes I did, I got them from following thread: http://forums.civfanatics.com/showthread.php?t=322317

And that post: http://forums.civfanatics.com/showpo...&postcount=252

But you can't use that for land transports. AI only loads a unit on a transport if that (cargo) unit can't reach its destination plot (usally a target city for assault) by itself. This works fine for a sea transport but it is never true for a 100% land path. This is where you would have to start, replacing the 'is destination reachable?' test by a path distance check... somehow.

I've had a chance to look through these posts but not yours yet (and I'm on the way to work right now) so I don't know how relevant the information is to your project. But if it is helpful here it is.

Great job, and I'll download and look at what you've done later so I can maybe help in some way.
 
...land units which can attack without declaring war would be great (terrorists/special forces). the AI won't use this atm but with your code they could. :)

That was kind of what I was thinking, though, I had yet another thought, I wonder if it is possible to make it so that if UNITCLASS_SO_AND_SO is defaulting to UNITAI_RAIDER and has an Invisible type they can attack and (if they survive) fade back into invisibility? They'd need to be fairly expensive and be nationally capped like execs or missionaries.
 
...Great job, and I'll download and look at what you've done later so I can maybe help in some way.

Thank you for the praise, but don't bother with the download, it was all because of ::shouldLoadOnMove(), I've tested it and Maniac was right. Though if you would like, I can upload the changed CvUnitAI file (I've only made it about a quarter of the way through so far).
 
One thing which may help you along the path to making the AI do this properly would be the AirLift code. That should include a check for travel distance/time comparisons between actual destination and a city with Airlift capability. In your case you would have to make it considerably more complicated since now it isn't a direct comparison of "Travel to Destination A, or Destination B (which instantly places me at A)" but instead "Travel to Destination A, or Destination B THEN A, after waiting for other units to join me" type of thing.

I'd also look at CvUnitAI's functions for deciding when/where to group units, as the best way to make the AI use land transport effectively would be when moving their stacks of doom. So they would decide to start building a SoD in a city, amass enough Land Transport to carry the intended stack size, and amass enough units to make the stack. Then set out.
 
I'm going to hopefully finish going through CvUnitAI tonight and after that, I'm assuming I'll simply (<--yeah :lol:) need to pick through the rest of the AI files and plug my new code into places that seem appropriate. here's hoping that maybe I can upload a working (by design and not coincidence) version by early next week. Oh, and again, thank you Xienwolf.
 
To repeat, so far this is an "interesting starting point". Assuming TLO is able to make the unit AI's work correctly, there is still a big (bigger) project to get the AI to build the right proportion of combat units, transport units and escort units. Also there are several lower level problems such as workers taking actions from within transports. I am going to take a crack at the third area, but IMHO all three should be solved before we integrate this into any other packages.
 
...Also there are several lower level problems such as workers taking actions from within transports...

Wouldn't this be solved by adding a isCargo check to AI_Update? Something along the lines of "if the unit is cargo, then set their mission to mission_skip"? something along those lines?
 
Both the AI and the player need to be prevented. I am tracing CvUnit::canPillage and CvUnit::canBuild, we will see what happens. I also need to trace the load and unload actions which are probably nearby.
 
I have tested out the following changes to prevent many kinds of illegal activities while inside a transport, in file CvUnit.cpp.

1. Add a line "if isCargo() return false" to canPillage(), canBuild(), canAttack(), canAutomate(), canLoad(). The only reason this is not checked already is that the game assumes a land unit will be cargo on an ocean unit, and the domain would have prevented this action anyway.

2. Add a line "finishMoves()" to load() and unload(). This uses up all the remaining action points upon loading or unloading. For unloading, this is a change in game behavior, but it seems reasonable to prevent any further movement or attacking after unloading. Your mileage may vary.

3. Add a line "if getMoves() >= maxMoves() return false" to canLoad() and canUnload(). This prevents loading or unloading unless the unit has movement points left. This is a change to game behavior, but it prevents multiple loads and unloads in the same turn. Your mileage may vary.

Unfortunately I cannot see any way to prevent mod-specific action buttons from having an effect. In python, if you have a mod-specific action button, you can check isCargo(); but I bet very few mods do that today.

Still, I feel the hard problem is getting the AI to build the right mixture of land transports and escorts.
 
2. Add a line "finishMoves()" to load() and unload(). This uses up all the remaining action points upon loading or unloading. For unloading, this is a change in game behavior, but it seems reasonable to prevent any further movement or attacking after unloading. Your mileage may vary.

I'd suggest adding an exception so that you still keep your movement points if you're unloading in a city.
 
I have tested out the following changes to prevent many kinds of illegal activities while inside a transport, in file CvUnit.cpp.

1. Add a line "if isCargo() return false" to canPillage(), canBuild(), canAttack(), canAutomate(), canLoad().

Does this stop amphibious invasions?

2. Add a line "finishMoves()" to load() and unload(). This uses up all the remaining action points upon loading or unloading.

I thought this was already a part of loading. As for unloading, I would not call finishMoves() if the plot is a city.

3. Add a line "if getMoves() >= maxMoves() return false" to canLoad and canUnload.

As above, I would skip this check if the plot is a city. If you make it to the city with no movement points, you should still be able to load.

Unfortunately I cannot see any way to prevent mod-specific action buttons from having an effect. In python, if you have a mod-specific action button, you can check isCargo(); but I bet very few mods do that today.

Any mod that includes land transports will have to modify their action buttons accordingly. I think that's a fair expectation.
 
Still, I feel the hard problem is getting the AI to build the right mixture of land transports and escortts.

It is done in CvCityAI::AI_chooseProduction().

Code:
int iEscorts = kPlayer.AI_totalAreaUnitAIs(pArea, UNITAI_ESCORT_SEA);
iEscorts += kPlayer.AI_totalAreaUnitAIs(pWaterArea, UNITAI_ESCORT_SEA);

...

if ((iEscorts < ((1 + 2 * iTransports) / 3)) && (GC.getGame().getSorenRandNum(2, "AI train escort sea") == 0))
{
	if (AI_chooseUnit(UNITAI_ESCORT_SEA))
	{
		AI_chooseBuilding(BUILDINGFOCUS_DOMAINSEA);
		return;
	}
}
 
Does this stop amphibious invasions?

I suppose that preventing canAttack() would turn off amphibious invasions. I am not sure what "amphibious" means for land transports. This is a good design question; the current code does not check if you have the amphibious promotion, but maybe it should. For Dune Wars, the feedback so far has been that it is too easy for a land transport to drive up from a distance and immediately launch an assault with little risk. This way, you have to plan where to unload, perhaps several turns away so that your attack units are not at risk while inside the transport.

As for unloading, I would not call finishMoves() if the plot is a city. [...] As above, I would skip this check if the plot is a city.

I am not sure why it should matter if the plot is a city. If you think it should matter, does it also matter whether the city is friendly, neutral or enemy?
 
I suppose that preventing canAttack() would turn off amphibious invasions. I am not sure what "amphibious" means for land transports.

When I think of an amphibious attack, I imagine the transports coming right up to shore and the troops pouring out onto the beach and attacking right there. I personally think that should suffer a -50% attack with the Amphibious promotion knocking that down to -25%, but that's beside the point.

Land transports to me are either air units (helicopters) or APCs. They would allow you to bypass defenses more easily than sea transports would, and for that reason I would be hesitant to allow units to attack from them. Also, there's less of an obvious "line in the sand" that the transports can drive up to and unload quickly as there is at sea (the beach). However, maybe having a new modifier for attacking from a land transport would balance this somewhat.

For Dune Wars, the feedback so far has been that it is too easy for a land transport to drive up from a distance and immediately launch an assault with little risk.

I agree. At least with sea transports the increased danger from approaching a defended position in a vulnerable craft is simulated by the -25% modifier. I would even like to see some sort of "free strike" that occurs when you do this. The enemy defenders should get a chance to do a small amount of damage as you arrive/unload with no risk to themselves.

I am not sure why it should matter if the plot is a city. If you think it should matter, does it also matter whether the city is friendly, neutral or enemy?

You cannot have a transport and unit in an enemy city to do the loading, so that's moot. As for domestic and friendly cities, my reasoning is only that the current game works this way. You should have a really good reason to change behavior that people are used to and expect to see. This seems to be a side-effect of the tweak to land transports, and I feel you can easily make that side-effect go away and still achieve the land transport limitation.
 
As for domestic and friendly cities, my reasoning is only that the current game works this way.

In the functions I modified, there is no special handling for cities. Are you sure that there is special handling for cities somewhere else? Where should I look?
 
Idea for maybe a completely different tack. You could make a Transporter promotion that's attained only as a free promotion for units of a certain unitai, the Transporter unitai. The transporter promotion would change the movement rate of all costacked units to its own movement rate (much like some promotions increase the healing rate of costacked units) and the transporter ai would tell the transporter units to beeline for and insert themselves into the largest stack lacking a transporter. The city ai would have to have instructions to make transporters, maybe based on some formula about average stack size and speed. Later you could maybe restrict the number of transported units per transporter and have the ai detect how many transporters it needed per stack.
 
In the functions I modified, there is no special handling for cities. Are you sure that there is special handling for cities somewhere else? Where should I look?

No, I'm saying that currently--without any special handling--if you move a unit to a city or fort (specifically a tile that can contain a sea transport unit) and it runs out of moves, you can still load it onto the transport that turn. You're adding code that will change this behavior indirectly by making loading onto a transport--any transport--require movement points.

So there is no special code right now, but if you add your special code you'll need to add some extra special code to keep it from affecting loading in cities/forts only if you want to maintain the current functionality.
 
You are saying that cities are handled specially for loading and unloading. That is fine. There is no evidence of this in the functions I modified. Therefore, there must be some other functions which provide the special handling of cities. I would like to look at those to understand them better. Can you help me to figure out where this special handling happens?
 
Top Bottom