View Full Version : Airport (An Interface Mod without Modding Ingame.lua or Worldview.lua)


jerseymike25
Jun 18, 2011, 07:04 PM
This builds off of the thread (http://forums.civfanatics.com/showthread.php?t=425393)I started in the Main C&C Forum - however this is a completed version of the Mod, so this forum is more appropriate.

Airport
Required Tech: Flight
Cost: 600 :c5production:
Maintenance: 5 :c5gold:
Purpose: When an Airport is built in a city, it allows a unit to be Airlifted to another city that also has an Airport, assuming that destination city does not have a Non-Garrisoned unit already. Late-game War, especially on bigger maps, is bogged-down by moving units great distances. This helps that problem (for the user, anyway.)
Compatability: Should be compatable with any Mod that does NOT use the Airlift InterfaceMode.

This building makes use of one of the left-over Civ4 stubs, the Airlift "mission" that was not otherwise implemented in Vanilla Civ 5. Included with this Mod, however, are UI treatments and restrictions on the standard Airlift logic when the mission is selected. When a unit is selected for Airlift, hexes under each of the user's Cities are highlighted in Green or Red indicating whether or not the unit can be Airlifted to that destination. Once the user clicks the left-mouse (typically to send the unit to its intended destination city), logic within this mod will determine if the Unit should actually be sent to the destination or not. For example, the vanilla "Airlift" functionality was to allow the Unit to be sent to any of the user's cities, regardless of whether or not the destination had an Airport or already had a non-garissoned unit there.

When I first made that other post, I mentioned that it required modifying Ingame.lua and Worldview.lua to achieve the kind of experience I was looking for with a Mod like this. I've since gone and figured out how to get what I wanted without modifying those files - something that I have not seen fully documented here (or much in general), although this post (http://forums.civfanatics.com/showthread.php?t=399743&highlight=SetInputHandler)from Omni covers the stuff that I had previously placed into WorldView.lua.

The Hex highlighting, which was previously tacked into Ingame.lua, is accomplished by registering my mod with the Events.InterfaceModeChanged event. My mod will check if the InterfaceMode has changed to INTERFACE_AIRLIFT, and if so, it will do the Hex highlights and allow whatever else is registered with InterfaceModeChanged to do what it needs to. If the previous InterfaceMode was for airlift, it will clear all of the Hex highlights.



function Airport_OnInterfaceModeChanged( oldInterfaceMode, newInterfaceMode)
--print("Airport_OnInterfaceModeChanged entered.");

if (newInterfaceMode == InterfaceModeTypes.INTERFACEMODE_AIRLIFT) then
ShowAirLiftView();
else if (oldInterfaceMode == InterfaceModeTypes.INTERFACEMODE_AIRLIFT) then
HideAirLiftView();
end

end

Events.InterfaceModeChanged.Add( Airport_OnInterfaceModeChanged );



For the logic that controls whether or not a unit can be sent to the destination City, I used ContextPtr:SetInputHandler and took action on LButtonUp. If the selected Hex allowed for a unit to be airlifted to it, then I did the work required and passed the message into the Game.SelectionListGameNetMessage function (as seen in WorldView.lua in a few places), and returned true from my handler indicicating that the LButtonUp action had been handled.


----------------------------------------------------------------
-- Input handling
----------------------------------------------------------------

function Airport_InputHandler( uiMsg, wParam, lParam )
local interfaceMode = UI.GetInterfaceMode();
if (interfaceMode == InterfaceModeTypes.INTERFACEMODE_AIRLIFT) and (uiMsg == MouseEvents.LButtonUp) then
local plot = Map.GetPlot( UI.GetMouseOverHex() );
local plotX = plot:GetX();
local plotY = plot:GetY();
local bShift = UIManager:GetShift();
local eInterfaceModeMission = GameInfoTypes[GameInfo.InterfaceModes[interfaceMode].Mission];

-- Did the plot clicked actually have a city? If not, return and indicate the input is done, and reset the interface mode.
if plot:IsCity() == false then
--print("Plot is not a city. Return true, reset interface mode.");
UI.SetInterfaceMode(InterfaceModeTypes.INTERFACEMO DE_SELECTION);
return true;
end

local city = plot:GetPlotCity();
if city:IsHasBuilding( GameInfo.Buildings["BUILDING_AIRPORT"].ID) then
local garrisonedUnit = city:GetGarrisonedUnit();
if (plot:GetNumUnits() == 0) or (garrisonedUnit and plot:GetNumUnits() == 1) then
if eInterfaceModeMission ~= MissionTypes.NO_MISSION then
if UI.CanDoInterfaceMode(interfaceMode) then
Game.SelectionListGameNetMessage(GameMessageTypes. GAMEMESSAGE_PUSH_MISSION, eInterfaceModeMission, plotX, plotY, 0, false, bShift);
UI.SetInterfaceMode(InterfaceModeTypes.INTERFACEMO DE_SELECTION);
return true;
end
end
end
end

-- If we get here, return true to indicate that the input has been handled, because the city has no airport or there's too many units there.
-- print ("Attempted to send to a city without an Airport.");
return true;
end

-- Either the interface mode is not AIRLIFT or a different button was pushed. Indicate false and let other handlers take care of this one.
return false;
end
ContextPtr:SetInputHandler( Airport_InputHandler );



Issues:
- No idea if the AI could make use of this. I would assume not.
- Does not create a Trade Route, as much as I would love it to do so.
- I can't get my GameSpy account to work, so I can't actually upload the Mod to be grabbed inside of the game. I used the Export function on ModBuddy to create a template and have attached it here.
- My kids are clamoring for my attention and my wife is giving me the evil eye, so I don't remember what other issues there might have been.

He-Who-Hunts
Jun 19, 2011, 04:24 AM
Do you think it would be possible to make it so airports give trade routes? Im playing around with the idea of a mod myself and that would be a part of it.

Hyronymus
Jun 19, 2011, 08:24 AM
Issues:
- No idea if the AI could make use of this. I would assume not.
- Does not create a Trade Route, as much as I would love it to do so.
- I can't get my GameSpy account to work, so I can't actually upload the Mod to be grabbed inside of the game. I used the Export function on ModBuddy to create a template and have attached it here.
- My kids are clamoring for my attention and my wife is giving me the evil eye, so I don't remember what other issues there might have been.

Do you think it would be possible to make it so airports give trade routes? Im playing around with the idea of a mod myself and that would be a part of it.

Most likely can be done but jerseymike25 hasn't been succesful at it yet.

jerseymike25
Jun 19, 2011, 03:10 PM
(Traderoutes) I'd played with it before - there isn't an attribute that can be added to a building that would do it, as best I can tell. The Harbor, for example, has the "AllowsWaterRoutes" attribute, but that seems to control whatever mechanism is responsible for calculating whether or not a city is connected to the capital. I think the calculation (of whether or not it's connected to the capital) is not something that can be accessed at the moment.

IF it can, though, it would be ideal - right now, a land-locked city on another contentent cannot possibly be connected via Trade Route, I believe.

mattpilot
Jun 24, 2011, 06:15 AM
awesome! thanks


Would it be possible to make it so that this also works with airports that workers build on tiles? (or combine its function with forts instead of adding another tile-improvement - thou i'd prefer a new tile improvement :)).

OmegaKabob
Jul 24, 2011, 01:49 PM
Actually, I'm pretty sure that there can be a trade route with a landlocked city on different continent than the capital. If I'm right you just need a city with a harbor on the continent with the landlocked city. Then just build a road between them. I may be wrong, but I'm almost certain you can do this.

Pablod
Feb 05, 2012, 07:40 AM
how to install it
where i save this in to