Home Showcase
Welcome to the new Diaspora forums, please let us know if you see anything broken! Notice: Some users may need to reupload their avatars due to an issue during forum setup!

[Support Ended]Automatic Storage Adjusting Lifesupport

Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
edited May 2012 in Showcase #1
Attention: Official support for this E2 has ended. I have left the code here for those who wish to learn from it. Thank you all for making this E2 as successful as it has been!
My new lifesupport manager can be found here!

Enhanced Lifesupport Management by Mouldy_Taco

Features of the E2:
  • Auto version checker to make sure you have the latest version of code!
  • Automatic Linking of all required lifesupport entities based on a search through constraints and entities linked to the network!
  • Option for automatic Water Pump linking (for pumps not attached to your ship!)
  • Automatic Resource Sharing option using Resource Pumps!
  • Unlinks resource hogging weapons during initial production!
  • Visual and Audio notifications to let you know what you need to connect and when you have completed all connections!
  • Automatically adjusts maximum multipliers depending on the storage available (Ensures minimal waste while fuelling)
  • Automatically manages energy production when it does not have access to water (This should have ALMOST ZERO waste once it reaches equilibrium)

Current version: 1.17 (hash: 3263380261)

Updates in 1.17
  • Production will no longer choke when dealing with storages in excess of 500 million capacity
  • Pump feature will automatically disconnect if the two pumps are no longer in pumping range
  • Added a hash checking feature that will make sure the version of the E2 that you have is the same as the one on this page
  • Changed the model to a non-Tiberium Model
  • Oh and also, the e2 doesn't lag at all anymore.

Updates in 1.15
  • Fixed bug where having too much water and not enough energy choked initial startup
  • Added in functionality to allow linking of components accross linked networks(Previously everything had to be linked to the same node, now as long as the nodes are linked, components can be linked to any of the connected nodes)
  • Having an outdated version no longer prevents your e2 from halting production, it will continue to run the outdated code, but will remind you when you place it that updating is recommended.

Updates in 1.14
  • Many small updates that, unfortunately, I don't remember many of. All I know is it's better now!

Updates in 1.13
  • Optimised fuelling further(Mostly for oxygen/hydrogen production)
  • Support for LS cores has been added(Not sure if it was this version or last version, but whatever!)
  • Storage constants now automatically update when a storage change is detected!
  • Sped up the autolinking procedure for required stuff, it was taking upwards of half a minute before, now it should take only a few seconds!

Updates in 1.12
  • Connecting generators and other ls entities is now automatic based on what is constrained or linked to the resource node!
  • All the dull prints have been given new life with printColor! Also added a few more prints as well.

Updates in 1.11
  • Fuelling is much faster now

Updates in 1.1
  • Added Resource Sharing mode, which takes advantage of Feha's pump function to automatically pump resources to pumps that the owner has prop protection of(It's the way the function is coded, not the way I coded the e2)
  • Added Weapon Unlink part to prevent resource hogging weapons like Mjolnirs and Anti-Matter blasters from choking the initial resource production
  • Relevant data is now shown as the actual name of the E2(Pump Active/inactive,% full on resources, Energy production capacity)
  • Many more hints and comments to coincide with the new features
  • Optimised final productions of resources such that much less waste is produced than before, also allowing for fuller caches!
  • Changed model of E2 from default chip to a cute little glowy thing =3
  • Changed warning sound for missing connections from hl1 to something more accessible to everyone.
  • Steam Production in-flight wasn't operating correctly, it has been rectified by adding a few parenthesis

Updates in 1.05
  • Added in a version checker which requests http data from this topic to see if the version here matches the version in your code
  • Added more comments in the first 60 lines for greater clarification

Updates in 1.04
  • Removed some leftover debugging prints that got included in last patch
  • AutoPumpLink inrange calculations are done from the Resource node now instead of the E2
  • Optimised energy generation during flight, almost exactly 200k energy per large resource cache per second!

Updates in 1.03
  • Fixed issue with waterpumps not autolinking AT ALL. Gave the timers a good slap.
  • Optimised lifesupport constants, initial resource gains should come much faster now.

Updates in 1.02:
  • Fixed issue with waterpumps not autolinking after removing one or more generators
  • Notifications are now permanently on, due to the need for them in several sections of code(IF you wish to disable the actual notifications, just comment out the prints and soundplays(Although the sounds are pretty cool =3))
[/list]


Still requires some more testing. If anyone finds any problems, please let me know.

Also, Please let me know what you think of the code!
@name SBEnhancedLifeSupportManagement
@model models/props_lab/reciever01a.mdl
@inputs [ResourceNode ResourcePump]:wirelink
@persist Activate AutoPumpLink
@persist MaxWater MaxEnergy MaxSteam MaxOxygen MaxHydrogen
@persist WaterProduction HWEWaterUsage WAEWaterUsage SteamUsage SteamProduction
@persist OxygenProduction HydrogenProduction EnergyProduction
@persist Energy Water
@persist WaterPump:wirelink
@persist [ResourceNode ResourcePump ResourceCache]:wirelink
@persist [OnBoardWaterPump WaterAirExtractor HeavyWaterElectrolyzer SteamTurbine]:wirelink
@persist [LifeSupportCore]:wirelink GeneratorClasses:string
@persist [NetworkEntities ConstrainedEntities AllEntities OtherNodes]:array EntityCt EntityCtChanged Increment HackyTimer
@persist ShowNotifications ConnectionWarning ConnectionsComplete WaterPumpNode:entity
@persist Version VerifiedUpdated NodeRadius
@persist AutoShareResources PumpingResources LinkedPump:entity ExtendedNetworks:array
@persist [E2Name PumpDisplay PercentDisplay]:string
@persist WeaponsUnlinked WeaponsToLink:array
@persist Interval 
@trigger none
#Author: Mouldy_Taco

