Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How can I add wood to a civ at worldgen?  (Read 1807 times)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
How can I add wood to a civ at worldgen?
« on: July 09, 2016, 09:14:59 pm »

I have a little issue...

I want to make a civilization without the PERMITTED_JOB:WOODCUTTER. aka Elves, which do not cut down trees. No problem in itself, but the civ will have no access to wood in worldgen, even if I give them a reaction that creates wood. Apparently only reactions that create bars are used in worldgen. Why, I dont know.

But since civs will always bring wagons and drinks in caravans made out of wood, the wood-less civ will take a RANDOM wood type from the raws. Every embark and every caravan will bring random wood items. EVEN if they have no access to the wood, like a wood that would only grow in the HFS, or does not grow at all; purely because it exists in the raws.

I do have this script that does REMOVE wood types from civs... I think it could be used to add them instead, but someone would need to change the script slightly.

Code: [Select]
local my_entity=df.historical_entity.find(df.global.ui.civ_id)
local sText=" "
local k=0
local v=1

for x,y in pairs(df.global.world.entities.all) do
my_entity=y

k=0
while k < #my_entity.resources.organic.wood.mat_index do
v=my_entity.resources.organic.wood.mat_type[k]
sText=dfhack.matinfo.decode(v,my_entity.resources.organic.wood.mat_index[k])
if (sText==nil) then
--LIQUID barrels
my_entity.resources.organic.wood.mat_type:erase(k)
my_entity.resources.organic.wood.mat_index:erase(k)
k=k-1
else
if(sText.material.id=="WOOD") then
if(sText.plant.id=="SPORE_TREE") then
my_entity.resources.organic.wood.mat_type:erase(k)
my_entity.resources.organic.wood.mat_index:erase(k)
k=k-1
end
end
end
k=k+1
end

k=0
while k < #my_entity.resources.misc_mat.crafts.mat_index do
v=my_entity.resources.misc_mat.crafts.mat_type[k]
sText=dfhack.matinfo.decode(v,my_entity.resources.misc_mat.crafts.mat_index[k])
if (sText==nil) then
--LIQUID barrels
my_entity.resources.misc_mat.crafts.mat_type:erase(k)
my_entity.resources.misc_mat.crafts.mat_index:erase(k)
k=k-1
else
if(sText.material.id=="WOOD") then
if(sText.plant.id=="SPORE_TREE") then
my_entity.resources.misc_mat.crafts.mat_type:erase(k)
my_entity.resources.misc_mat.crafts.mat_index:erase(k)
k=k-1
end
end
end
k=k+1
end

k=0
while k < #my_entity.resources.misc_mat.barrels.mat_index do
v=my_entity.resources.misc_mat.barrels.mat_type[k]
sText=dfhack.matinfo.decode(v,my_entity.resources.misc_mat.barrels.mat_index[k])
if (sText==nil) then
--LIQUID barrels
my_entity.resources.misc_mat.barrels.mat_type:erase(k)
my_entity.resources.misc_mat.barrels.mat_index:erase(k)
k=k-1
else
if(sText.material.id=="WOOD") then
if(sText.plant.id=="SPORE_TREE") then
my_entity.resources.misc_mat.barrels.mat_type:erase(k)
my_entity.resources.misc_mat.barrels.mat_index:erase(k)
k=k-1
end
end
end
k=k+1
end

k=0
while k < #my_entity.resources.misc_mat.wood2.mat_index do
v=my_entity.resources.misc_mat.wood2.mat_type[k]
sText=dfhack.matinfo.decode(v,my_entity.resources.misc_mat.wood2.mat_index[k])
if (sText==nil) then
--LIQUID wood2
my_entity.resources.misc_mat.wood2.mat_type:erase(k)
my_entity.resources.misc_mat.wood2.mat_index:erase(k)
k=k-1
else
if(sText.material.id=="WOOD") then
if(sText.plant.id=="SPORE_TREE") then
my_entity.resources.misc_mat.wood2.mat_type:erase(k)
my_entity.resources.misc_mat.wood2.mat_index:erase(k)
k=k-1
end
end
end
k=k+1
end

