1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[GS] CO2 Emission Effeciency

Discussion in 'Mod Creation Help' started by Beaust, Mar 4, 2019.

  1. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    Howdy.
    Trying to see if it can be done. My thoughts are to have a Tech or Civic or 2 that decreases CO2 emission from coal and oil.
    So far I have been trying to use the effect of the carbon sequestration project's modifier, but seems maybe that can't be used in a way that is tied to units of resource coal and oil consumed, as "ResourceType" is not recognised as an argument by that particular modifier.
    Or is it possible I'm doing something else wrong, with attaching it to the Civic Conservation or something.

    Code:
    INSERT INTO Modifiers(ModifierId, ModifierType, RunOnce, NewOnly, Permanent, OwnerRequirementSetId, SubjectRequirementSetId, OwnerStackLimit, SubjectStackLimit)
        VALUES
            ('COMBUSTION_EFFICIENCY_COAL', 'MODIFIER_PLAYER_ADD_SEQUESTERED_CARBON', '0', '0', '0', NULL, NULL, NULL, NULL),
            ('COMBUSTION_EFFICIENCY_OIL', 'MODIFIER_PLAYER_ADD_SEQUESTERED_CARBON', '0', '0', '0', NULL, NULL, NULL, NULL);
    INSERT INTO ModifierArguments(ModifierId, Name, Type, Value, Extra, SecondExtra)
        VALUES
            ('COMBUSTION_EFFICIENCY_COAL', 'ResourceType', 'ARGTYPE_IDENTITY', 'RESOURCE_COAL', NULL, NULL),
            ('COMBUSTION_EFFICIENCY_COAL', 'PerXItems', 'ARGTYPE_IDENTITY', '1', NULL, NULL),
            ('COMBUSTION_EFFICIENCY_COAL', 'Amount', 'ARGTYPE_IDENTITY', '410', NULL, NULL),
            ('COMBUSTION_EFFICIENCY_OIL', 'ResourceType', 'ARGTYPE_IDENTITY', 'RESOURCE_OIL', NULL, NULL),
            ('COMBUSTION_EFFICIENCY_OIL', 'PerXItems', 'ARGTYPE_IDENTITY', '1', NULL, NULL),
            ('COMBUSTION_EFFICIENCY_OIL', 'Amount', 'ARGTYPE_IDENTITY', '245', NULL, NULL);
    INSERT INTO CivicModifiers (CivicType, ModifierId)
        VALUES
            ('CIVIC_CONSERVATION' , 'COMBUSTION_EFFICIENCY_COAL'),
            ('CIVIC_CONSERVATION' , 'COMBUSTION_EFFICIENCY_OIL');


    Any ideas?
    Thanks
     
  2. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    Aah! Nevermind. I Realise this can never work now. Maybe perhaps with Lua IDK, a new ResourceSpent or some such argument is needed. Simply having a resource is not the same as using it anyway.
    ….Yikes, I'm sounding like Gandi now :eek:
     
  3. makrisgialos

    makrisgialos GREEK REBEL

    Joined:
    Jan 20, 2007
    Messages:
    256
    Location:
    GREECE
    Hello there,

    i wanted tha same thing. Yet, i believe i have found the way to do it.
    Go to Expansion2 resources.xml and there is a sentence which has this:

    CO2perkWh

    Its the amount of fuel (coal, oil, uranium) burned / Kwh.

    The coal has a high value of course, the Oil less and uranium even less.
    If you reduce these values, it is easily understood that the amount of Co2 released would be much less, therefore the ice melt will be slowed down.
     
  4. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    Hi @makrisgialos,
    Yes, altering the values there will change CO2perKWh throughout the whole game though and for every player.
    What I am trying to do is have the game CO2perKWh be the same as is until the Civic Conservation is researched. Initially to see if I can get it to work like that at all. Later, if I could get it working I could attached to a new Tech or Tech's and or Civic, so the player still has to make an effort to reduce emissions. Initially through just using SQL or xml I was looking to make use of the Carbon Sequestering Project's Modifier Effect to sequester a portion of the CO2 produced by each resource used for power, but that doesn't have the argument type necessary to do it. That particular project seems to just have an arbitrary 50000 assigned to it and has no bearing on the resource's you are consuming and CO2 you are producing at all.

    I have been looking at Lua now to solve this ...Maybe! I have never used Lua before so... Any code guru's Feel free to laugh at this and please do point out where I done it wrong:-
    I have found in the Script for the new Expansion, which only deals with world congress events a function that deals with power resource ban which may have some useful things in it.
    Here is where I'm at so far with it:-
    Code:
    GameEvents."CIVIC_CONSERVATION".Add(function(CIvicType, playerId)
     
      for row in GameInfo.Resource_Consumption() do
       local resourceCO2 = GameInfo.Resource_Consumption[row.CO2perkWh]:
       local resource = GameInfo.Resource_Consumption[row.ReasourceType]:
       if(resource and resource.ResourceType == "RESOURCE_COAL") then
        table.insert(resourceCO2,410):
        else if(resource and resource.ReasourceType == "RESOURCE_OIL") then
         table.insert(resourceCO2,245):
        end
       end
      end
    end);
    
    The other thing which is going to take a bit of time getting my head around is how to test it properly with the SDK and Fire Tuner which I have only just started using.
     
  5. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,756
    Location:
    Illinois, USA
    1. There's no such thing as GameEvents."CIVIC_CONSERVATION" so you cannot attach a listener function to it.
    2. Looks like you have too many "end" commands in the code you've written so far.
      • Every "function", "for", and "if" command requires a matching "end" command
      • You have three commands requiring an "end" so far as I can see but you have four "end" commnads
    3. You have dangling and "illegal" colon ( : ) characters laced within your code
    4. This does not create a valid lua table
      Code:
      local resourceCO2 = GameInfo.Resource_Consumption[row.CO2perkWh]
      So you cannot insert anything into it as you arfe doing here
      Code:
      table.insert(resourceCO2,410)
    5. Executing a
      Code:
      table.insert(TableName, Value)
      command within lua has no effect whatever on the game's SQL / XML database, if that was what you were attempting to do
    6. As a general reference this is proper syntax for executing-through the contents of an SQL / XML database game-table within an lua script:
      Code:
      local LuaTableOfData = {}
      for row in GameInfo.Resource_Consumption() do
      	if(row.ReasourceType == "RESOURCE_COAL") then
      		LuaTableOfData["RESOURCE_COAL"] = row.CO2perkWh
      	elseif (row.ReasourceType == "RESOURCE_OIL") then
      		LuaTableOfData["RESOURCE_OIL"] = row.CO2perkWh
      	end
      end
      This code would look through the XML table and record into the lua table called LuaTableOfData the "CO2perkWh" setting within the database table for each of these two resources listed in table <Resource_Consumption>.

      Lua does not and cannot however change the two values within the Database XML table
     
  6. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    Thank you very much @LeeS for all the pointers. No secret this lua stuff is for the most part over my head still. So basically its a static beast we're dealing with after game loading and what I'm trying to do, it can't be done. Oh well nothing ventured nothing gained so they say. 0>
     
  7. makrisgialos

    makrisgialos GREEK REBEL

    Joined:
    Jan 20, 2007
    Messages:
    256
    Location:
    GREECE
    Well i have found that the emissions of CO2 are having great effect in early stages of the game and it was really annoying for me.
    Your idea about the conservation civic is indeed good yet i m afraid this requires many changes and a lot of work. It also requires deep programming knowledge and i know only to edit xml.
    What i did was to search all xml files one by one to find the emissions of CO2.

    I want to ask you though you know where shall i look in order to increase the appearance frequency for strategic resources?
    Cause a bigger problem for me is the absence of coal or oil...

    Thx.!
     
  8. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,756
    Location:
    Illinois, USA
    We can however directly attach Modifiers to players and individual cities from lua. We cannot however remove them once attached. And we cannot attach modifiers to units.
    If you can create a modifier via the Modifiers, ModifierArguments, RequirementsSets, Requirements, etc., tables that will successfully reduce carbon emmisions when added to a player, this modifier can be attached to any player via lua at any point within the progress of the game that seems reasonable. In this case you would not be attempting to alter the contents of the database, you would be using lua to implement something already defined within the database and ready to be used.
     
  9. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,756
    Location:
    Illinois, USA
    I see you had another thread on this resource-placment issue. First you need to follow-through and check database.log etc as advised to be sure your code is actually being executed.

    Actual placement of resources when a game is created is done by the map generation lua-scripts. I am not sure whether any of those tend to override any of the general settings within the XML tables.
     
  10. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    Yeah, I could use the Modifier from the Carbon capture project, but that would be an arbitrary flat rate, same as the project itself.
    A new approach I'm thinking of now may be to create another resource altogether, say RESOURCE_BIOFUEL with a CO2perkWh of 200 or something unlock at Conservation.
    For Units, the only way is to have 5 new units that the top tier oil using units can upgrade to, essentially carbon copies but with Biofuel maintenance instead of oil. Would be good to have it produced by a tile improvement or city perhaps and option for power plants to convert, but I can find no way of making a new resource like that. Only on Map generation and a plot for it which would be silly.​
    Might be possible to make a Biofuel Plant Improvement though that provides free power unlock at conservation....would be something along the lines.
     
    Last edited: Mar 8, 2019
  11. makrisgialos

    makrisgialos GREEK REBEL

    Joined:
    Jan 20, 2007
    Messages:
    256
    Location:
    GREECE
    Lee s thx for your reply.

    I dont know how to edit lua files.

    Yet i have found this:
    <Resources>
    <Update>
    <Where ResourceType="RESOURCE_ALUMINUM"/>
    <Set>
    <Frequency>31</Frequency>
    </Set>
    </Update>
    <Update>
    <Where ResourceType="RESOURCE_HORSES"/>
    <Set>
    <PrereqTech>TECH_ANIMAL_HUSBANDRY</PrereqTech>
    <Frequency>11</Frequency>
    </Set>
    </Update>
    <Update>
    <Where ResourceType="RESOURCE_IRON"/>
    <Set>
    <Frequency>5</Frequency>
    </Set>
    </Update>
    <Update>
    <Where ResourceType="RESOURCE_OIL"/>
    <Set>
    <Frequency>44</Frequency>
    <PrereqTech>TECH_REFINING</PrereqTech>
    </Set>
    </Update>
    <Update>
    <Where ResourceType="RESOURCE_URANIUM"/>
    <Set>
    <Frequency>19</Frequency>



    There has to be a connection and a way to edit this.
     
  12. Seven05

    Seven05 Warmonger

    Joined:
    Dec 5, 2005
    Messages:
    2,056
    Gender:
    Male
    Location:
    USA
    The biggest problem this will lead you into is that it isn't the power plants creating most of the CO2 in the game, it's the units.

    An alternative way to look at this may be to greatly reduce the base CO2 per kwh for oil and coal and increase the maintenance cost for units and the power used by buildings. You should then be able to use civic cards to reduce the resource maintenance on units and add free power to the power plants. I think I saw both in there, don't quote me on that though. I'm working on something similar myself but not exactly what you're trying to do.

    Frequency is essentially what you're looking for to simply get more of that resource. When the resources are placed that will be used to figure out the ideal number of tiles to use. However, if you crank everything up it's possible to have resources on so many tiles that it blocks others from appearing since they enforce "buffer" ranges. It may be easier and more reliable to simply increase the number of resources gained from each coal mine or oil well. :)
     
  13. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    Hi @Seven05, I hadn't thought of that, that's a great idea. Likely would have to also bump up the amount of resources produced by the mines too.
    I think I may have worked out a way to do it with a new resource now since also. Similar to the way JNR's mod "Renewable Energies Complexity" has done it, basically making a coal mine produce a "Refined Coal" resource as well as the normal coal. The Refined version to be consumed in a new PP and new upgrade to Iron Clad and Battleship producing less CO2perkWh. Will do the same with oil if I can make it work. Slowly making progress I believe, trying to work out how Icons are hooked up.
     
  14. Seven05

    Seven05 Warmonger

    Joined:
    Dec 5, 2005
    Messages:
    2,056
    Gender:
    Male
    Location:
    USA
    The AI may struggle with that, and you may run into issues with the upgrade cost not being worth it for that small of a change. Now a nuclear version of the battleship could be worthwhile but for the ironclad or another coal based battleship... you may want to save yourself some headache and try it just on the power plants first since that should be an easy test and that may make enough difference in the global warming to satisfy you. I had played around with a similar upgrade chain for land units basically covering the bronze->iron ages and it worked there because I was also slowing down era progress substantially.
     
  15. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    Ok I think I have the framework there, possibly some more tweaking needed - Mod zip attached if anyone is interested. Still not sure how to update text for the power plants so they still show the original info not the new.
    Changes;

    Resource_Consumption Changes
    :- Power provided is 25% of what it was and now 1 to 1 ratio to resources coal and oil.
    :- CO2perkWh for coal & oil is 40% instead of 25% to allow for previous wastage. And to
    balance the fact units now produce much less CO2. May still need tweaking!
    :- CO2perkWh for Urainium divided by 4. Still some wastage possible!

    Building_XP2 Changes
    :- Factories use 3 times power what they used, but CO2 produced not necessarily 3 times as much.
    Example, bog standard, if city has a factory and no other power using buildings, it will be 1.5 times.
    Since using 1 resource supplies 4 power, factory only needs 2 but still 1 resource is consumed.
    Resource modified to 1 to 1 power - Power plants only use amount of resources needed for amount of
    power needed. Factories historically should be more power/resource hungry than other buildings.
    :- Added Power Efficiency to Buildings = 33% reduction to all power using buildings once Conservation is researched.

    Unit_XP2 Changes
    :- Smaller Units produce 1/4 CO2 of what they used to.
    :- Medium Units produce 1/2 CO2 of what they used to.
    :- Large Units produce 3/4 CO2 of what they used to.
    :- Largest(Battleships) produce = CO2 of what they used to.
     

    Attached Files:

  16. Seven05

    Seven05 Warmonger

    Joined:
    Dec 5, 2005
    Messages:
    2,056
    Gender:
    Male
    Location:
    USA
    Interesting approach, did you also increase the number of resources extracted since you'll be consuming as much as 4x the old value?
     
  17. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    @Seven05 Oh yes!, Forgot to mention.
    Extraction rate for Coal & Oil is now 7 up from 3, Uranium to 9. Stockpile cap up to 60 from 50.
    I had tried multiplying them by 4, but after testing I don't think it needs adjusting that much and may even bring them down further. Once you have conservation, depending on how many units and what type they are , a lot less resources are used too.
     
  18. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,756
    Location:
    Illinois, USA
    1. Since you are using <Components> here instead of <InGameActions> you need the <Items> in the UpdateText action:
      Code:
      	<Components>
      		<UpdateDatabase id="PE">
      			<Items>
       				<File>PE_Code.sql</File>
      			</Items>
      		</UpdateDatabase>
      		<UpdateText id="PE_Text">
      				<File>PE_Text.xml</File>
      		</UpdateText>
      	</Components>
    2. There's no table called <EnglishText>. You have to use <LocalizedText> with
      Code:
      Language="en_US"
      specified in your <Update> "Where" clauses.
    3. <EnglishText> is a "view" rather than a "real" table. From the relevant Firaxis-created SQL "schema" file for the language localizations:
      Code:
      CREATE VIEW EnglishText AS
      	SELECT Tag, Text, Gender, Plurality FROM LocalizedText WHERE Language = 'en_US';
      	
      CREATE TRIGGER AddEnglishText INSTEAD OF INSERT ON EnglishText
      BEGIN
      	INSERT INTO LocalizedText ('Language', 'Tag', 'Text', 'Gender', 'Plurality') VALUES('en_US', NEW.Tag, NEW.Text, NEW.Gender, NEW.Plurality);
      END;
      
      CREATE VIEW BaseGameText AS 
      	SELECT Tag, Text, Gender, Plurality FROM LocalizedText WHERE Language = 'en_US';
      	
      CREATE TRIGGER AddBaseGameText INSTEAD OF INSERT ON BaseGameText
      BEGIN
      	INSERT INTO LocalizedText ('Language', 'Tag', 'Text', 'Gender', 'Plurality') VALUES('en_US', NEW.Tag, NEW.Text, NEW.Gender, NEW.Plurality);
      END;
      These bits of SQL code are all used in essentially "end-processing" after everything has been loaded to make sure that all tags and texts go into the proper localization for the language the human is running under.
     
    Last edited: Mar 18, 2019
  19. Beaust

    Beaust Chieftain

    Joined:
    Nov 14, 2010
    Messages:
    15
    @LeeS Thank you very much again kind sir. All working now and file above updated.
     

Share This Page