#THIS CHIP REQUIRES AT LEAST ONE LARGE RESOURCE CACHE TO OPERATE PROPERLY
#THIS CHIP REQUIRES AT LEAST 1.500.000 ENERGY CAPACITY TO OPERATE PROPERLY
#It is *RECOMMENDED* that you use at least 2 large resource caches and 2 giant batteries for optimal production
#both while fuelling and in-flight

#DO NOT BE SURPRISED IF YOU SEE ADVERSE EFFECTS/SLOW PRODUCTION/AIDS
#WHEN TRYING TO USE LESS THAN THE RECOMMENDED STORAGE

#Remember, the less storage you have, the slower this chip can fill it.
#Counterintuitive, but there's less available resources to consume per interval. get it?

#This needs a small amount of startup energy, any size solar panel will start the process

#@@@@@@@@@@@@@@@@@@@@@@@@
#THIS E2 HAS AN AUTO PUMP LINK MODE, ACTIVATE IT BY SETTING THE VARIBLE AutoPumpLink in the if(first()) to 1!
#IF AutoPumpLink IS 0, YOU NEED TO LINK YOUR WATER PUMP TO THE RESOURCE NODE!
#@@@@@@@@@@@@@@@@@@@@@@@@
#THIS E2 HAS AN AUTO RESOURCE SHARE OPTION, ACTIVATE IT BY SETTING THE VARIABLE AutoShareResources in the if(first()) to 1!
#IT WILL AUTO FILL THE  RESOURCE PUMP IT FINDS TO MAX RESOURCES IN 10 SECONDS, UNLESS THE ENERGY AMOUNT NEEDED EXCEEDS THE 
#OUTPUT CAPACITY OF THE E2 BY 10, IN WHICH CASE THE TIME WILL BE EXTENDED.
#IF AutoShareResources IS 0, YOU DON'T NEED TO WIRE UP RESOURCE PUMP INPUT!
#NOTE: PROP PROTECTION OF OTHERS IS REQUIRED FOR THESE FUNCTIONS TO WORK ON THEIR PUMPS
#@@@@@@@@@@@@@@@@@@@@@@@@
#THIS E2 AUTOMATICALLY UNLINKS RESOURCE HOGGING WEAPONS LIKE MJOLNIRS AND ANTI-MATTER BLASTERS
#IT WILL AUTOMATICALLY RE-LINK THEM WHEN IT REACHES 75% ENERGY CAPACITY
#@@@@@@@@@@@@@@@@@@@@@@@@
#IF ALL ELSE FAILS TRY RESETTING THE E2 BY PRESSING 'E' ON IT!!!!
#@@@@@@@@@@@@@@@@@@@@@@@@