k=0
while k < #my_entity.resources.misc_mat.cages.mat_index do
v=my_entity.resources.misc_mat.cages.mat_type[k]
sText=dfhack.matinfo.decode(v,my_entity.resources.misc_mat.cages.mat_index[k])
if (sText==nil) then
--LIQUID cages
my_entity.resources.misc_mat.cages.mat_type:erase(k)
my_entity.resources.misc_mat.cages.mat_index:erase(k)
k=k-1
else
if(sText.material.id=="WOOD") then
if(sText.plant.id=="SPORE_TREE") then
my_entity.resources.misc_mat.cages.mat_type:erase(k)
my_entity.resources.misc_mat.cages.mat_index:erase(k)
k=k-1
end
end
end
k=k+1
end


end
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Roses

  • Bay Watcher
    • View Profile
Re: How can I add wood to a civ at worldgen?
« Reply #1 on: July 09, 2016, 10:18:54 pm »

I haven't tested my resource-change script in the new DFHack or even the new DF so something may have changed, but this *should* work to add oak wood to a civ.

Code: [Select]
entity/resource-change -civ CIV_ID(you will have to look up the id number for the civ you want to add too) -add -type ORGANIC:WOOD -obj OAK:WOOD
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: How can I add wood to a civ at worldgen?
« Reply #2 on: July 09, 2016, 10:44:55 pm »

Tried this. I added this to the onload.init.
entity/resource-change -civ FOREST -add -type ORGANIC:WOOD -obj FEATHER:WOOD

Several questions/points:
1. What is a id number for a civ? Like the ENTITY:id ? For example for elves it's ENTITY:FOREST, so would "-civ FOREST" work?
2. It throws an error about line 25, syntax error near '=='
3. In line 26 you have a typo I think. directino instead of direction.

Even when I correct the typo, the syntax error remains.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Roses

  • Bay Watcher
    • View Profile
Re: How can I add wood to a civ at worldgen?
« Reply #3 on: July 09, 2016, 11:05:44 pm »

No -civ FOREST won't work, at least not yet. I will update the script so that it will, but right now it is expecting a number (like if you look at a dwarf or elf with gui/gm-editor there will be a civ_id entry. I'll change it so that if you give it a string instead of a number it will assume you want all civs under entity FOREST to be effected.

You are right, there are actually several typos in the version I have uploaded.

Code: [Select]
--entity/resource-change.lua version 42.06a

local utils = require 'utils'
local split = utils.split_string

validArgs = validArgs or utils.invert({
 'help',
 'civ',
 'type',
 'obj',
 'remove',
 'add',
 'verbose'
})
local args = utils.processArgs({...}, validArgs)

mtype = string.upper(split(args.type,':')[1])
stype = string.upper(split(args.type,':')[2])
mobj = string.upper(split(args.obj,':')[1])
sobj = string.upper(split(args.obj,':')[2])
direction = 0
if args.remove then direction = -1 end
if args.add then direction = 1 end
if args.add and args.removes then return end
if direction == 0 then
 print('No valid command, use -remove or -add')
 return
end

if tonumber(args.civ) then
 civid = tonumber(args.civ)
 civ = df.global.world.entities.all[civid]
 if not civ then
  print('Not a valid civ number')
  return
 end

 dfhack.script_environment('functions/entity').changeResources(civ,mtype,stype,mobj,sobj,direction,args.verbose)
else
 civs = {}
 n = 0
 for _,civ in pairs(df.global.world.entities.all) do
  if civ.entity_raw.code == args.civ then
   civs[n] = civ
   n = n + 1
  end
 end
 
 for _,civ in pairs(civs) do
  dfhack.script_environment('functions/entity').changeResources(civ,mtype,stype,mobj,sobj,direction,args.verbose)
 end
end

That should work (just replace everything in the entity/resource-change file). I don't know, however, if it will cause the entity to actually bring the correct wood and such.

