Defining what is currently selected help

mauporte

Chieftain
Joined
Mar 7, 2012
Messages
21
Location
Monterrey, México
I am trying to create a mod with espionage type mechanics and whilst browsing through the databases and the code I stumbled upon the following in EspionageChooser.lua under Assets/UI/Choosers/


-- ===========================================================================
-- MEMBERS
-- ===========================================================================
-- Currently selected spy
local m_spy :table = nil;
-- Currently selected city
local m_city :table = nil;



the code then proceeds to do a series of checks to which information and options to display in the espionage chooser, but what I cannot find anywhere else in the data files is where and how is it defined that the currently selected city is m_city and that the currently selected spy is m_spy. So this brings me to the question: How does the game know what is currently selected? And where are these definitions stored?
 
appears to be
Code:
m_spy = selectedUnit;
within the function called Open(). selectedUnit is defined a few lines previously
Code:
-- Cache the selected spy
local selectedUnit:table = UI.GetHeadSelectedUnit();
m_city appears to be defined within the same function Open().

Function Open() is activated by function OnInterfaceModeChanged( oldMode:number, newMode:number ) which in turn is hooked to and fired by GameCore Event InterfaceModeChanged:
Code:
-- Game Engine Events	
Events.InterfaceModeChanged.Add( OnInterfaceModeChanged );
There might be other events that cause the firing of OnInterfaceModeChanged() and Open() but I did not look any deeper into the code.

Spoiler Open() function :
Code:
function Open()
	-- Set chooser mode based on interface mode
	if UI.GetInterfaceMode() == InterfaceModeTypes.SPY_TRAVEL_TO_CITY then
		m_currentChooserMode = EspionageChooserModes.DESTINATION_CHOOSER;
	else
		m_currentChooserMode = EspionageChooserModes.MISSION_CHOOSER;
	end

	-- Cache the selected spy
	local selectedUnit:table = UI.GetHeadSelectedUnit();
	if selectedUnit then
		local selectedUnitInfo:table = GameInfo.Units[selectedUnit:GetUnitType()];
		if selectedUnitInfo and selectedUnitInfo.Spy then
			m_spy = selectedUnit;
		else
			m_spy = nil;
			return;
		end
	else
		m_spy = nil;
		return;
	end

	-- Set m_city depending on the mode
	if m_currentChooserMode == EspionageChooserModes.DESTINATION_CHOOSER then
		-- Clear m_city for Destination Chooser as it will be the city the player chooses
		m_city = nil;
	else
		-- Set m_city to city where in for Mission Chooser as we only want missions from this city
		local spyPlot:table = Map.GetPlot(m_spy:GetX(), m_spy:GetY());
		local city:table = Cities.GetPlotPurchaseCity(spyPlot);
		m_city = city;
	end
	
	if not m_AnimSupport:IsVisible() then
		m_AnimSupport:Show();
	end

	Refresh();
	
	-- Play opening sound
	UI.PlaySound("Tech_Tray_Slide_Open");
end
 
I don't know how I missed that, maybe because it was lower on the code, thanks.

What I'm trying to do is to create a new unit, the diplomat with its own interface, missions,promotions, etc.
so the script defines to retrieve the units table for the selected unit and then to check if said unit is a spy by this: "if selectedUnitInfo.Spy" Could this be a reference to the boolean column in the units table named Spy?
 
Ok, so what I'll do is create a new boolean column for the units table: Diplomat, and that would become selectedUnitInfo.Diplomat, following from that I should be able to duplicate the whole espionage mechanism.
Now the only thing I still need to figure out is how to add effects to the game since these do not seem to follow the same process as dynamic modifiers

There is one other problem I have found though, and it involves changing one crucial dynamic modifier effect:
<Row Type="EFFECT_GRANT_SPY" Kind="KIND_EFFECT" />

I scrolled down thinking I would find something similar to this:
<Row EffectType="EFFECT_GRANT_SPY" UnitType="SPY" />

But then after a visit to 01_GameplaySchema.sql I found out that there is no Effects table.

Many thanks
 
Top Bottom