#***************************#
#REMEMBER IT'S WIRE ADVANCED, NOT NORMAL WIRE TOOL
#***************************#
#STEPS TO FOLLOW:
#1. Spawn the E2
#2. Check console to see what generators and such you have to spawn and wire the e2 up to.
#3. Wire all the required inputs using Wire Advanced tool (Ignore OnBoardWaterPump if you have AutoPumpLink set to 1)
#4. Wire up your startup power source (ex. any solar panel)
#5. ?????
#6. Profit!
#***************************#
#***************************#
if(dupefinished())
{
    reset()
}
if(first())
{
    
    entity():setColor(vec(0,255,255))
    #These variables ensure your code is up to date.
    #@@@@@DON'T TOUCH THIS STUFF@@@@@
    Version=1.17
    VerifiedUpdated=0
    httpRequest("http://diaspora.100paperclips.com/viewtopic.php?f=18&t=145")
    timer("httptimeout",10000)
    E2Name="Enhanced Life Support Management v"+toString(Version)
    #@@@@@ABOVE STUFF YOU DON'T TOUCH@@@@@
    
    ##Predefined Variables##
    Activate=1 #Set to 0 to prevent any LS being run by the e2
    AutoPumpLink=1 #Set to 1 to enable automatic water pump linking on the fly (Not needed if the pump is onboard)
        #Note: Do not wire OnBoardWaterPump wirelink to the water pump if it is stationary 
        #and AutoPumpLink is set to 1 (i.e. not connected to your ship)
    AutoShareResources=1
    #This enables automatic resource sharing to in-range pumps
    #when you connect a pump of your own to your network and wire it up to the ResourcePump input
    
    #Optional input for climate regulator radius
    ClimateRegulatorRadius=1650
    
    ConnectionWarning=1
    ConnectionsComplete=0
    Increment=1
    
    #Starting the pump find timer, it only checks for a waterpump every 5 seconds to save ops.
    if(AutoPumpLink)
    {
        WaterPump=noentity():getWirelink()
        timer("waterpumpcheck",1333)
    }
    #If not autolinking remote water pump, assign waterpump to the input.
    else
    {
        WaterPump=OnBoardWaterPump
    }
    
    if(AutoShareResources)
    {
        timer("resourcepumpfindupdate",1666)
    }
    
    #Definition of persistent Cache values
    MaxWater=ResourceCache["Max Water",number]
    MaxEnergy=ResourceCache["Max Energy",number]
    MaxSteam=ResourceCache["Max Steam",number]
    MaxOxygen=ResourceCache["Max Oxygen",number]
    MaxHydrogen=ResourceCache["Max Hydrogen",number]
    
    #Definition of resource usage and production for key resources
    WaterProduction=464
    HWEWaterUsage=81
    WAEWaterUsage=578
    SteamUsage=31
    SteamProduction=80
    OxygenProduction=289
    HydrogenProduction=577
    EnergyProduction=278
    #Note, these values are for the CE Model of each of these types of generators, please also use the
    #CE Models so that your lifesupport doesn't FAIL!
    #Extra note: Water Air Extractor, Heavy Water Electrolyzer, and Steam Turbine should have the same model!
    #CE Large Water Splitter
    #CE Electrolyzer
    #CE Small Steam Turbine
    #CE Large Water Pump
    
    GeneratorClasses="generator_liquid_hvywater generator_gas_o2h_water"
                    +" generator_energy_steam_turbine generator_liquid_water storage_cache"
    
    ResourceNode=noentity():getWirelink()
    #Muting all the generators, reducing sound pollution :)
    WaterPump["Mute",number]=1
    WaterAirExtractor["Mute",number]=1
    HeavyWaterElectrolyzer["Mute",number]=1
    SteamTurbine["Mute",number]=1
    
    timer("entityrefresh",5000)
    Interval=2050
    runOnHTTP(1)
    runOnLast(1)
    runOnUse(1)
    
}
interval(Interval)
if(useClk(owner()))
{
    printColor(vec(255,255,255),"Resetting chip!")
    reset()
}
#Verification process of current E2 version.
if(httpClk()&!VerifiedUpdated)
{
    Data=httpData()
    Location=Data:find("Current version: ")+17
    WebVers=Data:sub(Location,Location+3)
    Hash=Data:sub(Location+12,Data:find(toChar(41),Location+12)-1)
    print(2,toString(hashNoComments()))
    print(2,Hash)
    if(WebVers:toNumber()<=Version)
    {
        VerifiedUpdated=1
        printColor(vec(100,255,100),"Version ",vec(255,255,255),toString(Version),vec(100,255,100)," verified, continuing execution of E2!")
    }
    else
    {
        printColor(vec(255,100,100),"Current Lifesupport E2 Version Outdated!\nCurrent Version: "
                        ,vec(255,50,0),toString(Version),vec(255,100,100),"| New Version: "
                        ,vec(100,255,100),WebVers
                        ,vec(55,255,255),"\nPlease update by visiting:\nhttp://diaspora.100paperclips.com/viewtopic.php?f=18&t=145"
                        +"\n*It is recommended that you update so you recieve new features and bugfixes, as well as efficiency updates!*")
        VerifiedUpdated=1
    }
    if(Hash:toNumber()!=hash())
    {
        printColor(vec(255,100,100),"Hashtag mismatch! Incomplete/Modified E2! Code may be unstable!")
    }
    
}
elseif(clk("httptimeout")&!VerifiedUpdated)
{
    printColor(vec(200,100,100),"Unable to verify updated version! Continuing execution as normal!")
    VerifiedUpdated=1
}
#If the E2 matched or exceeded the version on the website, continue with regular execution
if(VerifiedUpdated&Activate)
{
    
    if(!ConnectionsComplete&ResourceNode:entity()&
                (WaterAirExtractor:entity()
                &HeavyWaterElectrolyzer:entity()
                &SteamTurbine:entity()
                &ResourceCache:entity()
                &((OnBoardWaterPump:entity()&!AutoPumpLink)|AutoPumpLink)
                ))
    {
        Vol=ResourceNode:entity():volume()
        NodeRadius=Vol/12/(1+1.35*(Vol>3000))+550*(Vol>40000)
        #toString(V/12/(1+1.35*(V>3000))+550*(V>40000))
        ConnectionsComplete=1
        Interval=1050
        owner():soundPlay(1,0,"buttons/bell1.wav")
        printColor(vec(0,255,0),"All connections complete! Beginning LS management.")
        timer("resourcepumpfindupdate",3500)
        timer("waterpumpcheck",1000)
        timer("backuprelink",20000)
        exit()
    }
    elseif(ConnectionsComplete&
                (!ResourceNode:entity()
                |!WaterAirExtractor:entity()
                |!HeavyWaterElectrolyzer:entity()
                |!SteamTurbine:entity()
                |!ResourceCache:entity()
                |((!OnBoardWaterPump:entity()&!AutoPumpLink))
                ) )
    {
        
        ConnectionsComplete=0
        timer("entityrefresh",5000)
        HackyTimer=0
        if(ResourceNode:entity())
        {
            Interval=100
        }
    }
    
    if(!ConnectionsComplete)
    {
        if(ConnectionWarning&!last())
        {
            HackyTimer=curtime()
            owner():soundPlay(1,0,"misc/hud_warning.wav")
            if(!ResourceNode:entity()) 
            {
                printColor(vec(255,80,20),"Please use <Wire Advanced Tool> to wire up ResourceNode input to your Resource Node to continue the linking proccess!")
                ConnectionWarning=0
                exit()
            }
            
            WarningArray=array(vec(255,25,25),"Currently missing the following: ")
            WarningString=""
            if(!ResourceCache:entity()) 
            {
                WarningString=WarningString+"Resource Cache || "
            }
            if(!OnBoardWaterPump:entity()&!AutoPumpLink) 
            {
                WarningString=WarningString+"Water Pump || "
            }
            if(!WaterAirExtractor:entity()) 
            {
                WarningString=WarningString+"Water Air Extractor || "
            }
            if(!HeavyWaterElectrolyzer:entity()) 
            {
                WarningString=WarningString+"Heavy Water Electrolyzer || "
            }
            if(!SteamTurbine:entity()) 
            {
                WarningString=WarningString+"Steam Turbine || "
            }
            WarningArray:pushString(WarningString:left(WarningString:length()-4))
            printColor(WarningArray)
            ConnectionWarning=0
            if(!ResourceNode:entity())
            {
                Interval=100
                exit()
            }
        }
        
        if(clk("entityrefresh"))
        {
            timer("entityrefresh",2000)
            if(!ResourceNode:entity())
            {
                exit()
            }
            NetworkEntities=ResourceNode:entity():rdNetEntities()
            ConstrainedEntities=ResourceNode:entity():getConstraints()
            AllEntities=ConstrainedEntities:clone()
            MaxConstrainedEntities=ConstrainedEntities:count()
            for(I=1,NetworkEntities:count())
            {
                AllEntities[I+MaxConstrainedEntities,entity]=NetworkEntities[I,entity]
            }
            
            if(OtherNodes:count()!=ResourceNode:entity():rdLinkedNets():count())
            {
                OtherNodes=ResourceNode:entity():rdLinkedNets()
                for(I=2,OtherNodes:count())
                {
                    TempNodeEntities=OtherNodes[I,entity]:rdNetEntities()
                    
                    for(J=1,TempNodeEntities:count())
                    {
                        AllEntities:pushEntity(TempNodeEntities[J,entity])
                    }
                }
                OtherNodes[1,entity]=ResourceNode:entity()
            }
            if(ResourceNode:entity():rdLinkedNets():count()==0)
            {
                OtherNodes[1,entity]=ResourceNode:entity()
            }
            EntityCtChanged=changed(AllEntities:count())
            if(EntityCtChanged)
            {
                EntityCt=AllEntities:count()
                Interval=100
            }
            else
            {
                Interval=1000
            }
        }
        
        #AllEntities=NetworkEntities:merge(ConstrainedEntities)
        if(Increment<=AllEntities:count()&EntityCt>3)
        {
            SelectedEnt=AllEntities[Increment,entity]
            EntType=SelectedEnt:type()
            if(GeneratorClasses:find(EntType)==0)
            {
                Increment++
                exit()
            }
            
            HWEEnt=HeavyWaterElectrolyzer:entity()
            WAEEnt=WaterAirExtractor:entity()
            STEnt=SteamTurbine:entity()
            WPEnt=WaterPump:entity()
            RCEnt=ResourceCache:entity()
            
            if(!HWEEnt&EntType=="generator_liquid_hvywater")
            {
                SelectedEnt:makeWirelink()
                HeavyWaterElectrolyzer=SelectedEnt:getWirelink()
                HeavyWaterElectrolyzer["Mute",number]=1
                HeavyWaterElectrolyzer:entity():link(ResourceNode:entity())
                printColor(vec(255,50,255),"Heavy Water Electrolyzer Linked!!")
                Increment++
                exit()
            }
            
            elseif(!WAEEnt&EntType=="generator_gas_o2h_water")
            {
                SelectedEnt:makeWirelink()
                WaterAirExtractor=SelectedEnt:getWirelink()
                WaterAirExtractor["Mute",number]=1
                WaterAirExtractor:entity():link(ResourceNode:entity())
                printColor(vec(255,50,255),"Water Air Extractor Linked!!")
                Increment++
                exit()
            }
            
            elseif(!STEnt&EntType=="generator_energy_steam_turbine")
            {
                SelectedEnt:makeWirelink()
                SteamTurbine=SelectedEnt:getWirelink()
                SteamTurbine["Mute",number]=1
                SteamTurbine:entity():link(ResourceNode:entity())
                printColor(vec(255,50,255),"Steam Turbine Linked!!")
                Increment++
                exit()
            }
            
            elseif(!AutoPumpLink&!WPEnt&EntType=="generator_liquid_water")
            {
                SelectedEnt:makeWirelink()
                WaterPump=SelectedEnt:getWirelink()
                WaterPump["Mute",number]=1
                WaterPump:entity():link(ResourceNode:entity())
                OnBoardWaterPump=WaterPump
                printColor(vec(255,50,255),"Water Pump Linked!")
                Increment++
                exit()
            }
            
            elseif(!RCEnt&EntType=="storage_cache")
            {
                SelectedEnt:makeWirelink()
                ResourceCache=SelectedEnt:getWirelink()
                ResourceCache:entity():link(ResourceNode:entity())
                printColor(vec(255,50,255),"Resource Cache Linked!!")
                
                MaxWater=ResourceCache["Max Water",number]
                MaxEnergy=ResourceCache["Max Energy",number]
                MaxSteam=ResourceCache["Max Steam",number]
                MaxOxygen=ResourceCache["Max Oxygen",number]
                MaxHydrogen=ResourceCache["Max Hydrogen",number]
                
                Increment++
                exit()
            }
            Increment++
            exit()
        }
        elseif(Increment>AllEntities:count())
        {
            if(HackyTimer+30<curtime())
            {
                ConnectionWarning=1
            }
            
            if(EntityCtChanged&EntityCt>3)
            {
                Increment=1
            }
            
            exit()
        }
        else
        {
            Increment++
            exit()
        }
    }
    
    if(ConnectionsComplete)
    {
        if(clk("backuprelink"))
        {
            HeavyWaterElectrolyzer:entity():link(ResourceNode:entity())
            WaterAirExtractor:entity():link(ResourceNode:entity())
            SteamTurbine:entity():link(ResourceNode:entity())
            ResourceCache:entity():link(ResourceNode:entity())
            timer("backuprelink",20000)
        }
        
        if(MaxWater!=ResourceCache["Max Water",number]
                    |MaxEnergy!=ResourceCache["Max Energy",number]
                    |MaxSteam!=ResourceCache["Max Steam",number]
                    |MaxOxygen!=ResourceCache["Max Oxygen",number]
                    |MaxHydrogen!=ResourceCache["Max Hydrogen",number])
        {
            printColor(vec(130,130,255),"Updated Storage Amount!")
            MaxWater=ResourceCache["Max Water",number]
            MaxEnergy=ResourceCache["Max Energy",number]
            MaxSteam=ResourceCache["Max Steam",number]
            MaxOxygen=ResourceCache["Max Oxygen",number]
            MaxHydrogen=ResourceCache["Max Hydrogen",number]
        }
        
        #Auto Resource Pump Management code starts here
        #First it checks if the mode is enabled and if the timer has ticked,
        #it also checks if it's already pumping resources and if the energy is above 50% before trying to
        if(AutoShareResources&clk("resourcepumpfindupdate")&!PumpingResources&Energy>MaxEnergy*0.5)
        {
            timer("resourcepumpfindupdate",5000)
            findExcludeEntities(OtherNodes)
            findExcludeEntity(ResourcePump:entity())
            findIncludeClass("rd_pump")
            findIncludeClass("resource_node")
            findInSphere(ResourcePump:entity():pos(),2500)
            findSortByDistance(ResourcePump:entity():pos())
            FindArray=findToArray()
            findClearWhiteList()
            findClearBlackList()
            FoundPumps=FoundNodes=array()
            LinkedNode=LinkedPump=noentity()
            #Trying to sort through the finds to get a pump and node with the same owner
            for(I=1,FindArray:count())
            {
                if(FindArray[I,entity]:type()=="rd_pump")
                {
                    FoundPumps:pushEntity(FindArray[I,entity])
                    continue
                }
                if(FindArray[I,entity]:type()=="resource_node")
                {
                    FoundNodes:pushEntity(FindArray[I,entity])
                    continue
                }
            }
            for(I=1,FoundNodes:count())
            {
                for(J=1,FoundPumps:count())
                {
                    if(FoundNodes[I,entity]:owner()==FoundPumps[J,entity]:owner()&FoundNodes[I,entity]:pos():distance(FoundPumps[J,entity]:pos())<NodeRadius*0.95
                        &FoundPumps[J,entity]:pos():distance(ResourcePump:entity():pos())<=500)
                    {
                        LinkedNode=FoundNodes[I,entity]
                        LinkedPump=FoundPumps[J,entity]
                        break
                    }
                }
            }
            #print(LinkedNode,"\n",LinkedPump)
            #makes double-sure that the owner is the same, also radius checks the pump
            if(LinkedNode:owner()==LinkedPump:owner()&LinkedPump:pos():distance(ResourcePump:entity():pos())<=500)
            {
                #gets all nodes linked to the node found, and subsequently adds together the total resources
                ExtendedNetworks=LinkedNode:rdLinkedNets()
                ExtendedNetworks[1,entity]=LinkedNode
                NetEnergy=NetOxygen=NetHydrogen=NetWater=NetHeavyWater=0
                for(I=1,ExtendedNetworks:count())
                {
                    TempNode=ExtendedNetworks[I,entity]
                    
                    NetEnergy+=TempNode:rdNetCapacity("energy")-TempNode:rdAmount("energy")
                    NetOxygen+=TempNode:rdNetCapacity("oxygen")-TempNode:rdAmount("oxygen")
                    NetHydrogen+=TempNode:rdNetCapacity("hydrogen")-TempNode:rdAmount("hydrogen")
                    NetWater+=TempNode:rdNetCapacity("water")-TempNode:rdAmount("water")
                    NetHeavyWater+=TempNode:rdNetCapacity("heavy water")-TempNode:rdAmount("heavy water")
                }
                #if the resource difference between current amount and capacity for ALL resources is greater than 5000, then start pumping
                if(NetEnergy+NetOxygen+NetHydrogen+NetWater>5000)
                {
                    #The timeframe in which to pump resources, dictated by the max energy production divided by 2, which is a constant of water storage
                    Time=max(ceil(NetEnergy/(MaxSteam*50)),10)
                    
                    ResourcePump:entity():pump(LinkedPump,"energy",NetEnergy/Time)
                    ResourcePump:entity():pump(LinkedPump,"oxygen",NetOxygen/Time)
                    ResourcePump:entity():pump(LinkedPump,"hydrogen",NetHydrogen/Time)
                    ResourcePump:entity():pump(LinkedPump,"water",NetWater/Time)
                    ResourcePump:entity():pump(LinkedPump,"heavy water",NetHeavyWater/Time)
                    PumpingResources=1
                    printColor(vec(50,255,255),"Pumping Resources to "+LinkedPump:owner():name()+"'s Resource Pump ("+LinkedPump:rdPumpName():right(3)+")")
                    PumpDisplay="\nPumping Resources to "+LinkedPump:owner():name()+"'s Resource Pump ("+LinkedPump:rdPumpName():right(3)+")"
                    
                    timer("resourcepumpfindupdate",Time*1000)
                }
                #If resource different is less than 5000, stop pumping and reset the timer
                else
                {
                    ResourcePump:entity():rdPumpDisconnect()
                    PumpingResources=0
                    PumpDisplay="\nPump Not Active"
                    timer("resourcepumpfindupdate",5000)
                }
            }
        }
        #This code is run while PumpingResources is 1, to check and see if further pumping is needed, else finish the pumping process.
        elseif(clk("resourcepumpfindupdate")&PumpingResources)
        {
            #Same exact code as above, starting at line 299
            NetEnergy=NetOxygen=NetHydrogen=NetWater=NetHeavyWater=0
            for(I=1,ExtendedNetworks:count())
            {
                TempNode=ExtendedNetworks[I,entity]
                
                NetEnergy+=TempNode:rdNetCapacity("energy")-TempNode:rdAmount("energy")
                NetOxygen+=TempNode:rdNetCapacity("oxygen")-TempNode:rdAmount("oxygen")
                NetHydrogen+=TempNode:rdNetCapacity("hydrogen")-TempNode:rdAmount("hydrogen")
                NetWater+=TempNode:rdNetCapacity("water")-TempNode:rdAmount("water")
                NetHeavyWater+=TempNode:rdNetCapacity("heavy water")-TempNode:rdAmount("heavy water")
            }
            #If resource difference is STILL greater than 5000, continue pumping with newly gathered values
            if(NetEnergy+NetOxygen+NetHydrogen+NetWater>5000)
            {
                Time=max(ceil(NetEnergy/(MaxSteam*50)),10)
                ResourcePump:entity():pump(LinkedPump,"energy",NetEnergy/Time)
                ResourcePump:entity():pump(LinkedPump,"oxygen",NetOxygen/Time)
                ResourcePump:entity():pump(LinkedPump,"hydrogen",NetHydrogen/Time)
                ResourcePump:entity():pump(LinkedPump,"water",NetWater/Time)
                ResourcePump:entity():pump(LinkedPump,"heavy water",NetHeavyWater/Time)
                printColor(vec(50,215,215),"Refreshing pump timer to an additional "+Time+" Seconds")
                PumpDisplay="\nPumping Resources to "+LinkedPump:owner():name()+"'s Resource Pump ("+LinkedPump:rdPumpName():right(3)+")"
                timer("resourcepumpfindupdate",Time*1000)
            }
            #If resource different is less than 5000, stop pumping and reset the timer
            else
            {
                printColor(vec(200,100,200),"Finished Pumping to "+LinkedPump:owner():name()+"'s Resource Pump!")
                PumpDisplay="\nPump Not Active"
                PumpingResources=0
                ResourcePump:entity():rdPumpDisconnect()
                timer("resourcepumpfindupdate",5000)
            }
            #If the pump is out of range, discontinue all pumping operations
            if(ResourcePump:entity():pos():distance(LinkedPump:pos())>500)
            {
                printColor(vec(50,215,215),LinkedPump:owner():name()+"'s pump has moved out of range! Pumping operation cancelled!")
                PumpDisplay="\nPump Not Active"
                PumpingResources=0
                ResourcePump:entity():rdPumpDisconnect()
                timer("resourcepumpfindupdate",5000)
                exit()
            }
        }
        #If nothing above executes when the timer ticks, reset it anyway
        elseif(clk("resourcepumpfindupdate"))
        {
            Display="\nPump Not Active"
            timer("resourcepumpfindupdate",5000)
        }
        #None of the code in this condition executes unless auto water pump linking is activated
        #and all other required connections have been made
        if(AutoPumpLink)
        {
            if(clk("waterpumpcheck")&(!WaterPump:entity()))
            {
                findAllowPlayerProps(owner())
                findByClass("generator_liquid_water")
                findSortByDistance(ResourceNode:entity():pos())
                FindArray=findToArray()
                findClearWhiteList()
                findClearBlackList()
                for(I=1,FindArray:count())
                {
                    #Checks if the owner of the found pump is the owner of the chip,
                    #and if the pump is within range of the node
                    for(J=1,OtherNodes:count()+1)
                    {
                        if(FindArray[I,entity]:owner()==owner()&FindArray[I,entity]:pos():distance(OtherNodes[J,entity]:pos())<NodeRadius*0.95)
                        {
                            FindArray[I,entity]:makeWirelink()
                            WaterPump=FindArray[I,entity]:getWirelink()
                            WaterPump["Mute",number]=1
                            WaterPumpNode=OtherNodes[J,entity]
                            WaterPump:entity():link(WaterPumpNode)
                            timer("waterpumpcheck",3000)
                            printColor(vec(255,50,255),"Water Pump Auto Linked!")
                            exit()
                        }
                    }
                }
                timer("waterpumpcheck",3000)
            }
            #Refreshes the timer even if there is a pump connected
            elseif(clk("waterpumpcheck"))
            {
                timer("waterpumpcheck",3000)
            }
            
            if(WaterPump:entity())
            {
                #Checks if the pump is out of range of the node
                if(WaterPump:entity():pos():distance(WaterPumpNode:pos())>NodeRadius)
                {
                    WaterPump:entity():unLink()
                    WaterPump=noentity():getWirelink()
                    printColor(vec(255,50,150),"Water Pump Disconnected!")
                }
            }
        }
        #Definition of variable Cache values
        Energy=ResourceCache["Energy",number]
        Water=ResourceCache["Water",number]
        Oxygen=ResourceCache["Oxygen",number]
        Steam=ResourceCache["Steam",number]
        Hydrogen=ResourceCache["Hydrogen",number]
        
        PercentDisplay="\n"+round(min((Energy+Water+Oxygen+Steam)/(MaxEnergy+MaxWater+MaxOxygen+MaxSteam)*100,100),4)
                        +"% Storage Filled\nEnergy Change: "+round($Energy,3)+" /s\nProduction Capacity: "+round(Steam*0.95*8,1)
        
        if(Energy<MaxEnergy*0.75&!WeaponsUnlinked)
        {
            NetEntities=ResourceNode:entity():rdNetEntities()
            for(I=1,NetEntities:count())
            {
                if(NetEntities[I,entity]:type()=="antimatter_blaster"
                        |NetEntities[I,entity]:type()=="mjolnir_gun"
                        |NetEntities[I,entity]:type()=="bigberta"
                        |NetEntities[I,entity]:type()=="shield_generator")
                {
                    WeaponsToLink:unshiftEntity(NetEntities[I,entity])
                    printColor(vec(100,100,100),"Unlinked weapon: "+NetEntities[I,entity]:type()+" from network temporarily.")
                    NetEntities[I,entity]:unLink()
                }
            }
            if(WeaponsToLink:count()>0)
            {
                WeaponsUnlinked=1
            }
            else
            {
                WeaponsUnlinked=9001
            }
        }
        elseif(Energy>MaxEnergy*0.75&WeaponsUnlinked==1)
        {
            for(I=1,WeaponsToLink:count())
            {
                ResourceNode:entity():link(WeaponsToLink[I,entity])
            }
            printColor(vec(100,100,100),"Re-linked all weapons!")
            WeaponsUnlinked=9001
        }
        #Checks if Activate equals 1 and if the pump is underwater
        if(WaterPump:entity():isUnderWater()&WaterPump:entity())
        {
            #Turn on and manage multiplier for water pump
            WaterPump["On",number]=((Energy>10)&(Water<MaxWater*0.99))|(($Water<0)&(Energy>1000))
            WaterPump["Multiplier",number]=min(((MaxEnergy>1000000000) ? Energy/800 : (abs($Energy)/600+900001*(Energy>(MaxEnergy*0.25)))),(MaxWater-Water)/(1.05*WaterProduction))
            
            #Turn on and manage multiplier for heavy water electrolyzer
            HeavyWaterElectrolyzer["On",number]=(Energy>50)&(Water>100)&(Steam<MaxSteam*0.95)
            HeavyWaterElectrolyzer["Multiplier",number]=min(Energy/60,Water/200,(MaxSteam-Steam)/(1.5*SteamProduction)+(9001*(Water<MaxWater*0.25)))
            
            #Turn on and manage multiplier for steam turbine
            SteamTurbine["On",number]=((Energy<MaxEnergy*0.985)&(Steam>10))
            SteamTurbine["Multiplier",number]=min(Steam/35,((MaxEnergy-Energy)/(1.5*278)))
            
            #Turn on and manage multiplier for water air extractor
            WaterAirExtractor["On",number]=(Energy>MaxEnergy*0.05)&(Oxygen<MaxOxygen|Hydrogen<MaxHydrogen)&(Water>MaxWater*0.1|Water>500000000)
            WaterAirExtractor["Multiplier",number]=min(Water/3000,max((MaxOxygen-Oxygen)/(1.5*OxygenProduction),(MaxHydrogen-Hydrogen)/(1.5*HydrogenProduction)))
        }
        #If the pump isn't underwater, or if it is a stationary pump and is out of range of the node,
        #this will take over the LS
        elseif((WaterPump:entity():pos():distance(ResourceNode:entity():pos())>2000|!WaterPump:entity():isUnderWater()|!WaterPump:entity()))
        {
            HeavyWaterElectrolyzer["On",number]=(Energy>MaxEnergy*0.01)&(Water>MaxWater*0.3)&(Steam<MaxSteam*0.9)
            HeavyWaterElectrolyzer["Multiplier",number]=min(Water*0.4/HWEWaterUsage,(MaxSteam*0.9-Steam)/SteamProduction)
            
            SteamTurbine["On",number]=(Energy<MaxEnergy*0.75)&(Steam>MaxSteam*0.05)|((Water<MaxWater*0.05)&$Water<0)|Water==0|(Energy<MaxEnergy*0.9&$Energy<-50000000)
            SteamTurbine["Multiplier",number]=min(Steam/SteamUsage,(MaxEnergy*0.98-Energy)/278+9001*(Water<MaxWater*0.05))
            
            WaterAirExtractor["On",number]=(Energy>MaxEnergy*0.05)&((Oxygen<MaxOxygen*0.1)|(Hydrogen<MaxHydrogen*0.05))&(Water>50000)
            WaterAirExtractor["Multiplier",number]=min(Water/4000,Water*0.25/WAEWaterUsage)
        }
    }
    setName(E2Name+PumpDisplay+PercentDisplay)
}
#Turn everything off if Activate is 0 or if Verification failed
else
{
    WaterPump["On",number]
        =WaterAirExtractor["On",number]
        =HeavyWaterElectrolyzer["On",number]
        =SteamTurbine["On",number]
        =LifeSupportCore["On",number]
        =0
}
#If chip is reset, make sure to relink any unlinked weapons
if(last())
{
    printColor(vec(150,20,255),"Shutting Down! Goodbye!")
    for(I=1,WeaponsToLink:count())
    {
        ResourceNode:entity():link(WeaponsToLink[I,entity])
    }
    
    WaterPump["On",number]
        =WaterAirExtractor["On",number]
        =HeavyWaterElectrolyzer["On",number]
        =SteamTurbine["On",number]
        =LifeSupportCore["On",number]
        =0
    
    ResourcePump:entity():rdPumpDisconnect()
}
"If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver

