Jump to content

Welcome to the Forum!

The best place to exchange builds and ideas! Vote for the best ideas and suggestions here.

Join the Avorion Discord!

Connect with other passionate players and talk about the latest news.
Discord

DLC Avorion Into the Rift Out Now!

Now available on Steam!
Steam

stylegenerator.lua


5b641a68697514fe
 Share

Recommended Posts

Hello,

I am enjoying Avorion right now.

But I'd like to learn much more about everything that happens in the file "internal/stylegenerator.lua".

I've checked the documentation provided with the game, the front page of the Internet website, DuckDuckGo, the Avorion wiki... but I was sadly unable to locate any documentation, noting that the documentation is "not necessarily complete".

The best documentation would simply by the LUA code. According to forum moderator koonschi's comment number 25054, "we don't encrypt anything". I have a legal copy of Avorion. What would be the best way to obtain the LUA code (or detailed documentation) for the "internal/stylegenerator.lua" file?

Thank you very much for your assistance.

Edited by 5b641a68697514fe
Link to comment
Share on other sites

  • Boxelware Team

Hei there, the stylegenerator is one of the few scripts that isn't openly available. This is because it's a big selling point of the game. Our entire procedural station and ship generation is based on it.

As for a basic summary: We built a ton of part templates (e.g. engine structures, ship noses, solar panel arms) in Avorion's build mode and each of these templates gets connector points. In the generator a root block is generated and then the generator tries to attach these template parts. New template parts can only be attached to a connector point and with that and multiple iterations the generator builds a ship or station. This is actually why the old generator used to create loads of stick-shapes. We didn't have enough parts with multiple connector points and the generator selected end points way too often.

I hope this helps 🙂

Link to comment
Share on other sites

Well might I add that you and all the other developer(s) did a fantastic job with the new ship generator. 

The summary helped, but I'll be able to see the file in whole sooner or later.

If anyone else is interested, here's a little script I wrote so I could spawn in a ship no-fuss, with any parameters I wanted, giving much more access to the game's ship generator than the ~dev script. All arguments are optional, and the default will spawn a fully functioning ship in front of the player. Returns the created ship (Entity).

function spawn_ship(args)
  -- Accepted args. All are optional. Indent indicates fallback option(s).
  -- args.faction
    -- args.factionIndex
  -- args.plan
    -- args.style
      -- args.typeName -- either "Ship", "Carrier", "Freighter", "Miner", "Station", or "XsotanShip"
      -- args.styleName -- seed for ship style randomization
    -- args.seed -- seed for ship plan randomization, based on style constraints
    -- args.volume
    -- args.maxBlocks -- 200 for fighters and shuttles; 5,000 for most ships; 10,000 for stations
    -- args.scaleToFit -- usually 1 or nil?
    -- args.material
      -- args.materialType -- number: 0 = Iron, etc.
  -- args.sector -- sector to spawn ship in
  -- args.name -- ship name
  -- args.position -- position to spawn ship at in sector
  -- args.arrivalType -- 0, 1, or 2
  -- args.crew
  -- args.shieldDurability
  -- args.defenseLevel -- 2 is "careful", usually 1 for players, usually 0 for ai.
  
  local StyleGenerator = include("internal/stylegenerator.lua")
  local Galaxy = include("galaxy")

  args.faction = args.faction or Faction(args.factionIndex) -- defaults to player's faction

  if args.plan == nil then
    if args.style == nil then
      local generator = StyleGenerator(args.faction.index)
      args.style = generator["make" .. (args.typeName or "Ship") .. "Style"](generator, Seed(args.styleName or math.random(0xffffffff)))
    end
    args.plan = GeneratePlanFromStyle(
      args.style,
      Seed(args.seed or math.random(0xffffffff)),
      args.volume or Balancing_GetSectorShipVolume(args.faction:getHomeSectorCoordinates()) * 7.5,
      args.maxBlocks or 5000,
      args.scaleToFit or 1,
      args.material or Material(args.materialType or MaterialType.Iron)
    )
  end

  args.sector = args.sector or Sector()
  local ship = args.sector:createShip(
    args.faction,
    args.name or "",
    args.plan,
    args.position or MatrixLookUpPosition(-Entity().look, Entity().up, Entity().translationf + Entity().look * 100),
    args.arrivalType or EntityArrivalType.Jump
  )
  
  ship.crew = args.crew or ship.idealCrew
  ship.shieldDurability = args.shieldDurability or ship.shieldMaxDurability
  
  ship:addScriptOnce("data/scripts/entity/startbuilding.lua")
  ship:addScriptOnce("data/scripts/entity/entercraft.lua")
  ship:addScriptOnce("data/scripts/entity/exitcraft.lua")
  ship:addScriptOnce("data/scripts/entity/invitetogroup.lua")
  ship:addScriptOnce("data/scripts/entity/orderchain.lua")
  ship:addScriptOnce("data/scripts/entity/transfercrewgoods.lua")

  local boarding = Boarding(ship)
  boarding.defenseLevel = args.defenseLevel or 2
  
  return ship
end

Example:
 

spawn_ship{name = "My Ship 9000"}

 

Edited by 5b641a68697514fe
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...