General DLL programming questions

See the code in CvUnitAI::AI_genericUnitValueTimes100() which does do those evaluations. I wrote that routine while TB was working extensively on the combat mod so I didn't want to mess with AI_promotionValue() at the time as we'd have clashed. It was always intended that AI_promotionValue() would have similar code, but we forgot to actually port it over when TB was done with the combat mod changes. Please feel free to do so ;)

Note - AI_genericUnitValue() is used to evaluate how much an extant unit is actually worth during evaluation of combat results (i.e. - whether it's worth losing one set of units for another set of enemy kills).

That's not going to work too well because the unit value is calculated in CvUnitAI and the promotion value is calculated in CvPlayerAI (why I'm not quite certain).
 
That's not going to work too well because the unit value is calculated in CvUnitAI and the promotion value is calculated in CvPlayerAI (why I'm not quite certain).

So what? The CvUnitAI stuff can call a routine in CvPlayerAI for the common part if need be.
 
@AIAndy:

I have two questions for you about making the City Go To popup for Viewports.

1. Is this the correct way to make a popup list which will have all of the cities for a player in order as clickable buttons?

Code:
//ls612: City Goto in Viewports
bool CvDLLButtonPopup::launchGoToCityPopup(CvPopup *pPopup, CvPopupInfo &info)
{
	int iI;
	CvPlayer& pPlayer = GET_PLAYER(GC.getGameINLINE().getActivePlayer());
	CvWString szBuffer = gDLL->getText("TXT_KEY_POPUP_GOTO_CITY");
	CvCity* pCity;

	gDLL->getInterfaceIFace()->popupSetBodyString(pPopup, szBuffer);

	for (iI = 0; iI < pPlayer.getNumCities(); iI++)
	{
		pCity = pPlayer.getCity(iI);
		gDLL->getInterfaceIFace()->popupAddGenericButton(pPopup, gDLL->getText(pCity->getName()).c_str(), NULL, iI, WIDGET_GENERAL);
	}

	gDLL->getInterfaceIFace()->popupLaunch(pPopup, false, POPUPSTATE_IMMEDIATE);

	return true;
}

2. How do I create a key shortcut (ctrl-shift-G or something) that will raise the popup event?
 
@AIAndy:

I have two questions for you about making the City Go To popup for Viewports.

1. Is this the correct way to make a popup list which will have all of the cities for a player in order as clickable buttons?

Code:
//ls612: City Goto in Viewports
bool CvDLLButtonPopup::launchGoToCityPopup(CvPopup *pPopup, CvPopupInfo &info)
{
	int iI;
	CvPlayer& pPlayer = GET_PLAYER(GC.getGameINLINE().getActivePlayer());
	CvWString szBuffer = gDLL->getText("TXT_KEY_POPUP_GOTO_CITY");
	CvCity* pCity;

	gDLL->getInterfaceIFace()->popupSetBodyString(pPopup, szBuffer);

	for (iI = 0; iI < pPlayer.getNumCities(); iI++)
	{
		pCity = pPlayer.getCity(iI);
		gDLL->getInterfaceIFace()->popupAddGenericButton(pPopup, gDLL->getText(pCity->getName()).c_str(), NULL, iI, WIDGET_GENERAL);
	}

	gDLL->getInterfaceIFace()->popupLaunch(pPopup, false, POPUPSTATE_IMMEDIATE);

	return true;
}
It looks correct. But then I have not made that many popups yet so just use the code and find out if it works correctly.

2. How do I create a key shortcut (ctrl-shift-G or something) that will raise the popup event?
Best use a normal mission (as those can have hotkeys defined in the XML) and intercept it in the DLL.
 
