Help improve the expansion pack!

Hi Thal...

Looked a bit at how to change Plot_GetPlotsInCircle, I see that it returns a table of land plots. I am not too familiar with LUA, but if I did this in C++ using an array I guess there is no easy way for LUA to access that array information which is what you are looking for.

One way, if I can find how to expose a new C++ function to LUA (should be). Then I would to modify your Plot_GetPlotsInCircle function so that it stills fills in the table of land plots but all the finding of those single plots would be done in C++. Do you think that should give the efficiency you need?


Need to rethink this, seems the current code is already pushing arrays to LUA...
 
The key thing I need to know is the process. The steps are more important than the code itself. I figure you're a good mentor because you seem familiar with the steps to make a core mod. If I can see an example of how to do just 1 building attribute, I can do all the other attributes by following in your footsteps.

It's like the difference between giving someone fish and learning how to fish. If I can watch you catch 1 fish, I can learn to catch a dozen! :lol:

How to set up the mod? Where are the places to hook in new code? I'm familiar with writing lua and c++, so I can figure out how to convert algorithms, once I know the right steps to get there. If the function poses too much of a problem, just do whatever seems easiest.

You probably recognized GetPlotsInCircle(minR, maxR) is intended as a method of the CvPlot class. It can return an array of plot IDs instead of plot tables. The code calling plot:GetPlotsInCircle() could loop through that ID list, figure out which plot corresponds to each ID, and set the owner of the plot, if this makes sense.


If GetPlotsInCircle was a core c++ function, I think the lua code would look like this, if it helps:
Code:
[B]local centerPlot = targetCity:Plot()[/B]
local borderExpand = buildingInfo.InstantBorderRadius
if borderExpand ~= 0 then
    for _, adjPlotID in pairs([B]centerPlot:[/B]GetPlotsInCircle(1, borderExpand)) do
        [B]local adjPlot = Map.GetPlotByIndex(adjPlotID)[/B]
        if adjPlot:GetOwner() == -1 then
            adjPlot:SetOwner(playerID, city:GetID())
        end
    end
end
 
I think I am miles behind you and other modders around here. Learning mostly while changing stuff around and testing a lot. Need to know better how LUA and C++ tie together, I need to verify if it is so easy for a C++ function to create an array and make that available for LUA. If that is the case it would be easy to fit some similar code which I have found in other functions that check several plots around the city.

There is also an interesting function that is called GetNeigbourghPlots or similar which could also fit in this solution. I think I have also find how C++ is able to read XML tags, will have to do some tests stil.
 
I think I am advancing on the right direction but I will like confirmation. I am acting too much on instinct, wished I had more deep understanding on how all of this works.

First, for accessing XML values from C++ I am using this guide, it is from Civ 4 but I think it matches, need to verify with a small test code I prepared.

http://forums.civfanatics.com/showthread.php?t=166935

Secondly I have been looking at the C++ exposure to LUA to solve the plot iteration problem, seems that the exposure is done with the code under the LUA folder, so in our case it would be something like this:

Code:
int CvLuaCity::lGetPlotsInCircle(lua_State* L)
{
	CvCity* pkCity = GetInstance(L);
	const int iMin = lua_tointeger(L, 2);
	const int iMax = lua_tointeger(L, 3);	
	std::vector<int> aiPlotList;
	aiPlotList.resize(20, -1);
	pkCity->GetCityRing(aiPlotList,iMin,iMax);

	int iReturnValues = 0;

	for(uint ui = 0; ui < aiPlotList.size(); ui++)
	{
		if(aiPlotList[ui] >= 0)
		{
			CvPlot* pkPlot = GC.getMap().plotByIndex(aiPlotList[ui]);
			CvLuaPlot::Push(L, pkPlot);
			iReturnValues++;
		}
		else
		{
			break;
		}
	}

	return iReturnValues;
}

Then the C++ function that actually returns the list of plots, based on a similar function that searched for purchasable plots:

