So I just did what you wanted and made special care to record what I did, my method and thought process to approaching this would be as such, hopefully you can find this useful:
( This all worked for me ingame perfectly fine, however it may be the case that during typing it up I made a syntax error somewhere, so I suggest using this as a guide only! )
1 - I want to remove the FOW for only the regions of a certain faction, as such I know I need to use the "make_region_visible_in_shroud" function.
2 - To use this function I need an event in which to call this function and the two arguments that the function takes, which is the faction who will see the FOW removed and the region to remove the FOW from.
Example usage: scripting.game_interface:make_region_visible_in_shroud("pro_rome", "pro_magna_grecia_italia");
3 - I want the FOW shown on the start of each of my turns, so I know to use the "FactionTurnStart" event, from that I can check it's my turn with "scripting.game_interface:model():is_player_turn()" and then get the ID of my faction from the string of the context argument for that event.
So far my code looks like this:
Code:
local function OnFactionTurnStart(context)
local current_faction = context.string;
if scripting.game_interface:model():is_player_turn() == true then
-- I know that at this point it's the players (my) turn and I have the ID of my faction in the current_faction variable.
end
end
scripting.AddEventCallBack("FactionTurnStart", OnFactionTurnStart);
4 - Now all I need are the ID's of the regions controlled by the faction I want to unhide the FOW of. For that I'll create a new function so as to allow code reusability and keep things neat. My function will take the ID of the player faction and the ID of the faction to unhide the FOW in their regions.
Code:
function RemoveFOW(player, factionID)-- Do stuff
end
5 - I need to be able to access the actual faction object of the faction to unhide the FOW of, so I'll use the "faction_by_key" function and pass it the factionID. With this faction object I can then get the factions regions using the "region_list" method of that faction. My function now looks like this:
Code:
function RemoveFOW(player, factionID)
local faction = scripting.game_interface:model():world():faction_by_key(factionID);
local factions_regions = faction:region_list();
end
6 - I can now iterate through the "factions_regions" list and from that I know I can use the "name" method of the region to get the ID of the region to pass to the "make_region_visible_in_shroud" function. My function is complete and when called will unhide the FOW for the specified factions region in the second argument for the other faction specified in the first argument:
Code:
function RemoveFOW(player, factionID)
local faction = scripting.game_interface:model():world():faction_by_key(factionID);
local factions_regions = faction:region_list();
for i = 0, factions_regions:num_items() - 1 do
local region = factions_regions:item_at(i);
local region_name = region:name();
scripting.game_interface:make_region_visible_in_shroud(player, region_name);
end
end
7 - I now combine it all together and call my function within the event created earlier to get my faction ID, make sure it used on my turn as that's when I want the FOW unhidden. I also need to make sure to specify here what faction I want the FOW unhidden for:
The final code
Code:
local function OnFactionTurnStart(context)
local current_faction = context.string;
if scripting.game_interface:model():is_player_turn() == true then
RemoveFOW(current_faction, "rom_carthage") -- Note: here I set the faction to unhide the FOW of, in this case Carthage
end
end
function RemoveFOW(player, factionID)
local faction = scripting.game_interface:model():world():faction_by_key(factionID);
local factions_regions = faction:region_list();
for i = 0, factions_regions:num_items() - 1 do
local region = factions_regions:item_at(i);
local region_name = region:name();
scripting.game_interface:make_region_visible_in_shroud(player, region_name);
end
end
scripting.AddEventCallBack("FactionTurnStart", OnFactionTurnStart);