EDIT: You can use -civ FOREST with the above posted code
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: How can I add wood to a civ at worldgen?
« Reply #4 on: July 09, 2016, 11:39:22 pm »

Tested, works partly.

YES, they bring the wood.
NO, their wooden items are not made of that wood.

That is because it only adds wooden logs, not wooden barrels, cages, etc. See the script above; it has entries for barrels, cages, wood, crafts and wood2, which I assume is the wagon.

I tried adding those in addition to ORGANIC:WOOD like this: MISC_MAT:BARRELS, MISC_MAT:WOOD2, MISC_MAT:CAGES, MISC_MAT:CRAFTS, but it did not work. Barrels, cages, wagon, etc, are still made of random woods.

Edit: Anyway, it does work well enough, thank you :)
« Last Edit: July 10, 2016, 12:34:17 am by Meph »
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Roses

  • Bay Watcher
    • View Profile
Re: How can I add wood to a civ at worldgen?
« Reply #5 on: July 10, 2016, 02:23:31 am »

I was afraid of that. I will make the necessary additions to the script so that they actually bring things made of the wood as well. I noticed that the vanilla FOREST entity has wood for their metal weapons as well, I will make it so each is independent and you can say what exactly you want. So that it will be like just how you thought it should be (except I think I will just use MISC instead of MISC_MAT). Should be a fairly simple change.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: How can I add wood to a civ at worldgen?
« Reply #6 on: July 11, 2016, 08:43:03 am »

That is interesting to see. If you finish that script, please share in the thread, I would love to see the end result. Thank you for the great help.
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Roses

  • Bay Watcher
    • View Profile
Re: How can I add wood to a civ at worldgen?
« Reply #7 on: July 11, 2016, 11:23:47 am »

I've been doing some research into the resources a civ has, it seems to be more flexible than I originally thought. For instance, the reason elves use wood as metal for weapons and such is because they actually have wood in their metal resources. I can't be certain, but it seems like that would mean you could give a race weapons of other materials (e.g. ruby weapons, sand weapons, leaf weapons, scale weapons, etc...).

Also in research, the materials a civ has access to and the materials that they can make items out of are two different tables. You could easily have a race that only makes golden crafts, steel weapons, and oak cages, while still bringing silver bars, iron bars, and maple logs. You can also change the permitted skills, ethics, and values of a civ although I don't know if that would have any affect on the game.

EDIT: There are some weird fields in the entity table. In particular in unknown2 there is resource_allotment, and in that there is resource_allotments, and in that there are resource_allotment_specifiers. Now I don't know where those names came from, but there seems to be information on all of their allowed items/materials. This is different than just their resources fields and I don't know if these need to be changed as well in order to get accurate working changes. Here is an example metal resource_allotment_specifier
Code: [Select]
<resource_allotment_specifier_metalst: 0x273d3ce0>
anon_1                   = 0
anon_2                   = -1
anon_3                   = 0
mat_type                 = 0
mat_index                = 1
resource_allotment_specifier_metalst.anon_1      = 64
resource_allotment_specifier_metalst.anon_2      = <int32_t[]: 0x273d3cfc>
« Last Edit: July 11, 2016, 11:40:59 am by Roses »
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: How can I add wood to a civ at worldgen?
« Reply #8 on: July 11, 2016, 03:58:19 pm »

No idea about the resource allotments, but elves also have a WOOD_WEAPONS and WOOD_ARMOR tag in the entity file. Not sure if ruby weapons would work, but that would be very interesting. That way you can give them unique materials for each specific item.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Legendary Marksdorf

  • Bay Watcher
  • Praying for Nakéen to stay this time (copium)
    • View Profile
Re: How can I add wood to a civ at worldgen?
« Reply #9 on: July 11, 2016, 06:02:06 pm »

wood that would only grow in the HFS

Wait; I'm going off topic there, but, wood grows there ???
I've been to HFS in adventure mode and I haven't seen a single tree :o

Halnoth

  • Bay Watcher
  • Plan for the Worst. Hope for the Best. Have Fun!
    • View Profile