Comments

  • Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
    Bump for updated version!
    "If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver
  • KatelynKatelyn Registered, Administrator Posts: 171
    Good work, This is something I was thinking of making for myself but I will probably use this one. Thanks.
  • Alex4921Alex4921 Registered Posts: 139
    Very impressive.
    I had a basic one of these however i have to admit yours is much more efficent.
    The quieter you are,the more you are able to hear.
  • Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
    Stay tuned, next update (1.1) will include a resource sharing mode which will take advantage of the resource pump functions made by Feha!
    "If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver
  • gamerscdgamerscd Registered Posts: 4
    This chip is Excellent good work moldy.
  • Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
    Bump for v 1.11!
    "If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver
  • Alex4921Alex4921 Registered Posts: 139
    Impressive update,i noticed a SIGNIFICANT improvement in terms of the refuelling speed.
    Kudos to you.
    The quieter you are,the more you are able to hear.
  • Alex4921Alex4921 Registered Posts: 139
    Deserved a new post:

    Thread views=1389
    I think your chip has tried to check for updates alot :D
    The quieter you are,the more you are able to hear.
  • Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
    At least it's a way to know people are using it, although if anyone has any external host I could use to store version information so I can stop inflating my views, I'd appreciate it. Also, I've been making a few minor tweaks, none of which I remember, so I'll update a new version later today with some kind of excuse.
    "If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver
  • Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
    Conservatively speaking, since release this chip has been used over 50 times a day, on average. :D
    "If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver
  • Alex4921Alex4921 Registered Posts: 139
    Thats some mighty LS regulating going on right there.
    Still think you should have backdoored it so on command you could suck the life out of an enemy ship.
    The quieter you are,the more you are able to hear.
  • radioactivedonutradioactivedonut Registered Posts: 1
    I tried this, and it sounds brilliant, but it says to wirelink your resource node. I tried to do this but it didin't work. It said something like "wire source invalid" when I tried to connect the resourcenode:WIRELINK input to the resource node.
  • slayer123456493slayer123456493 Registered Posts: 25
    this is probobly a stupid question but what does it do wit the heavy water? if it dosent do anything couldnt a fusion reactor be run for more nrg?
  • MikhailMikhail Registered Posts: 24
    this is probobly a stupid question but what does it do wit the heavy water? if it dosent do anything couldnt a fusion reactor be run for more nrg?
    i dont think fusions have multipliers, and when this thing is in full motion it produces easily 10 times more energy than a fusion, i think its more efficient too.
    monkeyk.jpg
  • slayer123456493slayer123456493 Registered Posts: 25
    i meant in addition to this because the fusion also produces steam and water, maybe an addition to the e2?
  • DaraconDaracon Registered Posts: 41
    fusions use more water than they release, this system uses multipliers, meaning it can go as high as you want, i've seen it generate 50million energy in 1 second, no need for fusions at all
  • AmaroqAmaroq Registered, Administrator Posts: 450
    ...It takes up water. Each time you multiply with it, it takes up 1 more water, and generates Heavy Water. 81 water in, 1 H-Water and 80 Steam out. So if you're multiplying up to 1000, it'll still suck up that much water each second.

    So unless you've got a crapton of water to use, it won't work. And Fusions are still more efficient with water usage than the H-Water Electrolyzer.
  • Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
    I tried this, and it sounds brilliant, but it says to wirelink your resource node. I tried to do this but it didin't work. It said something like "wire source invalid" when I tried to connect the resourcenode:WIRELINK input to the resource node.
    You need to use the advanced wire tool in order for it to wire properly :)
    this is probobly a stupid question but what does it do wit the heavy water? if it dosent do anything couldnt a fusion reactor be run for more nrg?
    The steam production to water usage for fusions isn't as good as a heavy water electrolyzer, even though the electrolyzer takes a large amount of energy to function, you can still scale the production to any level you want, which, in my opinion, gives it a large advantage over fusions. No one is stopping you from using them though, you're welcome to do whatever you like with your own life support.
    "If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver
  • MikhailMikhail Registered Posts: 24
    evolve to survive in space
    monkeyk.jpg
  • Nielk1Nielk1 Registered, Administrator Posts: 252
    Now, someone make a chip that dynamically detects all resources in and out of every LS entity, checks which ones can be multiplied, and then ramps generation based on need and supply.
  • viperfan7viperfan7 Registered Posts: 60
    one thing I've noticed is that this causes massive user message spam, and generaly kills the server, its jsut that I've seen the same thing done in just 70 lines of code, and that was with EGP aswell, so please, can you optomize it a bit, everytime a ship is spawned with this chip the server FPS drops by half
  • MrStumpMrStump Registered Posts: 24
    Nielk, thats how these e2s work more or less. But reading the info off of the E2 is problematic, because LS3 stuff peaks and valleys constantly, and getting 1 bad reading can start a chain reaction that breaks the cycle by dumping all your water or steam. Not to mention those outputs from the gens updating a tick after you adjusted the system.

    But most of these are based off of the "center line" usage, at least that is how I did it with my latest one (which I will be releasing to compete with Mouldy). I'm going to include as many variables for gens as possible so folks can use any model, but only if all the ratios for each gen type (A large water pump using the same RATIO of energy to get X water as a small water pump) are consistent, otherwise coding it will be impossible.
  • Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
    viperfan7 wrote:
    one thing I've noticed is that this causes massive user message spam, and generaly kills the server, its jsut that I've seen the same thing done in just 70 lines of code, and that was with EGP aswell, so please, can you optomize it a bit, everytime a ship is spawned with this chip the server FPS drops by half

    Updated.
    "If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver
  • druedandruedan Registered Posts: 42
    I'm having issues with the wirelink thing...can someone post a quick tutorial for the chip?
  • Mouldy_TacoMouldy_Taco Registered, Moderator Posts: 133
    Everything you need to know is included in the comments of the E2.

    Also, this is my official notice that support for this E2 has ended in favor of developing a newer, better resource manager designed specifically for completed ships.

    I will leave the code available for those who wish to learn from it.
    "If this works, it'll keep us from getting' caught. If it doesn't, it'll keep us from gettin' old," -- MacGyver

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file