Create [Artificial Planet] on Tiny & Small planets

A place for discussion of making game modifications.
Jem
Posts: 31
Joined: Tue Aug 15, 2017 9:21 am

Create [Artificial Planet] on Tiny & Small planets

Postby Jem » Tue Mar 05, 2019 3:05 am

I tried editing the script logic to allow (unoccupied) Tiny & Small planets to be 'upgraded' to Medium Barren planets after using create [Artificial Planet]. My thinking was since we can create Medium size planets from nothing, the same should be able to apply to Tiny&Small planets by 'filling' them up to Medium size with more 'soil'. :) Anyone who might find this useful please refer to below that ends with '--jem'. Cheers!

in production.lua

Code: Select all

  function StarProperty.cant_build_more_planets(star)
    local a,b=StarOrbitRange![star.type]()
    for i=a,b
      if not star.planets[i]
        return false
      end
      if (star.planets[i].type=='Gas Giant' or star.planets[i].size=='Tiny' or star.planets[i].size=='Small') and (not star.planets[i].empire) --jem
        return false
      end
    end
    return true
  end

    function StarProperty.num_planet_build_sites(star)
    local a,b=StarOrbitRange![star.type]()
    local rval=0
    for i=a,b
      if not star.planets[i]
        rval+=1

  function complete_build_planet_project(planet,report)
    clear_current_project(planet)
    local push, candidate_slots = pusher {}
    local star in planet
   
    local a,b=StarOrbitRange![star.type]()
    for i=a,b
      if (not star.planets[i]) or (
          (star.planets[i].type=='Gas Giant' or star.planets[i].size=='Tiny' or star.planets[i].size=='Small') and (not star.planets[i].empire) ) --jem
        push | i
      end
    end

    --print(v2s | star.planets)

    if not next | candidate_slots
      report.unable_to_complete='No Build Sites'
      return
    end

    local orbit = candidate_slots[ dice_roll(#candidate_slots) ]
    local old_planet = star.planets[orbit]
    local size='Medium'
    if old_planet and star.planets[orbit].type=='Gas Giant' --jem

Jem
Posts: 31
Joined: Tue Aug 15, 2017 9:21 am

Re: Create [Artificial Planet] on Tiny & Small planets

Postby Jem » Wed Mar 13, 2019 5:02 am

After some testing, I went ahead and add 'Cold' & 'Inferno' planets (regardless of size) to the list of planets that can be 'transformed' by [Make Artificial Planet]. Also the [Rich] mineral property is kept; if any; all other special resources are not. Refer to below lines end with --jem.
\Lua state\Orders\production.lua

Code: Select all

  function StarProperty.cant_build_more_planets(star)
    local a,b=StarOrbitRange![star.type]()
    for i=a,b
      if not star.planets[i]
        return false
      end
      if (star.planets[i].type=='Gas Giant' or star.planets[i].type=='Inferno' or star.planets[i].size=='Tiny' or star.planets[i].size=='Small' or star.planets[i].temperature=='Cold' or star.planets[i].minerals=='Poor') and (not star.planets[i].empire) --jem
        return false
      end
    end

    return true
  end

    function StarProperty.num_planet_build_sites(star)
    local a,b=StarOrbitRange![star.type]()
    local rval=0
    for i=a,b
      if not star.planets[i]
        rval+=1
      elseif (star.planets[i].type=='Gas Giant' or star.planets[i].type=='Inferno' or star.planets[i].size=='Tiny' or star.planets[i].size=='Small' or star.planets[i].temperature=='Cold' or star.planets[i].minerals=='Poor') and (not star.planets[i].empire) --jem
        rval+=1
      end
    end

    return rval
  end

  function complete_build_planet_project(planet,report)

    clear_current_project(planet)
    local push, candidate_slots = pusher {}
    local star in planet
   
    local a,b=StarOrbitRange![star.type]()
    for i=a,b
      if (not star.planets[i]) or (
          (star.planets[i].type=='Gas Giant' or star.planets[i].type=='Inferno' or star.planets[i].size=='Tiny' or star.planets[i].size=='Small' or star.planets[i].temperature=='Cold' or star.planets[i].minerals=='Poor') and (not star.planets[i].empire) ) --jem
        push | i
      end
    end

    --print(v2s | star.planets)

    if not next | candidate_slots
      report.unable_to_complete='No Build Sites'
      return
    end

    local orbit = candidate_slots[ dice_roll(#candidate_slots) ]
    local old_planet = star.planets[orbit]
    local size='Medium'
    if old_planet and (star.planets[orbit].type=='Gas Giant' or star.planets[orbit].size=='Large') --jem
      size='Large'
    end

    local kW_m2=1.2

    local new_planet = new_planet_ref {
      type='Barren',
      minerals='Normal',
      ..size,
      ..planet.star,
      ..kW_m2,
      ..orbit,
      day_length=32,
      rarity='common',
      temperature = get_temperature(kW_m2),
      --name = 'Artificial Planet' , 
          name = (star.name .. " " .. to_roman(orbit) .. '-A'),
      specials = {},
    }
    if old_planet and star.planets[orbit].minerals=='Rich' --jem
      new_planet.minerals='Rich'
    end

akkamaddi
Posts: 147
Joined: Tue Sep 26, 2017 5:11 am

Re: Create [Artificial Planet] on Tiny & Small planets

Postby akkamaddi » Fri Aug 09, 2019 2:14 am

I'm sorry, but I'm having a bit of trouble with this. Where in the file should this be added?

gaerzi
Posts: 210
Joined: Wed Jul 10, 2019 1:30 pm

Re: Create [Artificial Planet] on Tiny & Small planets

Postby gaerzi » Fri Aug 09, 2019 10:49 am

I've used this as a base to make tiny planets buildable but not gas giants. I can accept gathering asteroids and stuff to build planets (it's kind of unlikely there's enough materials to build something the mass of the Earth but let's ignore that) but condensing a gas giant into something solid where the gravity would not be devastating?

Plus the gas giants in this game are too pretty.

@akkamaddi: you need to edit the following functions:
  • function StarProperty.cant_build_more_planets(star)
  • function StarProperty.num_planet_build_sites(star)
  • function complete_build_planet_project(planet,report)

The first two have the logic for finding where you can build artificial planets, the last one has the logic for setting up the new planet's stats.

Backfire_22
Posts: 5
Joined: Mon Aug 19, 2019 1:59 pm

Re: Create [Artificial Planet] on Tiny & Small planets

Postby Backfire_22 » Sun Aug 25, 2019 5:07 pm

Yes, on one hand, it'd make the game much more convenient, but on the other hand, it'd need an even higher level of sci-fi tech than what's available in game - if it is something that can be done at all, this is.
It might be fun to try it once, though... :roll:

AMX
Posts: 66
Joined: Fri Nov 24, 2017 10:41 pm

Re: Create [Artificial Planet] on Tiny & Small planets

Postby AMX » Mon Aug 26, 2019 10:39 am

Backfire_22 wrote:Yes, on one hand, it'd make the game much more convenient, but on the other hand, it'd need an even higher level of sci-fi tech than what's available in game - if it is something that can be done at all, this is.
It might be fun to try it once, though... :roll:

I'm confused - Planet Construction has been available in the game since release?

This mod only makes it a little more logical - the current vanilla system where you can create new planets in empty orbits (and replacing gas giants) but not in orbits blocked by Tiny planets does seem a little weird.

gaerzi
Posts: 210
Joined: Wed Jul 10, 2019 1:30 pm

Re: Create [Artificial Planet] on Tiny & Small planets

Postby gaerzi » Sat Sep 28, 2019 11:13 pm

Replacing "and (not star.planets[i].empire)" by "and (star.planets[i].no_colony or not star.planets[i].empire)" allows to build artificial planets on planet slots where you have an orbital station but no population on the ground.

I think this also lets you build artificial planets "below" AI-controlled orbitals, but that's not too much of a problem IMO.

gaerzi
Posts: 210
Joined: Wed Jul 10, 2019 1:30 pm

Re: Create [Artificial Planet] on Tiny & Small planets

Postby gaerzi » Wed Oct 02, 2019 2:16 pm

I ran into an interesting bug caused by the ability to create artificial planets on small worlds. Here's how you can reproduce it:
  1. Set up a production queue with first building an artificial planet on a slot used by a small planet, and as a second item, colonizing said planet
  2. Once the planet is built, the colonization is still queued to the small planet that was replaced.
  3. If the colonization is complete, you will be the proud owner of an invisible colony on the "ghost" planet.

I'm not sure what consequences this can have. It might be an exploit. Of course it's an exploit that requires a mod, so it's not a problem for the developers.


Another, related, minor issue: my thing above for building artificial planets on planets that have orbitals has the drawback that the orbitals in question remain on the "ghost" planet. It might be possible to transfer them from the old to the new, but I'm not sure how.

Jem
Posts: 31
Joined: Tue Aug 15, 2017 9:21 am

Re: Create [Artificial Planet] on Tiny & Small planets

Postby Jem » Thu Oct 31, 2019 11:07 am

I've changed this to allow existing planets to keep their 'specials'. Previously I only keep the 'Rich' trait.
Thanks gaerzi for your addition!

Find the file > \Lua state\Orders\production.lua
Look for the function then the section with --jem

Code: Select all

  function StarProperty.cant_build_more_planets(star)
    local a,b=StarOrbitRange![star.type]()
    for i=a,b
      if not star.planets[i]
        return false
      end
      if (star.planets[i].type=='Gas Giant' or star.planets[i].type=='Inferno' or star.planets[i].size=='Tiny' or star.planets[i].size=='Small' or star.planets[i].temperature=='Cold' or star.planets[i].minerals=='Poor') and (star.planets[i].no_colony or not star.planets[i].empire) --jem
        return false
      end
    end

    return true
  end

    function StarProperty.num_planet_build_sites(star)
    local a,b=StarOrbitRange![star.type]()
    local rval=0
    for i=a,b
      if not star.planets[i]
        rval+=1
      elseif (star.planets[i].type=='Gas Giant' or star.planets[i].type=='Inferno' or star.planets[i].size=='Tiny' or star.planets[i].size=='Small' or star.planets[i].temperature=='Cold' or star.planets[i].minerals=='Poor') and (star.planets[i].no_colony or not star.planets[i].empire) --jem
   rval+=1
      end
    end

    return rval
  end


  function complete_build_planet_project(planet,report)

    clear_current_project(planet)
    local push, candidate_slots = pusher {}
    local star in planet
   
    local a,b=StarOrbitRange![star.type]()
    for i=a,b
      if (not star.planets[i]) or (
          (star.planets[i].type=='Gas Giant' or star.planets[i].type=='Inferno' or star.planets[i].size=='Tiny' or star.planets[i].size=='Small' or star.planets[i].temperature=='Cold' or star.planets[i].minerals=='Poor') and (star.planets[i].no_colony or not star.planets[i].empire) ) --jem
   push | i
      end
    end

    --print(v2s | star.planets)

    if not next | candidate_slots
      report.unable_to_complete='No Build Sites'
      return
    end

    local orbit = candidate_slots[ dice_roll(#candidate_slots) ]
    local old_planet = star.planets[orbit]
    local size='Medium'
    if old_planet and (star.planets[orbit].type=='Gas Giant' or star.planets[orbit].size=='Large') --jem
      size='Large'
    end

    local kW_m2=1.2

    local new_planet = new_planet_ref {
      type='Barren',
      minerals='Normal',
      ..size,
      ..planet.star,
      ..kW_m2,
      ..orbit,
      day_length=32,
      rarity='common',
      temperature = get_temperature(kW_m2),
      --name = 'Artificial Planet' , 
          name = (star.name .. " " .. to_roman(orbit) .. '-A'),
      specials = {},
    }
    if old_planet
      if star.planets[orbit].minerals=='Rich' --jem
        new_planet.minerals='Rich'
      end
      if star.planets[orbit].special_resources --jem
   if not new_planet.special_resources
     new_planet.special_resources={}
   end
        for i,r in ipairs | star.planets[orbit].special_resources?
     new_planet.special_resources[1+#new_planet.special_resources]=r
        end
      end
    end

    local i=orbit


I'm thinking to do the Mass Scrap of (Same) Building and Ship which will help quite a bit when playing. But after looking around the codes (I don't know LUA) I feel faint and that I suspect (but I could have misunderstood) that LUA is a 'patchwork' programming language. The 'randomness' got to me... I mean there must be an easier way to find out How Many ships of current type is refittable (after following the mass-refit codes)... I was thinking of reusing those codes to count how many ships/station of Same type I can scrap in current star, then across galaxy/empire... I can't help ranting. Cheers!

Jem

rustyi
Posts: 32
Joined: Sat Feb 11, 2017 3:36 am
Location: San Francisco, CA

Re: Create [Artificial Planet] on Tiny & Small planets

Postby rustyi » Wed Mar 04, 2020 2:43 am

I tried only adding the -jem lines into the code and was getting strange errors about hammers and food... I tried adding it 2 different ways and didn't quite get it to work.
Using latest dev build. Really like this concept though!

Jem
Posts: 31
Joined: Tue Aug 15, 2017 9:21 am

Re: Create [Artificial Planet] on Tiny & Small planets

Postby Jem » Tue Jul 21, 2020 3:54 am

Hello rustyi, I'm attaching my production.lua here for you to test. Please backup your own production.lua before replacing with mine. Hope this helps. If it works, then you can use a compare tool to see the difference between both old/new. Cheers!
Attachments
production.zip
(6.08 KiB) Downloaded 1143 times

rustyi
Posts: 32
Joined: Sat Feb 11, 2017 3:36 am
Location: San Francisco, CA

Re: Create [Artificial Planet] on Tiny & Small planets

Postby rustyi » Fri Nov 27, 2020 1:21 am

Thanks Jem - using last dev (august) and tried adding this as mod (mods\orders) and got the same food error (playing Tinkers)


Return to “Modding”

Who is online

Users browsing this forum: No registered users and 14 guests