Jump to content

[Idea] Empire Builder


celludriel

Recommended Posts

Hey,

 

This is something I had in mind during my X3 days but never worked out because of the frustrating scripting language x3 had.  Avorion gives the right tools to maybe do it though.  Lua is a pretty strong language to develop in and it might work.  This is what I had in mind.

 

The players are all agents for a wealthy family that wants to create an empire from scratch.  Each player that joins the server gets tasks assigned all towards building that empire.  These tasks can be building a station in a specific system, mining an amount of resources that you need to deliver to a station, Destroy a pirate den threatening the empire, Build a bunch of ships for the empire,  Help fight of an enemy empire invasion, etc...  With each accomplished task the wealthy family rewards the player with money, mods or whatever drives a player to complete the tasks.  There could be an end goal to win the game for example the family owns a certain amount of territory, or gains an amount of money, influence.

 

This would be a first iteration of the mod, in later iterations there could be AI families , managed by some sort of simulation running in the background, rivaling the players family but that is an all other matter of complexity.

 

I see following challenges in this endeavor

 

- Players login and logoff their tasks need to be persisted somewhere and each time they login their needs to be a way to load the task and assign it to the logged in player.

- There needs to be one master script running from the moment the server starts.  Lets call it the game mode script, that assigns tasks to players, keeps track of their progress, gives rewards, checks if the game has been won, generates events to annoy the players while they finish their tasks etc...  I'm not sure Avorion offers a way to run a script on it's own thread.  Also this script has to be crash proof, suppose it goes down, it needs to reset itself so the server doesn't have to be rebooted.

- The tasks given to the players need to make sense in building an empire.  So that means devising some kind of order in things.  First build a farm station, before building a habitat for example.  Deciding when to start building the next station in queue or give a task to supply an existing station with supplies.

- Since not all sectors are loaded all the time, means supplies of stations don't dwindle, there needs to be a simulation that takes supplies from stations.

 

There are probably many more challenges, this won't be easy to create.  However should it work, I think this can be a fun game mode, giving meaning to the Avorion sandbox.

 

So what do you guys think, possible, don't even try, could be fun, worst idea ever etc... ?

Link to comment
Share on other sites

Well I went ahead and wrote a bit of code that I think would be fundamental for my idea.  A way to run the empire builder manager on it's own thread.  Well ... kinda ... since it seems there is no such thing as real multi threading in lua.  I had to come up with some kind of middle way solution.  I'm happy with the results but it could be a lot better, since I'm hijacking server.lua Update() for scheduling my thread.  Which should be a not done scenario when the game updates server.lua I'm SOL.

 

thread class:

package.path = package.path .. ";data/scripts/lib/?.lua"
package.path = package.path .. ";data/scripts/?.lua"
package.path = package.path .. ";?.lua"
package.path = package.path .. ";?"

local EmpireBuilderThread = {}
EmpireBuilderThread.__index = EmpireBuilderThread

local function new()
    local obj = setmetatable({}, EmpireBuilderThread)
    printlog("creating thread")
    obj.thread = coroutine.create(obj.createEmpireBuilderMasterThread)
    coroutine.resume(obj.thread)
    return obj
end

function EmpireBuilderThread:resume()
    printlog("resuming thread", type(self))
    coroutine.resume(self.thread)
end

function EmpireBuilderThread:createEmpireBuilderMasterThread()
    local elapsedTime = os.clock()
    local nextTriggerTime = elapsedTime + 5

    while true do
      printlog("thread is running")
      if elapsedTime >= nextTriggerTime then
          nextTriggerTime = nextTriggerTime + 5
      end
      
      coroutine.yield()
      elapsedTime = os.clock()
    end
end

return setmetatable({new = new}, {__call = function(_, ...) return new(...) end})

 

server updates

function onStartUp()
    Server():registerCallback("onPlayerLogIn", "onPlayerLogIn")
    Server():registerCallback("onPlayerLogOff", "onPlayerLogOff")
    Galaxy():registerCallback("onPlayerCreated", "onPlayerCreated")
    Galaxy():registerCallback("onFactionCreated", "onFactionCreated")
    empireBuilderThread = EmpireBuilderThread();
end

function update(timeStep)
    local guardianRespawnTime = Server():getValue("guardian_respawn_time")
    if guardianRespawnTime then

        guardianRespawnTime = guardianRespawnTime - timeStep;
        if guardianRespawnTime < 0 then
            guardianRespawnTime = nil
        end

        Server():setValue("guardian_respawn_time", guardianRespawnTime)
    end
    empireBuilderThread:resume()
end

 

See how I instantiate the thread at startup and use the update to resume my yielded thread.  It works but certainly not how I want it.  There should be some kind of callback on serverStart and serverUpdate so I could move all my code to the thread class.

 

Well not sure if I'm going to continue yet, but it does seem to be possible finishing my idea

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
×
×
  • Create New...