Air recon target tile selection

insert_brain

Chieftain
Joined
Jun 14, 2014
Messages
8
Hello everyone,
I am a newcomer to the modding panorama, and I am currently trying to create an air recon unit. As of now, I have added the unit in game (the xml stuff) and I added a special action (e.g. air recon) modifying the UnitPanel.lua file. When clicked, the action will trigger a function which will highlight the area in which it is possible to launch an air recon. What I am not sure is how exactly to hook a custom function (to reveal a portion of the map near the selected tile) when a tile is actually selected. I would look into how air strikes/bombardment (or any ranged attack in general) scripts are implemented, but I can't seem to find the files I need. Thanks to whoever will help.
 
You're picking a tough assignment with which to get started.

Bombardment.lua is in \Assets\UI\InGame (includes unit/city ranged attacks, airstrikes, and nukes). It uses Events.SerialEventHexHighlight() to perform the highlighting.

whoward69's UI Tutorial is fairly extensive, and should help get you started.

I'm no expert, but you'll need something like this to figure out which hex the user clicks on:
Code:
function InputHandler(uiMsg, wParam, lParam)
    if (uiMsg == MouseEvents.MouseLButtonUp) then
        return Map.GetPlot(UI.GetMouseOverHex());
    else
        if(uiMsg == KeyEvents.KeyDown) then
            if (wParam == Keys.VK_ESCAPE) then
                OnClose();
                return nil;
            end
        end
    end
ContextPtr:SetInputHandler(ProcessInput)

There's a plot:SetRevealed() method, but no plot:SetVisible() [only plot:UpdateVisibility()]. Perhaps you could put an invisible, unmoveable unit in the appropriate space with the appropriate visibility range, and then remove it after a specified number of turns.
 
You're picking a tough assignment with which to get started.

Bombardment.lua is in \Assets\UI\InGame (includes unit/city ranged attacks, airstrikes, and nukes). It uses Events.SerialEventHexHighlight() to perform the highlighting.

whoward69's UI Tutorial is fairly extensive, and should help get you started.

I'm no expert, but you'll need something like this to figure out which hex the user clicks on:
Code:
function InputHandler(uiMsg, wParam, lParam)
    if (uiMsg == MouseEvents.MouseLButtonUp) then
        return Map.GetPlot(UI.GetMouseOverHex());
    else
        if(uiMsg == KeyEvents.KeyDown) then
            if (wParam == Keys.VK_ESCAPE) then
                OnClose();
                return nil;
            end
        end
    end
ContextPtr:SetInputHandler(ProcessInput)

There's a plot:SetRevealed() method, but no plot:SetVisible() [only plot:UpdateVisibility()]. Perhaps you could put an invisible, unmoveable unit in the appropriate space with the appropriate visibility range, and then remove it after a specified number of turns.
Thank you for your input :). As of now after a lot of search I'm at the point where I created a new interface mode (testing if it works right now). The flow of the code I thought would be:

- Make the new action button I added through modifying UnitPanel.lua change the interface mode to INTERFACEMODE_RECON (which I clearly added)

- Register a listener with Events.InterfaceModeChanged which will highlight the area in which it is possible to perform a recon action

- Register an InputHandler function that checks that the current InterfaceMode is INTERFACEMODE_RECON and that the event is a left mouse button click, in which case for now it should (not tested yet) fire a popup just as a test. In case it works i will proceed with revealing the selected tiles (I am quite sure I have the revealing part done) and fire a "MOVE_TO" mission (same as airstrikes), which should make the flight animation work.

The only thing is, I am not sure this is the most proper way of doing this (and if it will actually work :)).
Thanks again to anyone that will stop by and drop a line about this :)
 
Your approach sounds perfectly logical. I have a need for something like this in my mod - a Scry spell that will allow caster to set a "recon plot" at some distance from the caster. The spell effect is already in place and works with some AI logic. But I haven't sat down yet with 5 hrs to kill on the human UI part of the problem (for selecting a plot out to a given distance).

Hope you will be willing to post code when you get it working.
 
Your approach sounds perfectly logical. I have a need for something like this in my mod - a Scry spell that will allow caster to set a "recon plot" at some distance from the caster. The spell effect is already in place and works with some AI logic. But I haven't sat down yet with 5 hrs to kill on the human UI part of the problem (for selecting a plot out to a given distance).

Hope you will be willing to post code when you get it working.
I will be glad to, I am almost there :)
 
Back
Top Bottom