General questions + could this work? [Canals/forts revisited]

toadhunter

Chieftain
Joined
Dec 31, 2011
Messages
3
Ok, I have read that people say that it is impossible to add canals to Civ5. But the discussion mainly goes around modifying XML and terrain.

As I looked around, it seemed to me that perhaps it still could be done somehow, but you would need to modify game behaviour on deeper level than XML: maybe not change terrain, but unit movement?

I was wondering if reimplementing forts like they were in Civ4 could possibly work: you could enter a fort with a naval unit, if the fort was next to water (basically providing a 2-tile max-length canals).

So, I tried to add a hook to the GameEvents.UnitSetXY, something like that:

Code:
function NavalUnitsEnterForts(iPlayer, iUnitID, iX, iY)
  	local pUnit = Players[ iPlayer ]:GetUnitByID( iunitID );
    if ( pUnit:GetDomainType() ~= DomainTypes.DOMAIN_SEA ) then
      return false;
	end;
    local plot= Map.GetPlot(iX,iY);
    if (plot:GetImprovementType() ~= GameInfo.Improvements.IMPROVEMENT_FORT.ID ) then
	     return false;
	end;
    if (plot:IsAdjacentToShallowWater()) then
      return true;    
	end;
	return false;
end

GameEvents.UnitSetXY.Add(NavalUnitsEnterForts)

I have made this into mod with modbuddy and it compiles OK, I have also added the
Code:
    <OnModActivated>
      <UpdateDatabase>NavalForts.lua</UpdateDatabase>
    </OnModActivated>

to the modinfo file (from within modbuddy too, no manual editing here, so i don't mess anything up).

The mod can be loaded, but appears to do nothing.

I added some print() statements to the function and attached Firetuner process, but the mod doesn't seem to activate at all. Am I doing something wrong?

Also, when trying to make a function by hand in Furetuner, I get confused:

I see in other mod LUA files references to "Players" and some other objects. I can't reference them directly from Firetuner LUA console, but have to use "GameCore.Players" instead? Same with some other LUA objects: I see "GameEvents" in FireTuner, but in some mod files I see "Events", are they the same?

And is there a way to write multiline functions in Firetuner's LUA console?

Any hints appreciated. While I have some programming experience, I haven't done any LUA before, nor done any Civ XML modding so far.
 
Lua files are not added via UpdateDatabase as they are not database files. They are either hooked in via some manner of UIAddin or just set to VFS true.
 
Okay, just in case somebody else is interested in today's findings:

The original idea does not work; apparently the problem is that it is not possible to set land tile as target for sea unit at all, therefore UnitSetXY event never actually fires.

What I tried else:

You can set Ice as passable terrain, but Ice is a feature on TOP of actual terrain type, so setting a tile to Ice by itself doesn't make it passable for naval units.

What WILL work (in a manner) is that you can, of course, set a plot's TerrainType to Coast. This is relatively easy and could be added, for example, as Worker action "Dig Canal". But it is obviously not a proper canal, for land units will need to embark to cross it. A poor man's canal then, would be adding the option to Worker and making some safeguards: for example, you can only dig canal X tiles long, not on elevated terrain, you automagically move worker away from Canal plot, when about to finish, etc.

I believe any of the following options should work for a more "proper" implementation of naval fort/canal, but requires much more knowledge about the game than I have, to consider whether it is doable at all:

a) alter game's unit possible movement calculation, so that land tiles next to water are included as possible destinations for naval units. The check whether naval unit can enter that particular tile itself could be similar to the one I posted in the beginning.

b) alter fort/canal tiles so that they are considered City tiles for movement purposes. City tiles actually currently already CAN hold both land and water units.

c) make it so that all naval units can move over ALL terrain, but make additional check so that they actually can only move over their appropriate water tiles (coast/ocean) and over fort tiles next to existing water. The LUA unit game object shows they have CanMoveAllTerrain checking function, but I have no idea whether this is actually settable anywhere.

NB.
A funny thing that as I implemented my original checking function, it gave me the same GetDomainType() 0 (Sea unit) for both a trireme and a scout. When querying directly from LUA console, the scout getdomaintype showed correct domain (land unit). Wierd.
 
Back
Top Bottom