Modding Help ISE4 and a rule breaker "Excavator"

Discussion in 'Starbound Modding' started by DraLUSAD, Mar 7, 2017.

  1. DraLUSAD

    DraLUSAD Giant Laser Beams

    Hello everyone, I'm in need for some modding/coding help based on my mod ISE4 (Industrialization 4: Reconstruction)

    In the past, i ruled out that no Miners/Excavators/Quarries where to be added into my mod, however, after some though, and playing through a Minecraft mod "Immersive Engineering", I've decided i would like to implement such machine

    What it is?
    The Excavator is a Miner type machine, which can collect "Weighted" ores based on the planet your on, it does not take up any forms of blocks, nor does it remove any ore from the underground, but instead "Generates" ores inside its own inventory, which you can remove later for use

    Balancing
    The idea here is that it uses a fuel source, and not just any fuel, ISE4 Batteries, there are a total of 3 current batteries, using them as fuel for the Excavator will determine how much ores it will find
    • Basic Battery = adds 20 rotation points, will collect 20 units of materials
    • Battery Pack = adds 50
    • Fission Battery = adds 250
    as before, the items it adds into its inventory are weighted at values, which means Coal and Salt are more common to find, than that of gold, Silver and Diamonds (excluding Core Fragments)

    Will it find everything?
    Nope, depending on what planet your on, chooses what finds you get
    • T1: Salt, Coal, Tin, Copper, Silver, gold, Iron, Diamonds
    • T2: Salt, Coal, Tin, Copper, Silver, gold, Tungsten, Diamonds, Amethyst
    • T3: Salt, Coal, Tin, Copper, Silver, gold, Titanium, Diamonds, Topaz
    • Ect
    So you'll need to move/make a new Excavator in order to mine the different materials

    Is it worth it?
    In the long run, yes, it will be very expensive to make, and fairly large (Size: TBA), also slow, but still worth it, adding this addition to the mod not only breaks what i ruled out i said i wouldn't add, but also a benefit to players in finding materials

    Seems like something I've seen/heard before
    Maybe you have, a mod i used to play called "Colonies", which allowed you to make a mine, and give a worker a pickaxe to randomly gather materials, like ores, stone and dirt, something similar to add into my mod, but with a more, industrious design.
     
  2. bk3k

    bk3k Oxygen Tank

    I want to be sure I understand. It "finds" (but not really) ores that exist on that planet, and adds them to its own inventory? So this machine is a container at the very least. Adding ore to a container is pretty simple.

    To determine the ore set, Is it reading a biome file or is it actually searching the world?

    I can handle weighted selection, but what do you mean by "Weighted" ores?
     
  3. DraLUSAD

    DraLUSAD Giant Laser Beams

    It would be suited as a container type, since it needs to store items into it, so what ever it calculates puts in a container

    about the ore set thing, i was meaning what planet the miner was on with what resources is located there, so a planet that contains Titanium, could not find Iron, Durasteel, Tungsten, ect, with my custom ore sets, Salt and Tin is universal, but Gems are split on each planet depending on type (Excluding diamonds) so on a fiery planet, Rubies are found there, and radioactive, Emeralds, and so on

    and by weighted i mean by probability of receiving that item, since salt and coal are more, common, they would appear more (less than other materials like cobble, dirt ect), unlike gold and silver which is less common, and diamonds which is very rare, if you know what i mean
     
  4. bk3k

    bk3k Oxygen Tank

    Okay so you're building weighted sets that are indexed by primary biome then.
    Probably you find your world by world.type()
    Check that you aren't on a ship
    Code:
    is_shipworld = function()
      return world.getProperty("ship.fuel") ~= nil
    end
    You want a "default" set too in case the player is in a biome you don't yet support(say a new FU biome). Probably the default set isn't too great of stuff.

    So lets say you have something like
    Code:
    biome[garden] = [
      [ 1.30, "coal"],
      [ 0.60, "copper"],
      [ 0.15, "silver"],
      [ 0.10, "gold"],
      [ 0.00, "diamond"],
      [ 0.00, "corefragment"],
      [ 0.20, "iron"],
      [ 0.15, "tungsten"],
      [ 0.05, "titanium"],
      [ 0.00, "durasteel"],
      [ 0.00, "aegisalt"],
      [ 0.00, "ferozium"],
      [ 0.00, "violium"],
      [ 0.00, "solarium"]
    ]
    You can feed it into this

    Code:
    pickOre = function(whatBiome)
    local list = biome[whatBiome] or biome["default"]
      return biome[ weightedChoice(list) ][2]
    end
    
    
    math.fRandom = function(fMin, fMax, precision)
      --precision should be 10, 100, 1000, etc with a zero for every digit you want in precision
      --if not utilized, default to 100
      precision = precision or 100
      --this returns a random float number between min and max
      --with the exception that the arguments with be effectively reduced to 2 digits of precision.
    
      return math.random( math.floor(fMin * precision), math.floor(fMax * precision) ) / precision
    end
    
    
    
    weightedChoice = function(group)
      local groups = #group
      if groups == 1 then
        return 1
      end
    
      local weight = 0
    
      for _, iWeight in ipairs(group) do
        weight = weight + iWeight[1]
      end
    
      local winner = math.fRandom(0, weight)
    
      local i = 0
      local set = {}
      while i < groups do
        i = i + 1
        set = group[i]
        winner = winner - set[1]
        if winner < 0 then
          return i
        end
    
      end
    
      --failsafe for fRandom return of 0.00, return last group
      return #group
    end
    
    Thus
    Code:
      local ore = pickOre("garden")
    
    That would return an ore selection from the list above. Despite my example list, you could store it in JSON if you wished and load with
    Code:
    allSets = root.assetJson("/objects/myObject/oreLists.config")
    For that matter, you could do this
    Code:
    biomeSet = root.assetJson("/objects/myObject/oreLists.config:" .. whatBiome )
    But that runs the risk of crashing should the biome you would reference not exist in that file.

    edit:
    You might also consider a weight list modifier based off of the threat level itself. There are after all mods that add more threat tiers to planet types than vanilla allows. High threat forest planets, etc.
     
    Last edited: Mar 8, 2017
  5. DraLUSAD

    DraLUSAD Giant Laser Beams

    as coding goes, i'm kinda clueless, in other words, there is so much i understand before a wall slaps bang in front of me, kind of thing, the suitable thing i can think of, and don't feel like I'm insulting you or anything, I'm somewhat not.... um, mentally strong in that department, but instead, could it be possible to build up and put together the "Vanilla" sort of way, like, a working set up, that functions with vanilla and perhaps i can advance from there.

    But thank you all the same for hearing me out, just piecing this sort of thing together, I'm terrible at, if this is alright with you, I'd most appropriate it

    P.S. I'm not trying to make it an excuse, or making out I'm lasy, i'm honestly slow in that coding department
     
  6. bk3k

    bk3k Oxygen Tank

    In any case that code I provided will handle the selection process. Even if you aren't great with coding, I just did a lot of it for you. All you'd need to do is build lists that look like
    Code:
    biome[garden] = [
      [ 1.30, "coal"],
      [ 0.60, "copper"],
      [ 0.15, "silver"],
      [ 0.10, "gold"],
      [ 0.00, "diamond"],
      [ 0.00, "corefragment"],
      [ 0.20, "iron"],
      [ 0.15, "tungsten"],
      [ 0.05, "titanium"],
      [ 0.00, "durasteel"],
      [ 0.00, "aegisalt"],
      [ 0.00, "ferozium"],
      [ 0.00, "violium"],
      [ 0.00, "solarium"]
    ]
    Etc. The number up front is the weight. Bigger numbers are more likely to be selected. 0.00 will never be.
    So you just play with numbers to handle the balancing. It is alright if you don't necessarily understand the code yet.

    You can more or less just copy/paste that list for every primary biome(same thing as the planet type really). Then change the numbers for balance.

    Then for your object(besides the code I provided)
    Code:
    init = function()
      storage.biome = world.type()
      storage.ship = (world.getProperty("ship.fuel") == nil)
      storage.state = storage.state or false
        --storage.state used to tell if the object is active
        --The only thing I know off hand that will be stored between sessions
      storage.harvest_timer = config.getParameter("harvest_timer", 60)
        --obviously you can adjust that.
      storage.harvest_countDown = storage.harvest_timer
    end
    
    update = function(dt)
      if storage.Ship then
        return
      end
    
      if storage.state then
        if (storage.harvest_countDown < 0) then
          storage.harvest_countDown = storage.harvest_countDown - dt
        else
          local ore = pickOre(storage.biome)
          addItem(ore)
          storage.harvest_countDown = storage.harvest_timer + math.random(0, 120)
            --that would give a random cycle time of 1 to 3 minutes.  Adjust according to your vision.
        end
      end
    end
    
    addItem = function(item)
      local addMe = {
        name = item,
        count = math.max( math.min( object.level(), world.threatLevel() ), 1),
          --this could cause faster harvesting on higher threat worlds, with higher tier extractors
        parameters = { }
      }
    
      world.containerAddItems(entity.id(), addMe)
    end
    
    
    Now I typed most that directly into the browser instead of notepad++ and that doesn't make any sense, but I did.

    Anyhow you'd add the functions I gave you above. Note this is missing something - a means to activate. I was going to leave that to you, as you know what you'd demand to run it etc. However you'd want to handle that, you need only flip storage.state to true

    Keep in mind that once storage.state is set to true, it will remain that way between sessions(even if you exit and re-start Starbound), so you need to remember at some points to turn it off. Maybe another timer, etc. Also missing is code to load the lists themselves. I can make that once you figure out how you want to store it. I would recommend a dedicated JSON file like biomeOres.config

    In any case, most your coding is done.

    edit:
    In case this is throwing you off
    init = function()
    function init()
    These are essentially the same thing. I just prefer init = function() to make clear init is the nameSpace, and it is being assigned a function as its value.

    anotherEdit:
    That is an extremely lazy addItem function. It doesn't check for existing items, attempt combining, roll-over any extras to the next available slot. I could do better.
     
    Last edited: Mar 8, 2017
  7. DraLUSAD

    DraLUSAD Giant Laser Beams

    I don't mean to be rude, but i really appreciate your help, but looking at it this way, is just to confusing for me :'(, if you (or someone else) could build it up, as if it was a mode directly for vanilla, I can change it from there, and credit you for your time/work.
    I understand where your getting at, but to me, this is like a jigsaw which I'm unable to understand
     
  8. bk3k

    bk3k Oxygen Tank

    Built for vanilla? That list only has vanilla ores.

    Otherwise I don't understand what you mean. Well that's okay it is your mod.
     
  9. DraLUSAD

    DraLUSAD Giant Laser Beams

    no, no, xD, I'm trying to not sound needy or be disrespectful, what I'm trying to say is, could you paint/build it up to work to what you mentioned, but being its own mod that works for only Vanilla you know, being its own mod with out using modded content, with it being built, I can then change/edit the files needed for ISE4 mod, if that makes sense
     
  10. bk3k

    bk3k Oxygen Tank

    I still don't quite understand what you mean by using "modded content" because any mod itself is "modded content." But if you're talking about needing anything external, no you wouldn't need anything external. I think you have the wrong idea about what that code does. Nothing in that code does anything FU specific, etc. All vanilla. It could be adapted to mod planets though.

    I'm guessing you are confused because I didn't throw it all together. I could mock up an object if you want. That way you can see it work.

    That's all just code for your object to do what (I think) you said you wanted it to do.

    1. Look at what planet it is placed on. It won't do anything on shipworlds.
    2. Based off what planet, pull ore from a weighted list of vanilla ores. Not too often either(1-3 minutes between, could be adjusted).
    3. Some ores will come up more often than others.

    What it is missing is something like onInteraction() to turn it on or off. Or maybe it could turn on/off by wire node, because you probably want to open the container when people interact with it. The other thing it is missing is, searching for fuel in the container and using it.

    Tell me the item name strings for those, and I can do just that. Or I guess I can just download your mod and see for myself.

    I suppose you probably also want a output node that indicates operation. That could tell people when it is out of fuel to run.
     
  11. DraLUSAD

    DraLUSAD Giant Laser Beams

    exactly, that would diffidently help me a massive lot, and i would appreciate it, unlike writing code, i am able to take a piece of content, look at it, experiment with it, and see what i can do with it

    All this sounds perfect to what I'd like to add into the mod ^_^

    mhm, if it makes it more easier on you sure, i don't mind

    That i'd like, man this sounds really awesome, too bad i'm only limited to what i understand, its nice to know people like you who have this kind of knowledge grateful to share

    Edit: currently i added my own "Version" of a miner, but its not as Realistic as I'd like it to be, since it uses a "Crop" coding, but your design, would diffidently make all the difference
     
  12. bk3k

    bk3k Oxygen Tank

    Yeah "ise4emdmk1" etc. I'm messing around with that now, based off the latest version you released. Got most of it put together.

    Now being a container and given that ore stacks to 1000 in vanilla, I think your "full" etc animations might go to waste... unless they're going to tell you how much fuel remains.

    If you like how that generally works(I think you will), you might consider an interface more like the old stove(I have old assets BTW) where you have a small input(for fuel) itemgrid and an itemgrid for output. For now a standard container interface will work.
     
  13. DraLUSAD

    DraLUSAD Giant Laser Beams

    it was a quick idea for using the "Crops" just to identify the fullness, but being a container, that's something we don't need to worry about

    it does sound good, and promising too :)
     
  14. bk3k

    bk3k Oxygen Tank

    I'd like to say it is done(feature complete), but Starbound is being difficult. Or rather maybe I'm to tired to see my obvious mistake. So I'm going to pass out now, figure it out tomorrow.
     
  15. DraLUSAD

    DraLUSAD Giant Laser Beams

    no worries man, i'm not expecting you to rush, or doing it ASAP, just take your time, I appreciate you doing this either way ^_^
     
  16. bk3k

    bk3k Oxygen Tank

    Here's the file. Based off a slightly outdated version as it where. Could use a few improvements but try it out.
     

    Attached Files:

    • ISE4.7z
      File size:
      183.5 KB
      Views:
      2
  17. DraLUSAD

    DraLUSAD Giant Laser Beams

    I'll have a good run at it, Thank you for the help, btw, are you on Steam, could add you as friend and be a contributor, if you don't mind
     
  18. bk3k

    bk3k Oxygen Tank

Share This Page