Lets put some cogs on fishpeople (modding thread)

Discussion in 'Clockwork Empires General' started by Dienes, Jul 18, 2014.

  1. Dienes

    Dienes Member

    Very cool. Do you think you could grab the functions that are called in the CE files but not defined in any of them or the LUA base files? I know there are some gaslamp added and they might be important or useful.
     
  2. rydash

    rydash Member

    I just read through this and saw your screenshots that included citizens with modified traits. But, I have a question - shouldn't all the citizens have ended up with all three traits? You only have three listed in your xml files. And as far as I can tell, citizen.go assigns traits with the following:
    Code:
    for i=1,3 do
         randomTrait = rand(1,#traitNames)
    
         state.AI.traits[ traitNames[ randomTrait ] ] = true
         state.traits[ i ] = state.AI.traits[traitNames[ randomTrait ] ]
    end
    So, this could mean:
    • traitNames is being defined somewhere or by something else that does not match up with the actual amount of traits in the XML file
    • Collisions on a random number selection cause a new trait to not get selected, leaving a citizen with less than three traits
    • You added the icons in stages while taking the screenshots, meaning the citizens do have three traits without visible icons for some of them at that point.
    If the answer is either of the first two, that has some serious implications on how this system works. I'm curious to find out what the answer is!

    EDIT: Okay, it's not the first one - #traitNames is derived from the XML file. Neat!
     
    Last edited: Aug 5, 2014
    Xyvik likes this.
  3. Xyvik

    Xyvik Member

    I put all three traits and their icons in at the same time before I even ran the game. I was a bit surprised to see people with only one or two traits as well. Quite an intriguing system, for sure.
     
  4. Alistaire

    Alistaire Member

    Then they must've added a specific trait twice. What you WANT to do is this;

    Code:
    local tmp = traitNames
    for i = 1, ( #tmp >= 3 and 3 or #tmp ) do
       randomIndex = math.random( 1, #tmp )
     
       state.AI.traits[ tmp[randomIndex] ] = true
       state.traits[ i ] = state.AI.traits[ tmp[randomIndex] ]
     
       table.remove( tmp, randomIndex )
    end
    tmp = nil
    
    This code creates a temporary copy of traitNames. It then checks IF traitNames has enough entries to generate 3 traits.
    Then it picks a random index randomIndex from tmp, uses that index in tmp for further calculations. After those calculations it REMOVES that index from tmp, so it's not possible to choose the contents of that index during any further iterations, because the entire table shifts to keep a continuous numeric table which still contains every trait someone could have if they took the trait in index randomIndex.

    Be careful with this (untested, because I ain't got the game myself) code, because Lua uses pointers when you actually want to assign a variable to another variable, and local tmp = traitNames doesn't COPY traitNames to tmp. tmp = nil frees the pointer, but I'm not sure whether table.remove( tmp, randomIndex ) affects traitNames, or whether it uses a local copy of traitNames (which would be harmless).

    Code:
    t = {"A", "B"}
    local t2 = t
    print(t[1], t2[1])
    table.remove(t2, 1)
    print(t[1], t2[1])
    
    >A   A
    >B   B
    
    ^ Demonstration of table.remove on local table pointer t2 overwriting data in actual table t

    IF it does work, it should fix the bug where people have less than 3 traits.

    However if it doesn't you'll need to add a table.copy() function somewhere so you can tmp = table.copy( traitNames ) - (table.copy() isn't a native function, but there's enough versions of it on the internet).
     
    Last edited: Aug 6, 2014
    Samut likes this.
  5. Dienes

    Dienes Member

    Good lua wizarding to know but you might want to repost it over in this thread.
     
  6. ZodiacIsEpic

    ZodiacIsEpic Member

    Xyvik, thank you for the post about how to make new traits, I have already begun to abuse it 2016-04-19.png
     
  7. Samut

    Samut Member

    I never saw this thread until just now; it's a great introduction to modding CE.

    As someone who fooled around with mods for a while after CE first went into Early Access, I'm looking forward to the game getting out of EA (once it's working properly) and hopefully Steam Workshop support being added. It will be fun to start modding again once my changes don't get blown away with every update.
     
  8. MOOMANiBE

    MOOMANiBE Ah, those were the days. Staff Member

    This would almost certainly remove the data from the source table. Lua's direct table pointers are the main reason we pull data OUT of database tables in the code before modifying it.
     
  9. ZodiacIsEpic

    ZodiacIsEpic Member

    I have nothing against Koreans, it's a running joke with my mates: upload_2016-5-2_19-37-58.png