Electricity mod/Resource requiring Buildings?

KnelRivendare

Warlord
Joined
Jan 13, 2012
Messages
271
so i would like to know what happens to resource requiring buildings like "Factory"
if you dont have the req' resources anymore? does the bonus of the building drop?

i tested this myself but i havent found any penalty when im out of the req' resource maybe im just overlooking something maybe someone of you guys knows it.

im asking this because im thinking about making a "Electricity" mod where power is an actual resource and you have to take care what you build, since you need the power to run it.

im finding it odd that electricity has no presentation in the game at all even tho it's such an important thing nowadays,

All modern buildings will require power,

and you will get the power via power plants, some give a lot of power but also unhappiness and unhealthiness such as "coal plants" and "nuclear plants" or solar plants which dont give much power but no penalty in health and happiness.

also it would be great to make it possible to sabotage these power plants with spies or bombing but thats way out of my league.


sincerely yours Knel~
 
Cool ideas. I do think that currently, once you have build the factory, it will continue to function even if you loose acces to Coal - unlike units, who will get a penalty once you loose the resource.
 
you can easy test it using the InGame Editor from DonQuiche.

That's an interesting question I will have a look in it as well.
 
mhm seems like there really isnt any penalty when losing the resource so theres a workaround needed for that first, ive been a bit to naiv too think that this mod could be done via "XML" coding.

tho i will start making the basics for now, meaning the buildings the resource and balancing.
 
What you can probably do is to give the building a boost in production when the required resource is available. But I don't know what would happen if suddenly you had 5 buildings for only 4 resources!

It's too bad because with the code that Redox wrote to make the lumbermill give timber it would be easy to have windmills produce electricity and as tile improvement they would require some protection!
 
Come to think of it, power plants as tile improvements -to defend them against pillagers, would be really more interesting and it would make them an essential part of modern warfare.

What you can probably do is to give the building a boost in production when the required resource is available.
what code would that be?
 
what code would that be?

I will have a look in it this evening when I am back at home. But there are some examples in game : if I'm right the temple has a boost in culture (or happiness, not sure) if wine is available.
 
I will have a look in it this evening when I am back at home. But there are some examples in game : if I'm right the temple has a boost in culture (or happiness, not sure) if wine is available.

found it, its the monastery that provides more faith and more culture if incense or wine is available,
trying that out now:
Code:
<Building_ResourceYieldChanges>
		<Row>
			<BuildingType>BUILDING_BROADCAST_TOWER</BuildingType>
			<ResourceType>RESOURCE_ELECTRICPOWER</ResourceType>
			<YieldType>YIELD_GOLD</YieldType>
			<Yield>+100</Yield>
		</Row>
</Building_ResourceYieldChanges>


Edit: aw got that wrong, that code just increases the tile yield if the resource is on it, but "megawatts" arent just lying around on the grass :P


wouldnt it be possible to add the "very unhappy empire" modifier or something alike to your Civ if you are out of electric power?


here is what i have done for now if anyone is interested in it:
 

Attachments

this means that we need a "Building_ResourceProductionChanges" like the "Building_ResourceCultureChanges" table.

It can probably be added with Lua but it's out of my skills for now :(
 
this means that we need a "Building_ResourceProductionChanges" like the "Building_ResourceCultureChanges" table.

It can probably be added with Lua but it's out of my skills for now :(

mhm maybe we can find a workaround maybe even without LUA; -lua stuff always makes the turn times longer anyways :P
 
found it, its the monastery that provides more faith and more culture if incense or wine is available,
trying that out now:
Code:
<Building_ResourceYieldChanges>
		<Row>
			<BuildingType>BUILDING_BROADCAST_TOWER</BuildingType>
			<ResourceType>RESOURCE_ELECTRICPOWER</ResourceType>
			<YieldType>YIELD_GOLD</YieldType>
			<Yield>+100</Yield>
		</Row>
</Building_ResourceYieldChanges>


Edit: aw got that wrong, that code just increases the tile yield if the resource is on it, but "megawatts" arent just lying around on the grass :P


wouldnt it be possible to add the "very unhappy empire" modifier or something alike to your Civ if you are out of electric power?


here is what i have done for now if anyone is interested in it:

This is a very cool concept that I have thought about myself but haven't looked into it yet. I am just getting started on a mod of my own and would like to incorporate something like this. My mod will be geared towards a post Industrial Age world kind of based on the Empires of the Smoky Skies scenario.

