Mission/UI - Choose a Target

bane_

Howardianism High-Priest
Joined
Nov 27, 2013
Messages
1,559
How do I simulate Ranged Attack mission's target selection?

Is there any easy (as in, less than 4 functions/100 lines) way to create a mission with a type of possible target (be it City, tile, specific kind of tile, unit, etc) and distance (like ranged has 1, 2 or 3, plane's rebase has way more, etc)?

As an extra data: I use whoward69's DLL, so solutions using another DLL are not useful for me and if using this DLL makes it easier, please refer to me how/why.

Thanks in advance.
 
Tile selection for a mission is a two part problem - writing the code for the AI to choose the tile and altering the UI to allow the player to choose the tile. The former can be done entirely in Lua, the latter requires you to add a new interface mode and modify the InGame.lua core file to respond to that interface mode. The basic sequence for a targetable mission is 1) click mission button, 2) change UI mode, 3) UI mode deals with tile highlighting, 4) user clicks to select tile, 5) UI mode code detects the click and calls the game core to continue processing the mission with the chosen tile as a parameter
 
I've got a script in my Wish for the World mod which handles clickable missions with targets -- the relevant code is in \Lua\Gameplay\MagicalGirls\MagicalGirlMissionHandler.lua.

It doesn't modify InGame.lua and doesn't add a new interface mode. While doing both of those things is the proper method of adding this functionality, I'm trying to avoid replacing base UI files whenever possible. It seems to work pretty well in my testing, at least.
 
Very very interesting.

To confirm, to use your Mission Handler, it is imperative that one uses whoward DLL's 'mission-maker', right? In order to get these:
--tMissionInfo contains:
--tMissionInfo.MissionID -- ID from the Missions database table
--tMissionInfo.RangePlots -- plots which are within the range of the mission
--tMissionInfo.ValidTargetPlots -- plots which are actually valid targets
--tMissionInfo.ExecFunction -- a string which corresponds to a function here, unique to each mission

I'm currently using bouncymisha's method, but I have no problem learning the another way. :)
 
Yes, it uses the CustomMission hooks provided by DVMC. If you are using DVMC, there is no reason to use the Lua-based mission definitions -- it is much more reliable to have an actual mission defined in the Missions table.

Oh, also: this is in the main Lua file for my mod rather than in MagicalGirlMissionHandler, but you'll want to include this in your top-level Lua file which includes this code. Meaning, if you're including this code from another script, you'll need to put this in the script which called it, not in the mission handler script itself.

Code:
function InputHandler( uiMsg, wParam, lParam )
	if uiMsg == MouseEvents.LButtonUp then
		local pPlot = Map.GetPlot( UI.GetMouseOverHex() )
		if pPlot then
			if tMissionInfo.ValidTargetPlots then
				if tMissionInfo.ValidTargetPlots[pPlot] then
					ExecuteMapClickCustomMission(pPlot)
				end
			end
		end
	end
end
ContextPtr:SetInputHandler( InputHandler );
 
Resurrecting a 1y+ old thread by myself, since I'm back at this same issue, I found this comment intriguing:

--...this really should be handled through WorldView with an actual InterfaceModeType, but I don't have the patience to work with a WorldView replacement yet until it's truly necessary.

Anyone (preferably VV himself) knows of any issue of not using WorldView replacements?
 
Back
Top Bottom