Source Code: Auto-Research

Discuss the future of Warzone 2100 with us.
smallfly
Trained
Trained
Posts: 85
Joined: 21 Aug 2009, 10:26

Source Code: Auto-Research

Post by smallfly »

As there is temporarily no forum, where we can discuss source code issues (not general development issues) i place my question here (hoping there will be a "Source Code" forum in future)

I want to realize a function, that automatically starts a new research topic after 10 seconds if a research facility is free and the user switched on an option "enable auto-research"

I want to implement the function in the source code file "hci.c" more precisely in void intCheckResearchButton(void)

Code: Select all

/*Checks to see if there are any research topics to do and flashes the button -
only if research facility is free*/
void intCheckResearchButton(void)
{
    UWORD       index, count;
	STRUCTURE	*psStruct;
	BOOL		resFree = false;

	for (psStruct = interfaceStructList(); psStruct != NULL; psStruct =
		psStruct->psNext)
	{
		if (psStruct->pStructureType->type == REF_RESEARCH &&
            psStruct->status == SS_BUILT &&
			((RESEARCH_FACILITY *)psStruct->pFunctionality)->psSubject == NULL)
		{
			addConsoleMessage(_("Research Facility is free!"), LEFT_JUSTIFY, SYSTEM_MESSAGE);
			resFree = true;
			break;
		}

	}

	if (resFree)
	{
		//set to value that won't be reached in fillResearchList
        //needs to be UWORD sized for the Patches
        index = (UWORD)(numResearch + 1);
		//index = (UBYTE)(numResearch + 1);
		//calculate the list
		count = fillResearchList(pList,selectedPlayer, index, MAXRESEARCH);
		if (count)
		{
			//set the research reticule button to flash
			flashReticuleButton(IDRET_RESEARCH);
		}
	}
}
I looked through the source code but i still dont know how to realize the function. The dummy code would be

Code: Select all

if (research facility is free)
{
     get first unresearched topic
     start this topic in free research facility
}
Kacen
Trained
Trained
Posts: 294
Joined: 19 Feb 2007, 19:28

Re: Source Code: Auto-Research

Post by Kacen »

I'm fine with it as long as this can be toggled off and on in-game.

Otherwise the research facility may research low-priority topics and use up your resources.
zeland
Rookie
Rookie
Posts: 28
Joined: 14 Aug 2009, 01:24

Re: Source Code: Auto-Research

Post by zeland »

Kacen wrote:Otherwise the research facility may research low-priority topics and use up your resources.
The Auto-research function should then follow (or try to follow) the line of research of the previously researched item. Eg. you start researching Light Cannon, next you'll start research on cannon rounds etc instead of ending up researching flamer or something else.
smallfly
Trained
Trained
Posts: 85
Joined: 21 Aug 2009, 10:26

Re: Source Code: Auto-Research

Post by smallfly »

Thats the problem that i meant. You start discussing about the sense, the advantages, disadvantages and possible options of auto-researching, but in this topic i really wanted to learn something about the piece of code i posted.

I would be very happy about an answer like (warning!dummy code!)

Code: Select all

for (psResearchTopic = playerResearchList(); psResearchTopic != NULL; psResearchTopic =
      psResearchTopic ->psNext)
{
     if (psResearchTopic->name == playerResearchWishList->nextTopic->name)
       playerResearchWishList->nextTopic->start();   
}
themac
Trained
Trained
Posts: 415
Joined: 17 Jul 2009, 19:14
Location: Germany

Re: Source Code: Auto-Research

Post by themac »

I personally would prefer if the auto-research-option would choose the cheapest available item to go on researching!
smallfly
Trained
Trained
Posts: 85
Joined: 21 Aug 2009, 10:26

Re: Source Code: Auto-Research

Post by smallfly »

themac wrote:I personally would prefer if the auto-research-option would choose the cheapest available item to go on researching!
even better. sounds easier to realize ;) so who knows enough about warzone coding to show how the realization looks like as c++ code?