Obsoleting Corporations

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
First off, I know The J has a python modcomp that "obsoletes" corporations, but I have a (unnatural) aversion to python, and it technically doesn't "obsolete" corporations the way I would in the SDK.

I added an obsolete tag to CvCorporationInfo, and some code to CvTeam in ProcessTechs(), but all it seems to do is lock up my game when I research the obsoletion tech, so I'm sure I mucked it up.

Here's the code from ProcessTechs, red code is added by me, regular text is default Firaxis code:
Code:
for (iI = 0; iI < GC.getNumCorporationInfos(); ++iI)
                        {
                            if (GC.getCorporationInfo((CorporationTypes)iI).getTechPrereq() == eIndex)
                            {
                                if (!(GC.getGameINLINE().isCorporationFounded((CorporationTypes)iI)))
                                {
                                    iBestValue = MAX_INT;
                                    eBestPlayer = NO_PLAYER;

                                    for (iJ = 0; iJ < MAX_PLAYERS; iJ++)
                                    {
                                        if (GET_PLAYER((PlayerTypes)iJ).isAlive())
                                        {
                                            if (GET_PLAYER((PlayerTypes)iJ).getTeam() == getID())
                                            {
                                                iValue = 10;

                                                iValue += GC.getGameINLINE().getSorenRandNum(10, "Found Corporation (Player)");

                                                if (GET_PLAYER((PlayerTypes)iJ).getCurrentResearch() != eIndex)
                                                {
                                                    iValue *= 10;
                                                }

                                                if (iValue < iBestValue)
                                                {
                                                    iBestValue = iValue;
                                                    eBestPlayer = ((PlayerTypes)iJ);
                                                }
                                            }
                                        }
                                    }

                                    if (eBestPlayer != NO_PLAYER)
                                    {
                                        GET_PLAYER(eBestPlayer).foundCorporation((CorporationTypes)iI);
                                        bFirstBonus = true;
                                    }
                                }
                            }
                            
                            
[COLOR=Blue]                            else if (GC.getCorporationInfo((CorporationTypes)iI).getObsoleteTech() == eIndex)
                            {
                                bool bObsolete = false;
                                for (iJ = 0; iJ < MAX_PLAYERS; iJ++)
                                {
                                    if (GET_PLAYER((PlayerTypes)iJ).isAlive())
                                    {
                                        if (GET_PLAYER((PlayerTypes)iJ).getTeam() == getID())
                                        {
                                            if (GET_PLAYER((PlayerTypes)iJ).hasHeadquarters((CorporationTypes)iI))
                                            {
                                                CvCity* pHeadquarters = GC.getGameINLINE().getHeadquarters((CorporationTypes)iI);
                                                if (NULL != pHeadquarters)
                                                {
                                                    bObsolete = true;
                                                }
                                            }
                                        }
                                    }
                                }
                                if (bObsolete)
                                {
                                    for (iJ = 0; iJ < MAX_PLAYERS; iJ++)
                                    {
                                        if (GET_PLAYER((PlayerTypes)iJ).isAlive())
                                        {
                                            int iLoop;
                                            CvCity* pLoopCity;
                                            for (pLoopCity = GET_PLAYER((PlayerTypes)iJ).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER((PlayerTypes)iJ).nextCity(&iLoop))
                                            {
                                                pLoopCity->setHasCorporation((CorporationTypes)iI, false, false, false);
                                                pLoopCity->updateCorporation();
                                                pLoopCity->setInfoDirty(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }[/COLOR]

I'm sure there is more code than this I have to change, but I don't see why this as it is causes a lock-up. (It doesn't CTD, just locks the game up, as if in an infinite loop)
 
I gave it a cursory glance, and it looks like you are using the correct loop counters in each part. My first guess would be that removing the corporation from the city with the headquarters before removing it from all other cities may have bad repercussions. In your first loop, store a pointer to the headquarters, skip it in your second loop, and finally remove it at the end.

Actually, the first part doesn't even need to loop or use the bOlsolete flag. Just grab the headquarters and check if the city belongs to a player on the same team. Also, setHasCorporation() already calls updateCorporation() and setInfoDirty() so don't call them again in the loop.

Code:
CvCity* pHeadquarters = GC.getGameINLINE().getHeadquarters((CorporationTypes)iI);
if (pHeadquarters != NULL && GET_PLAYER(pHeadquarters->getOwnerINLINE()).getTeam() == getTeam())
{
	// obsolete the corporation; skip bObsolete and first entire loop
	
	// remove corporation from each city except headquarters
	for (iJ = 0; iJ < MAX_PLAYERS; iJ++)
	{
		if (GET_PLAYER((PlayerTypes)iJ).isAlive())
		{
			int iLoop;
			CvCity* pLoopCity;
			CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iJ);
			
			for (pLoopCity = kPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kPlayer.nextCity(&iLoop))
			{
				if (pLoopCity != pHeadquarters)
				{
					pLoopCity->setHasCorporation((CorporationTypes)iI, false, false, false);
				}
			}
		}
	}
	
	// remove headquarters
	pHeadquarters->setHasCorporation((CorporationTypes)iI, false, false, false);
}

If I may, this seems a bit instantaneous and drastic. My first attempt would be to have the corporation (except headquarters) removed from all team member cities. If a team member has the headquarters, it would continue to earn :gold: but not provide the resource-related benefits.

But other teams would continue to receive those benefits and pay corporation maintenance. Only once they researched the obsoleting tech would they lose the benefits and maintenance costs.

For example, say you added Cold Fusion as an obsoleting tech for Standard Ethanol. Once researched, the founder of the corporation could continue to run the corporation in foreign states that don't have this technology. They'd still need ethanol and be willing to pay for it.

Consider that corporations are distributed in nature. Once the corporation has spread to a foreign city, it operates entirely converting resources to other things locally. That the founder of the corporation discovers a technology that makes this process obsolete shouldn't stop the foreigner from continuing to make use of the process.

Food for thought.
 
If I may, this seems a bit instantaneous and drastic. My first attempt would be to have the corporation (except headquarters) removed from all team member cities. If a team member has the headquarters, it would continue to earn :gold: but not provide the resource-related benefits.

Does a corporation even work anymore if the headquarters is destroyed? I never have tried to raze a corporation HQ to the ground, I always wanted it for myself. That's something I need to test today/

But other teams would continue to receive those benefits and pay corporation maintenance. Only once they researched the obsoleting tech would they lose the benefits and maintenance costs.

For example, say you added Cold Fusion as an obsoleting tech for Standard Ethanol. Once researched, the founder of the corporation could continue to run the corporation in foreign states that don't have this technology. They'd still need ethanol and be willing to pay for it.

Consider that corporations are distributed in nature. Once the corporation has spread to a foreign city, it operates entirely converting resources to other things locally. That the founder of the corporation discovers a technology that makes this process obsolete shouldn't stop the foreigner from continuing to make use of the process.

Food for thought.

Thanks. I was operating under the premise that once the HQ was gone, the corporation should just collapse. However, I can do this instead, it seems more logical.
 
Does a corporation even work anymore if the headquarters is destroyed? I never have tried to raze a corporation HQ to the ground, I always wanted it for myself. That's something I need to test today/

You can even create a corporation without a headquarter ;).
 
Note that I said the headquarters should remain in the city even though it only provides the :gold: from rival corporations. The :gold: received would decrease because the corporation would be removed from all team-members' cities save the one with the HQ.

You'd have to do a little trickery to keep the corporation in that one city yet remove it from the global count and its effects, but I'm confident that can be overcome. It would be like purging a religion from all of your cities but keeping the shrine for the income (no happiness, no incense boost--only :gold: and non-religion-based :commerce:).
 
Top Bottom