Re: How can I add wood to a civ at worldgen?
« Reply #10 on: July 12, 2016, 02:54:44 am »

wood that would only grow in the HFS

Wait; I'm going off topic there, but, wood grows there ???
I've been to HFS in adventure mode and I haven't seen a single tree :o

Masterwork
Logged
One of the dwarfs walked in front of Thor to get a better view of the prye, and Thor kicked him irritably into the middle of the flames, which made Thor feel slightly better and made all the dwarfs feel much worse.

Cloth Armor Mod http://www.bay12forums.com/smf/index.php?topic=158967.msg7063531#msg7063531

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: How can I add wood to a civ at worldgen?
« Reply #11 on: July 12, 2016, 06:23:39 am »

Even then it does not grow there. But once you breach the HFS layer it spawns the depth:5:5 grass and bushes and saplings in all cavern soil tiles.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

FantasticDorf

  • Bay Watcher
    • View Profile
Re: How can I add wood to a civ at worldgen?
« Reply #12 on: February 09, 2017, 03:09:49 am »

Sorry this is a old thread, but adding a reaction to create growths like seeds especially instead might prompt them to use the trees. (which then you could pass along to make the type/custom wood out of resulting seeds in fortress mode)

Nessecarily, civs will not use trees without discernible growths (as observable here in #0010131) and when a growth is not present (mushroom cap tops count as growths allowing underground trees to be available) it will fall off the list of applicable usable materials.

You would need to give a tree like glumprong in addition to [OUTDOOR_WOOD] (woodcutting without outdoor wood only applies to fortress mode) a growth to qualify for using [USE_EVIL_WOOD] in a goblin civilization in modded standard game raws to appear at all in worldgen.

Code: [Select]
[PLANT:GLUMPRONG]
[NAME:glumprong][NAME_PLURAL:glumprongs][ADJ:glumprong]
[USE_MATERIAL_TEMPLATE:STRUCTURAL:STRUCTURAL_PLANT_TEMPLATE]
[DISPLAY_COLOR:5:0:0]
[BASIC_MAT:LOCAL_PLANT_MAT:STRUCTURAL]
[USE_MATERIAL_TEMPLATE:WOOD:WOOD_TEMPLATE]
[STATE_NAME:ALL_SOLID:glumprong]
[STATE_ADJ:ALL_SOLID:glumprong]
[STATE_COLOR:ALL_SOLID:PURPLE]
[PREFIX:NONE]
[DISPLAY_COLOR:5:0:0]
[SOLID_DENSITY:1200]
[TREE:LOCAL_PLANT_MAT:WOOD][TREE_TILE:180]
[TRUNK_PERIOD:10]
[HEAVY_BRANCH_DENSITY:0]
[BRANCH_DENSITY:0]
[MAX_TRUNK_HEIGHT:6]
[TRUNK_BRANCHING:2]
[MAX_TRUNK_DIAMETER:1]
[TRUNK_WIDTH_PERIOD:200]
[ROOT_DENSITY:5]
[ROOT_RADIUS:3]
[STANDARD_TILE_NAMES]
[TREE_COLOR:5:0:0]
[DEAD_TREE_COLOR:0:0:1]
[PREFSTRING:living shadows]
[PREFSTRING:knobbly nuts]
[DRY][EVIL]
[BIOME:NOT_FREEZING]
[GROWTH:NUT]
[GROWTH_NAME:knuckle nut:STP]
[GROWTH_ITEM:SEEDS:NONE:LOCAL_PLANT_MAT:SEED]
[GROWTH_DENSITY:1000]
[GROWTH_HOST_TILE:BRANCHES_AND_TWIGS]
[GROWTH_TIMING:100000:250000]
[GROWTH_DROPS_OFF_NO_CLOUD]
[GROWTH_PRINT:0:7:6:0:0:NONE]

I hope this information is helpful to you in getting some more use out of your script. But i do highly press that without it being in worldgen they won't bring it along in trade or visibly use it.
Logged