Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Generate Experiment and Angel Graphics File (Vettlingr Tileset)  (Read 5611 times)

vettlingr

  • Bay Watcher
  • Þjóðalfur
    • View Profile
Generate Experiment and Angel Graphics File (Vettlingr Tileset)
« on: November 05, 2021, 07:42:49 pm »



Some of you may not know that I can code; but I can - and this is my second contribution to the Df community and Dfhack altogether.

This script Searches your save and indexes all creature raws of Angels and Experiments and generates a graphics file for them, giving them unique graphics in game.
The graphics art .pngs are derived from Mephs procedual creatures ultimately from Denzis Random Monsters.

Put the script into hack/scripts,
 the graphics files into your saves graphics folder,
  then and run the script in the dfhack terminal.

Also...
Back your stuff up!

Download on DFFD

Code: [Select]
--
--[====[

generate procedual graphics
==============
Generates graphics for necromancer experiments and divine creatures and puts it into your current save folder

]====]
local utils = require 'utils'

math.randomseed(os.time()) -- random initialize
math.random(); math.random(); math.random() -- warming up

function randomnumber( oneortwo )
        -- random generating
        if oneortwo == 1 then
            value1 = math.random(0,31)
            return value1
        end
        if oneortwo == 2 then
            value2 = math.random(0,29)
            return value2
    end
end
    local selection
    local key = 1
    local hfexpId = {}

    for id, raw in pairs(df.global.world.raws.creatures.all) do
        if raw.creature_id:startswith('HFEXP') then
            hfexpId[key] = raw.creature_id
            key = key + 1
        end
    end

    local key2 = 1
    local hfId = {}

    for id, raw in pairs(df.global.world.raws.creatures.all) do
        if raw.creature_id:startswith('HF') and not raw.creature_id:startswith('HFEXP') then
            hfId[key2] = raw.creature_id
            key2 = key2 + 1
        end
    end

function dfhack.getSavePath()
    if dfhack.isWorldLoaded() then
        return dfhack.getDFPath() .. '/data/save/' .. df.global.world.cur_savegame.save_dir .. '/raw/graphics/'
    end
end

os.execute('mkdir' .. dfhack.getSavePath()..'graphics_procedual_hfexp.txt')
file = io.open(dfhack.getSavePath()..'graphics_procedual_hfexp.txt', 'w')
file:write('graphics_procedual_hfexp\n')
file:write('[OBJECT:GRAPHICS] \n')
file:write('[TILE_PAGE:NECRO] \n')
file:write('[FILE:procedual_hfexp.png] \n')
file:write('[TILE_DIM:32:32] \n')
file:write('[PAGE_DIM:26:30] \n \n')

for i in ipairs(hfexpId) do
    file:write('[CREATURE_GRAPHICS:', hfexpId[i], '] \n')
    file:write('[DEFAULT:NECRO'..':'..randomnumber(1)..':'..randomnumber(2)..':AS_IS:DEFAULT] \n')
end

file:close()

os.execute('mkdir' .. dfhack.getSavePath()..'graphics_procedual_divine.txt')
file = io.open(dfhack.getSavePath()..'graphics_procedual_divine.txt', 'w')
file:write('graphics_procedual_divine\n')
file:write('[OBJECT:GRAPHICS] \n')
file:write('[TILE_PAGE:DIVINE] \n')
file:write('[FILE:procedual_divine.png] \n')
file:write('[TILE_DIM:32:32] \n')
file:write('[PAGE_DIM:26:30] \n \n')

for i in ipairs(hfId) do
    file:write('[CREATURE_GRAPHICS:', hfId[i], '] \n')
    file:write('[DEFAULT:DIVINE'..':'..randomnumber(1)..':'..randomnumber(2)..':AS_IS:DEFAULT] \n')
end

file:close()

print('Generated graphics for Divine and Experiments')
print('Found '..(key - 1)..' Experiments')
print('Found '..(key2 - 1)..' Angels')

return




Shameless Patreon Plug:
« Last Edit: November 06, 2021, 08:01:18 pm by vettlingr »
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: Generate Experiment and Angel Graphics File (Vettlingr Tileset)
« Reply #1 on: November 11, 2021, 04:09:39 am »

They don't match the actual descriptions, do they?

You could improve it by searching the creature raws for wings before assigning a sprite, at minimum.
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

vettlingr

  • Bay Watcher
  • Þjóðalfur
    • View Profile
Re: Generate Experiment and Angel Graphics File (Vettlingr Tileset)
« Reply #2 on: November 12, 2021, 09:38:32 am »

They don't match the actual descriptions, do they?

You could improve it by searching the creature raws for wings before assigning a sprite, at minimum.
Yeah I realised too late the semantics don't match. it generates a graphic file for procedual creatures, not procedual graphics. Going to change it when I get home today

The first release is really just intended to prevent invasions of capital H:s
« Last Edit: November 13, 2021, 02:55:52 pm by vettlingr »
Logged

Bihlbo

  • Bay Watcher
    • View Profile
Re: Generate Experiment and Angel Graphics File (Vettlingr Tileset)
« Reply #3 on: February 18, 2022, 09:13:58 pm »

This is a great idea, I can't wait to see what's possible!
Logged