What I am wondering is if you could rethink your approach and use this discovery to accomplish the task. What if electricity were a YIELD like :culture:? Then you would modify the amount of electricity produced by the city by using a power plant building modeled after the monastery. The coal plant wouldn't require any coal for the initial build but it would need to have coal within the city's radius in order for it to increase the amount of electricity YIELD produced by the city. A Hydro plant would still have to be built in a city next to a river and then could modify the electricity YIELD. A nuclear plant would obviously be the same as a coal plant. A solar plant would be the same as a hydro plant. I think it requires a desert tile if I'm not mistaken. Anyway, that's my thoughts on the subject. I hope you can get something like this working. I will be happy to use it and give you credit as it will save me from doing the experimenting myself.
 
This is a very cool concept that I have thought about myself but haven't looked into it yet. I am just getting started on a mod of my own and would like to incorporate something like this. My mod will be geared towards a post Industrial Age world kind of based on the Empires of the Smoky Skies scenario.

What I am wondering is if you could rethink your approach and use this discovery to accomplish the task. What if electricity were a YIELD like :culture:? Then you would modify the amount of electricity produced by the city by using a power plant building modeled after the monastery. The coal plant wouldn't require any coal for the initial build but it would need to have coal within the city's radius in order for it to increase the amount of electricity YIELD produced by the city. A Hydro plant would still have to be built in a city next to a river and then could modify the electricity YIELD. A nuclear plant would obviously be the same as a coal plant. A solar plant would be the same as a hydro plant. I think it requires a desert tile if I'm not mistaken. Anyway, that's my thoughts on the subject. I hope you can get something like this working. I will be happy to use it and give you credit as it will save me from doing the experimenting myself.





your idea sounds legit but theres one problem in that, atleast for me, "yields" arent tradeable and i really would like to have something like electricity deals, a country that overproduces electricity sells it to other countries just like in real.

A week ago or so i had a workaround in my head to do it all with xml but it was late i went to sleep and forgot it all, since then i always right down every idea i have :lol:

Im getting a bit into LUA right now, with lua there must be a way to shut down specific buildings or rather to give the whole empire a production malus without the resource required,
tho im just at the very start.
 
I would love to see this mod to be done,


your idea sounds legit but theres one problem in that, atleast for me, "yields" arent tradeable and i really would like to have something like electricity deals, a country that overproduces electricity sells it to other countries just like in real.

A week ago or so i had a workaround in my head to do it all with xml but it was late i went to sleep and forgot it all, since then i always right down every idea i have :lol:

Im getting a bit into LUA right now, with lua there must be a way to shut down specific buildings or rather to give the whole empire a production malus without the resource required,
tho im just at the very start.

Couldn't it be tradable the same way that you trade GPT or a lump sum of gold? I think that kind of gold is treated as a yield rather than a resource but it is tradable. It might be difficult to get the AI to use it properly but then I'm not sure it would. They don't seem to have any trouble trading GPT or lump sums. Granted, a lump sum deal would be a little weird compared to a GPT deal but then I guess you could look at it as a "we will trade you this amount of megawatts and no more" vs "we will trade you x number of megawatts for the next few years, months, etc." Then for the buildings that require electricity you treat it the same as maintenance. Instead of it being gold maintenance it would be so much electricity to maintain. And then you run into an electricity deficit and not sure how that would work but should be similar to happiness. Your empire starts to bog down with not enough power.
 
And then you run into an electricity deficit and not sure how that would work but should be similar to happiness. Your empire starts to bog down with not enough power.


thats the main problem here, to get a negative effect when you are out of electricity.
 
thats the main problem here, to get a negative effect when you are out of electricity.

Yeah, I agree that it might be tricky. It kind of depends on whether or not you could make it a yield that is kind of a hybrid of :c5gold: and :c5happy:. I haven't attempted to tackle LUA so I'm not sure what is possible. My preference would be to see it as an entirely XML mod comp but it may be necessary to have the negative effect dealt with in LUA if there are no XML tags that can be used to duplicate the way negative happiness affects :c5production: and :c5food:. As for the rest of it, I think it can all be done using XML in the way that I described based on your idea for using the monastery as a model.


Afterthought:
If all of the buildings required power/electricity as part of their maintenance and you don't have enough power/electricity, would their :c5happy:, :c5culture:, and :c5production: effects be reduced or eliminated? This might be a way to accomplish it with XML if the answer is yes. Or the player might have to sell the buildings in order to break even or produce a power surplus which would totally eliminate their effects since they had to be "demolished". I don't remember what happens when you run a deficit of GPT and the treasury runs dry. I think you are allowed to run a deficit for a little while but it eventually bogs you down as well. So just having the buildings require an electricity maintenance might be enough if the amount of power available is treated like :c5gold:.
 
