contingency how to get givepower to work?

For AI and campaign script related discussions and questions
Post Reply
User avatar
WZ2100ModsFAn
Trained
Trained
Posts: 271
Joined: 15 Apr 2018, 17:25
Location: United States.

contingency how to get givepower to work?

Post by WZ2100ModsFAn » 20 Jul 2018, 21:02

it works with 3.1.5 but in master it no longer works

is the old enumstruct deprecated?

@Berserk Cyborg

Code: Select all

var additionalPower = [0,0,0,0,0,0,0,0,0,0,0,0];
function givePower()
{
	for (var playnum = 0; playnum < maxPlayers; playnum++)
	{
		var windFarms = enumStruct(playnum, "WindFarm");
		var activeWindFarms = 0;
		var activeDerricks = 0;
		for (var i=0; i < windFarms.length; i++)
		{
			if (windFarms[i].status = BUILT)
				activeWindFarms+=1;
		}
		if (playerData[playnum].difficulty == INSANE)
		{
			var Derricks = enumStruct(playnum, "A0ResourceExtractor");
			for (var i=0; i < windFarms.length; i++)
			{
				if (Derricks[i].status = BUILT)
					activeDerricks+=1;
			}
			additionalPower[playnum] += ((activeWindFarms*2)+activeDerricks+20)*.1;
		}
		else
		{
			additionalPower[playnum] += (activeWindFarms+10)*.1;
		}
		while (additionalPower[playnum] >= 1)
		{
			setPower(playerPower(playnum)+1, playnum);
			additionalPower[playnum] -= 1;
		}
	}
}
no crash it gives you no power bonus once your out of oil derricks
Apologies if i dont see your post
central time usa

User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 639
Joined: 26 Sep 2016, 19:56

Re: contingency how to get givepower to work?

Post by Berserk Cyborg » 20 Jul 2018, 23:27

There were some mistakes like

Code: Select all

if (windFarms[i].status = BUILT)
and the other for loop, which I assume wants to count derricks, was evaluating the length of the windFarms array. So I corrected that. Also, that while loop was pretty redundant so I made it give a bulk power gain instead.

Derricks do not give any bonuses unless the player is insane difficulty (AI only). A human player will never get those bonuses (as they will always be on medium difficulty). So you will need to modify the code a little bit if you want that.

Unable to test this so hopefully it works.

Code: Select all

var additionalPower = [0,0,0,0,0,0,0,0,0,0,0,0];
function givePower()
{
	for (var playnum = 0; playnum < maxPlayers; ++playnum)
	{
		var windFarms = enumStruct(playnum, "WindFarm");
		var activeWindFarms = 0;
		var activeDerricks = 0;
		for (var i = 0; i < windFarms.length; ++i)
		{
			if (windFarms[i].status === BUILT)
			{
				activeWindFarms += 1;
			}
		}
		if (playerData[playnum].difficulty === INSANE)
		{
			var Derricks = enumStruct(playnum, "A0ResourceExtractor");
			for (var i = 0; i < Derricks.length; ++i)
			{
				if (Derricks[i].status === BUILT)
				{
					activeDerricks += 1;
				}
			}
			additionalPower[playnum] += Math.floor(((activeWindFarms * 2) + activeDerricks + 20) * 0.1);
		}
		else
		{
			additionalPower[playnum] += Math.floor((activeWindFarms + 10) * 0.1);
		}
		if (additionalPower[playnum] >= 1)
		{
			setPower(playerPower(playnum) + additionalPower[playnum], playnum);
			additionalPower[playnum] = 0;
		}
	}
}

User avatar
WZ2100ModsFAn
Trained
Trained
Posts: 271
Joined: 15 Apr 2018, 17:25
Location: United States.

Re: contingency how to get givepower to work?

Post by WZ2100ModsFAn » 21 Jul 2018, 02:09

Berserk Cyborg wrote:There were some mistakes like

Code: Select all

if (windFarms[i].status = BUILT)
and the other for loop, which I assume wants to count derricks, was evaluating the length of the windFarms array. So I corrected that. Also, that while loop was pretty redundant so I made it give a bulk power gain instead.

Derricks do not give any bonuses unless the player is insane difficulty (AI only). A human player will never get those bonuses (as they will always be on medium difficulty). So you will need to modify the code a little bit if you want that.

Unable to test this so hopefully it works.

Code: Select all

var additionalPower = [0,0,0,0,0,0,0,0,0,0,0,0];
function givePower()
{
	for (var playnum = 0; playnum < maxPlayers; ++playnum)
	{
		var windFarms = enumStruct(playnum, "WindFarm");
		var activeWindFarms = 0;
		var activeDerricks = 0;
		for (var i = 0; i < windFarms.length; ++i)
		{
			if (windFarms[i].status === BUILT)
			{
				activeWindFarms += 1;
			}
		}
		if (playerData[playnum].difficulty === INSANE)
		{
			var Derricks = enumStruct(playnum, "A0ResourceExtractor");
			for (var i = 0; i < Derricks.length; ++i)
			{
				if (Derricks[i].status === BUILT)
				{
					activeDerricks += 1;
				}
			}
			additionalPower[playnum] += Math.floor(((activeWindFarms * 2) + activeDerricks + 20) * 0.1);
		}
		else
		{
			additionalPower[playnum] += Math.floor((activeWindFarms + 10) * 0.1);
		}
		if (additionalPower[playnum] >= 1)
		{
			setPower(playerPower(playnum) + additionalPower[playnum], playnum);
			additionalPower[playnum] = 0;
		}
	}
}
got part of it fixed.

there isn't any power generated when there's no oil derricks.

it's appreciated :)

Code: Select all

var additionalPower = [0,0,0,0,0,0,0,0,0,0,0,0];
// Give all players a little power every second. More power is given if the player built more wind farms. INSANE AIs receive more power from Wind Turbines than other players, as well as additional power from each Oil Derrick they own.
function givePower() {
	for (var playnum = 0; playnum < maxPlayers; playnum++) {
		var windFarms = enumStruct(playnum, "WindFarm");
		var activeWindFarms = 0;
		var activeDerricks = 0;
		var powerMultiplier = powerType/400;
		for (var i=0; i < windFarms.length; i++) {
			if (windFarms[i].status = BUILT)
				activeWindFarms+=1;
		}
		if (playerData[playnum].difficulty == INSANE) {
			var Derricks = enumStruct(playnum, "A0ResourceExtractor");
			for (var i=0; i < Derricks.length; i++)
				if (Derricks[i].status = BUILT)
					activeDerricks+=1;
			additionalPower[playnum] += ((activeWindFarms*2)+activeDerricks+20)*.1*powerMultiplier;
		}
		else
			additionalPower[playnum] += (activeWindFarms+10)*.1*powerMultiplier;
		while (additionalPower[playnum] >= 1) {
			setPower(playerPower(playnum)+1, playnum);
			additionalPower[playnum] -= 1;
		}
	}
}
it gives you two power a second when there are no oil derricks or any power generators.
Apologies if i dont see your post
central time usa

Post Reply