Code:
void CvCity::GetCityRing(std::vector<int>& aiPlotList, iMinRing, iMaxRing)
{
	VALIDATE_OBJECT
	aiPlotList.resize(20, -1);
	int iResultListIndex = 0;

	CvPlot* pLoopPlot = NULL;
	int iDX, iDY;


	for (iDX = -iMaxRing; iDX <= iMaxRing; iDX++)
	{
		for (iDY = -iMaxRing; iDY <= iMaxRing; iDY++)
		{
			if (abs(iDX)>=iMinRing && abs(iDY)>=iMinRing)
			{
				pLoopPlot = plotXY(getX(), getY(), iDX, iDY);
				if (pLoopPlot != NULL)
				{
					if (pLoopPlot->getOwner() != NO_PLAYER)
					{
						continue;
					}	
					aiPlotList[iResultListIndex] = pLoopPlot->GetPlotIndex();
					iResultListIndex++;				
				}
			}
		}
	}

}

And finally the call to the exposed function in the LUA code, similar to what you put in first place:

pCity:GetPlotsInCircle(1,2)
pCity:GetPlotsInCircle(minradius,maxradius)
will return the list of plots in the ring of the city plot between (limits included) the min and max values given


I will go ahead and try to test all this as for me it is a good way to learn, just hope this is also of help for you.
 
If you can, make the function a method of CvPlot. This particular situation uses it on a city plot, but getting plots in a circle is used elsewhere for plots outside cities. :)
 
Just a tiny bug: If you chose "Restart Game" and play on the new map, some of the building info disappears. If you exit and reload the same game they reappear. Nothing major, just something to keep an eye out for.
 
Thal, the XML tag reading works. I am going to test the GetPlotsRing call from LUA, but looking at CivUP it appears no building has the InstantBorderRadius set to something other than 0. For the test I can manually set one of them, just wanted to know if I was missing something.

Also the source code has been updated it now matches the game version, time to include the DLL with your mod ;)
 
Hello friend Thalassicus, how are you? I am a regular fan of your mods, which let me explore more deeply this wonderful game called Civ5 and its expansion.

I have set the task of translating 100% both civ5up as GEM to spanish text, as the civ5UP story is mistranslated in regards to grammar and missing some parts)

So I set out to start from scratch and I'm at 60% or so, the translation is as faithful as possible using the original terms of the game in Spanish (I´m comparing original terms in original XML files).

I ask you, is there any way / tool to extract effective texts and to translate them without problem?

The idea is to extract only the text, not the xml code and then insert the translations.

How can I do a debug of texts while gaming to look what I'm missing?

Thank you for your wonderful work.
 
@rf900
Ooops! Your post about the c++ version of GetPlotsInCircle happened while I was away visiting family for Christmas, then the thread was not marked as "new post to read" when I got back! :crazyeye:

If you could post a small example mod which simply give the Terracotta Army a border radius of 3, using what you've discovered, this will give me a great starting point to learn core modding. :goodjob:

@Johnny Deacon
I started a thread for us to discuss this: click here
 
Thal, not sure what I can add. I basically took you LUA code of post 162.

And then the ones in 167 for the C++ functions, changed them to CvPlot instead of CvCity as you suggested, the functions themselves are the same.

You need to create one function that is exposed to LUA, parameters are read by accessing the LUA state=stack (not too familiar with it). And then the actual function that returns the list of plots. Anyway I think post 167 explains it quite well, let me know what is not clear.
 
I tested with your enhanced mod and patch 2.2.7 changing the monument attribute. I think this DLL was compiled before the update code in the SDK.

For the modinfo file I add it with the import set to 1.

<File md5="1ff04879f2bde1b9749220253c757169" import="1">CvGameCore_Expansion1.dll</File>
 

Attachments

  • instantring.zip
    1.3 MB · Views: 119
Hi,

My friend and I hotseat your mod and love the devil out of it. We've noticed that a lot of the new quotes don't have voice work, and I was wondering if I were to record some of them for you and they were of decent post-production quality, if you'd want them.

-GE
 
Top Bottom