If your treasury runs dry your research will decrease and your units will disband.

but, looking through the files i see no way to edit the Gold/Happiness system or even duplicate the system to change it to a electricity system, sounds like DLL modding to me.

I think the "Resource" system is the "easier" way.
 
you could make electricity a resource required by all industrial and post industrial units (and it makes sense, what works whithout electricty? even the infantry needs it for it's radio and communications). This way if you run in negativ the units will be less efficient. And if electricity is required for all buildings it will have an impact on which buildings can be build. The bad side is that it will not impact production at all :(
 
you could make electricity a resource required by all industrial and post industrial units (and it makes sense, what works whithout electricty? even the infantry needs it for it's radio and communications). This way if you run in negativ the units will be less efficient. And if electricity is required for all buildings it will have an impact on which buildings can be build. The bad side is that it will not impact production at all :(

true that! atleast one thing thats easy achievable will do that asap

tho this requires extensive balancing obviously. :crazyeye:


the whole thing that they didnt make the resource requiring buildings in Civ V "shut down" when out of resources
doesnt make sense to me, it even was in all previous civ's if i recall right.
Afterall many great things didnt make it into civ 5... cottages, corporations, random events... :cry:


hmm i should take a look at the civ 4 electricity system maybe it can hint me to something.
 
you could make electricity a resource required by all industrial and post industrial units (and it makes sense, what works whithout electricty? even the infantry needs it for it's radio and communications). This way if you run in negativ the units will be less efficient. And if electricity is required for all buildings it will have an impact on which buildings can be build. The bad side is that it will not impact production at all :(

I still think this can be done in a more "realistic" fashion than just making it a resource required by your units but that's certainly one way to go. It wouldn't be my preference though since modern mobile units don't run out of electricity, they run out of gas / diesel (or oil which the game kind of simulates with some units already). Now if you were doing some kind of futuristic global warming mod / scenario for the 21st century and beyond you could have them require electricity to simulate electric powered tanks, trucks, etc. You could have a scenario where all of the oil was depleted in a future world. That would seem more "realistic" to me and is actually on the horizon. There are currently some experimental hybrid humvee type vehicles out there to test the military "going green". It is conceivable that you could eventually have a completely electric military vehicle that had to be plugged in and recharged or something, thus requiring electricity for your units. Right now hybrids still need some form of petrol to fuel the engine which generates electricity to run the vehicle.

I've considered going this route with mechanized and air units where a refinery would require oil and produce petrol / gas / diesel (pick your preference) which would be very much like what Hulfgar is talking about for electricity. You could even get really elaborate and have a gas refinery producing gasoline, a diesel refinery producing diesel, and a jet fuel refinery producing jet fuel. Kind of complicated for a mod that focuses on the entire span of history in which the industrial / modern age is only a few turns but for something like I have planned, limited to a shorter span of history, I think it would add to the immersion factor.
 
Hello gents (or ladies?)

I have not read all of your posts in detail, but can tell you that it is quite a difficult undertaking trying to add a second layer of resourcing such as electricity as I have successfully done it for my mod which is under development still.

The biggest problem you will run into is tracking input/output of the resource as well as ensuring it does not foul up the AI. In my case as an example, coal is fed into power plants which output 'power'. This power is used by armament factories to produce various types of weapons which themselves are just another layer of new resourcing. If there is not enough electricity then the output of these weapons drops and so on.

In fact, I have standardized the code so much that it does not matter what you are inputting/outputting as long as it follows some base rules. I have not released it as a separate mod as it is an integral part of the mod I am working on right now and was hoping to include it as a feature of my mod.

Below is a sample of my main code to show how irrespective of the building type or resource, everything is standardized. Please note that I have also created a new special table that stores all the additional supply system info but this can easily be added to the existing Buildings table. Hopefully you might come up with something more generic for any map type or scenario as mine is quite specific to the map and scenario.

Code:
function GetBuildingResourceOutput(playerID, city, buildingType, buildingData, bImpacted)
-- PURPOSE: Get building resource output (steel, aluminium, fuel, power, rail, motor)
-- NOTE: Building output modifiers (i.e. worker quarters, rail yards) are calculated in this code	

	if playerID == nil or buildingType == nil or buildingData == nil or city == nil then
		Dprint("GetBuildingResourceOutput["..GameInfo.Buildings[buildingType].Type.."]: One or more parameters contained a nil value!")
		return
	else
		
		local ceil = math.ceil
		local floor = math.floor
		local random = math.random

		local buildingOutputType = buildingData.ResourceOutputType
		local buildingOutputRate = buildingData.ResourceOutput
		local buildingWorkers = g_PlayerBuildingCounters[playerID][buildingType].TotalWorkers
		local priResource = buildingData.PrimaryResource
		local secResource = buildingData.SecondaryResource 
		local outputModBuilding1 = buildingData.OutputModBuilding1
		local outputModBuilding2 = buildingData.OutputModBuilding2
		local impactedMod = buildingData.OutputImpactedModifier
		local cityID = city:GetID()
		local cityPop = g_CitySupplyData[playerID][cityID].Size
		local cityProd = g_CitySupplyData[playerID][cityID].Production
		local totalOutput = 0
		local prodModifier = 0

		local pResAvailable, pResTotal, pResUsed = 0,0,0
		local sResAvailable, sResTotal, sResUsed = 0,0,0
		local bHasPriResource, bHasSecResource =  false, false
		local seasonalPenalty = 0

		if priResource ~= nil then bHasPriResource = true end;
		if secResource ~= nil then bHasSecResource = true end

		-- Check if building requires primary resource
		if bHasPriResource == true then 
			pResAvailable, pResTotal, pResUsed = GetResourceQuantity(playerID, priResource)
			pResPenalty = CalculatePenalty (playerID, pResUsed, pResTotal)
		end

		-- Check if building requires secondary resource
		if bHasSecResource == true then
			sResAvailable, sResTotal, sResUsed = GetResourceQuantity(playerID, secResource)
			sResPenalty = CalculatePenalty (playerID, sResUsed, sResTotal)
		end

		-- Calculate output
		if buildingOutputType == "Power" then
			-- Power has a flat output rate
			totalOutput = buildingOutputRate
		elseif buildingOutputType == "Rail" or buildingOutputType == "Motor" then
			-- Flat transport points are multipled against city size.
			totalOutput = cityPop * buildingOutputRate
		else
			totalOutput = floor((cityPop ^ buildingOutputRate) * (cityProd/2))
			if bImpacted == true then	-- Building is occupied or isolated (if rail)
				totalOutput = totalOutput - floor((totalOutput * impactedMod) / 100)
			end
		end

		-- Check if city has other production modifier buildings that can boost this buildings output
		if outputModBuilding1 ~= nil then
			if city:IsHasBuilding(GameInfo.Buildings[outputModBuilding1].ID) then
				prodModifier = GetSupplyBuildingValue(outputModBuilding1, "Modifier")
				totalOutput = totalOutput + ceil((totalOutput * prodModifier)/100)
			end
		end
		if outputModBuilding2 ~= nil then
			if city:IsHasBuilding(GameInfo.Buildings[outputModBuilding2].ID) then
				prodModifier = GetSupplyBuildingValue(outputModBuilding2, "Modifier")
				totalOutput = totalOutput + ceil((totalOutput * prodModifier)/100)
			end
		end

		-- Apply primary resource penalty
		if bHasPriResource == true and pResPenalty > 0 then
			totalOutput = totalOutput - floor((totalOutput * pResPenalty) / 100)
		end

		-- Apply secondary resource penalty
		if bHasSecResource == true and sResPenalty > 0 then
			totalOutput = totalOutput - floor((totalOutput * sResPenalty) / 100)
		end

		-- Apply seasonal penalty
		local seasonalPenalty = g_CitySupplyData[playerID][cityID].SeasonalFoodPenalty
		if seasonalPenalty > 0 then
			totalOutput = totalOutput - floor((totalOutput * seasonalPenalty) / 100)
		end

		-- Update Production Resource Counters
		g_CitySupplyData[playerID][cityID][buildingOutputType.."_Output"] = g_CitySupplyData[playerID][cityID][buildingOutputType.."_Output"]	+ totalOutput			
		g_GlobalSupplyCounters[playerID][buildingOutputType].TotalOutput = g_GlobalSupplyCounters[playerID][buildingOutputType].TotalOutput + totalOutput
		
		local current, flux = GetTotalsCounters(playerID, buildingOutputType)
		current = current + totalOutput
		flux = flux + totalOutput
	
		UpdateTotalsCounters(playerID, buildingOutputType, current, flux , 0)

		return totalOutput
	end
end
 
Back
Top Bottom