Hm? Which XML are they in? Sorry but I'm a bit unfamiliar with this. Would the code be like the recalc triggering code?
Missions are in Civ4MissionInfos.xml and no, not like the recalc triggering code (although that would be an option if you don't want to go the mission way).
 
Missions are in Civ4MissionInfos.xml and no, not like the recalc triggering code (although that would be an option if you don't want to go the mission way).

Oh good, that looks easy. How do I handle the mission in the DLL? I can't seem to find where the missioninfos are used there.
 
Oh good, that looks easy. How do I handle the mission in the DLL? I can't seem to find where the missioninfos are used there.
Check CvGame::handleAction for the initial handling of missions (before messages, which is where you want to intercept it as you are not making a truely separate mission, just a special alias for the goto mission).
 
Check CvGame::handleAction for the initial handling of missions (before messages, which is where you want to intercept it as you are not making a truely separate mission, just a special alias for the goto mission).

If I'm just making it a normal mission do I need to do that or do I just need to add a case to CvDLLButtonPopup::launchButtonPopup (and the corresponding enum)?

Also how do I get the CvSelectionGroup involved in the mission to handle the mission?
 
If I'm just making it a normal mission do I need to do that or do I just need to add a case to CvDLLButtonPopup::launchButtonPopup (and the corresponding enum)?

Also how do I get the CvSelectionGroup involved in the mission to handle the mission?
If you look at CvGame::handleAction then you will see that the currently selected units are used.
You need to intercept the mission in CvGame::handleAction and then call your button popup stuff. Check how it is done for COMMAND_LOAD in that function.

After the button popup you just push a normal goto mission with CvGame::selectionListMove.
 
If you look at CvGame::handleAction then you will see that the currently selected units are used.
You need to intercept the mission in CvGame::handleAction and then call your button popup stuff. Check how it is done for COMMAND_LOAD in that function.

After the button popup you just push a normal goto mission with CvGame::selectionListMove.

How do I pass the plot of the city selected in the popup to the selectionListMove function?
 
How do I pass the plot of the city selected in the popup to the selectionListMove function?
I am not sure exactly what you are asking for. Do you want to know how to find out which city was actually selected in the popup?
 
Yes, because then I can get its plot and pass that to the move function.
You need to add a widget type for the city buttons and pass as the piece of data the city ID. Then in CvDLLWidgetData handle the actual pushing of the mission and use the city ID to get the city and its plot.
 
@AIAndy:

I'm encountering a strange problem. When I load the game with my new command and mission in the XML and enums, all of the unit command and mission buttons are gone from the UI and none of the shortcut keys for commands work. I looked and it says in a comment above the CommandTypes enum that all changes must be reflected in the GlobalTypes.xml, but there is nothing about commands in that XML file. I'm a bit confused as to what I'm doing wrong and why that comment is there in the CvEnums.h.
 
@AIAndy:

I'm encountering a strange problem. When I load the game with my new command and mission in the XML and enums, all of the unit command and mission buttons are gone from the UI and none of the shortcut keys for commands work. I looked and it says in a comment above the CommandTypes enum that all changes must be reflected in the GlobalTypes.xml, but there is nothing about commands in that XML file. I'm a bit confused as to what I'm doing wrong and why that comment is there in the CvEnums.h.
You have a new command AND a new mission? Why?
Use either a command or a mission and I recommend using a mission as that is what you will eventually push after the popup.
The command enum must have the same order and length as the entries in CIV4CommandInfos.
The same is true for the mission enum and CIV4MissionInfos except that you may have more entries in CIV4MissionInfos than in the enum but those you refer to in the enum need to be at the start of CIV4MissionInfos and in the same order.
 
You have a new command AND a new mission? Why?
Use either a command or a mission and I recommend using a mission as that is what you will eventually push after the popup.
The command enum must have the same order and length as the entries in CIV4CommandInfos.
The same is true for the mission enum and CIV4MissionInfos except that you may have more entries in CIV4MissionInfos than in the enum but those you refer to in the enum need to be at the start of CIV4MissionInfos and in the same order.

I'm sorry to ask so many questions, but this is rather hard. I've changed it to be a mission, but now it isn't showing up on any units. I see though that some units have action tags for special missions, but I don't want to make that for every unit. How do I make a new mission by default available for every unit?
 
I'm sorry to ask so many questions, but this is rather hard. I've changed it to be a mission, but now it isn't showing up on any units. I see though that some units have action tags for special missions, but I don't want to make that for every unit. How do I make a new mission by default available for every unit?
The function that determines if a unit can do a specific mission is CvGame::canHandleAction (in CvGameInterface.cpp). For missions that forwards the handling to CvSelectionGroup::canStartMission. When that function returns true, the mission button will be displayed. Just add a case to the big switch in there for your mission and return true.
 
I'm sorry to ask so many questions, but this is rather hard.
Don't worry Bro... I feel your pain. I warned this wasn't easy and I'm getting a little lost just trying to follow the conversation. I worked stuff out enough to DO things but trying to understand what someone's telling me or how to express anything about it effectively enough to communicate? Ugh...
 
Back
Top Bottom