Craig_Sutter
Deity
I am working on the first part of a long string of script which I will use to generate semi-random Viking attacks upon the British Isles. To that end, I am trying to create a table of cities that will be possible subjects of attacks.
I check that when a city is founded, it is within one of the grids I have created. If that is the case, the plot is then checked to see if it is either coastal or adjacent to a coast (I used whoward69's lighthouse code for this). I hope I ported it over correctly.
If everything works, the plot index should be stored as well as if the plot is coastal or adjacent to a coast.
Later, I will create a function to randomly select one of the six grids, and then randomly select a coastal or adjacent coastal city (with a greater probability of the former) and have a random Viking civilization attack the owner (given fulfillment of certain criteria).
For now, I have just done the selection process. I am very unfamiliar with tables, so I hope I have done that aspect correctly. Later, I want to figure out how to store it over saves. For now, I just want to get the information into the table correctly.
I have a couple of questions:
1) I have cities being founded during Events.SequenceGameInitComplete... will the function record those cities?
2) I don't need cities that are neither coastal nor adjcoastal... I'm not certain my code eliminates those.
Please excuse any glaring mistakes.
Thank-you.
PS I have not tested the code as I am in the process of doing other tests and do not want to redo the project until that test is done.
I check that when a city is founded, it is within one of the grids I have created. If that is the case, the plot is then checked to see if it is either coastal or adjacent to a coast (I used whoward69's lighthouse code for this). I hope I ported it over correctly.
If everything works, the plot index should be stored as well as if the plot is coastal or adjacent to a coast.
Later, I will create a function to randomly select one of the six grids, and then randomly select a coastal or adjacent coastal city (with a greater probability of the former) and have a random Viking civilization attack the owner (given fulfillment of certain criteria).
For now, I have just done the selection process. I am very unfamiliar with tables, so I hope I have done that aspect correctly. Later, I want to figure out how to store it over saves. For now, I just want to get the information into the table correctly.
I have a couple of questions:
1) I have cities being founded during Events.SequenceGameInitComplete... will the function record those cities?
2) I don't need cities that are neither coastal nor adjcoastal... I'm not certain my code eliminates those.
Please excuse any glaring mistakes.
Code:
tNorthscotland = {iplot,coastal,adjcoast}
tUmbria = {iplot,coastal,adjcoast}
tAnglia = {iplot,coastal,adjcoast}
tSouthengland= {iplot,coastal,adjcoast}
tIrishsea = {iplot,coastal,adjcoast}
tSouthireland = {iplot,coastal,adjcoast}
function citylist(iPlayer, iX, iY)
local plot = Map.GetPlot(iX, iY);
local iplot = plot:GetIndex()
if iX>=43 and iX<=84 and iY>=63 and iY<=77 then
citysort()
local tNorthscotland = iplot, coastal, adjcoastal
end
if iX>=47 and iX<=57 and iY>=32 and iY<=48 then
citysort()
local tUmbria = iplot, coastal, adjcoastal
end
if iX>=46 and iX<=52 and iY>=18 and iY<=34 then
citysort()
local tAnglia = iplot, coastal, adjcoastal
end
if iX>=26 and iX<=46 and iY>=14 and iY<=28 then
citysort()
local tSouthengland = iplot, coastal, adjcoastal
end
if iX>=33 and iX<=48 and iY>=47 and iY<=67 then
citysort()
local tIrishsea = iplot, coastal, adjcoastal
end
if iX>=47 and iX<=57 and iY>=32 and iY<= 48 then
citysort()
local tSouthireland = iplot, coastal, adjcoastal
end
end
GameEvents.PlayerCityFounded.Add(citylist)
directions = {DirectionTypes.DIRECTION_NORTHEAST, DirectionTypes.DIRECTION_EAST, DirectionTypes.DIRECTION_SOUTHEAST,
DirectionTypes.DIRECTION_SOUTHWEST, DirectionTypes.DIRECTION_WEST, DirectionTypes.DIRECTION_NORTHWEST}
function citysort (iX, iY)
local CityPlot = Map.GetPlot(iX, iY);
if CityPlot:IsCoastalLand() then
-- If the city is on a coastal tile
return coastal
else
-- Or, if the city is adjacent to a coastal tile
for loop, direction in ipairs(directions) do
local pPlot = Map.PlotDirection(pCityPlot:GetX(), pCityPlot:GetY(), direction)
if (pPlot ~= nil and iPlayer == pPlot:GetOwner()) then
if (isCoastLine(pPlot)) then
if (pPlot:IsWater() and not pPlot:IsLake()) then
return adjcoast
end
end
end
end
end
end
Thank-you.
PS I have not tested the code as I am in the process of doing other tests and do not want to redo the project until that test is done.