Created
April 18, 2013 21:07
-
-
Save Rumrusher/5416231 to your computer and use it in GitHub Desktop.
Updated spawnunit for r3 originally made by warmist using it will spawn a unit ontop of the active[0] unit aka the adventurer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getCaste(race_id,caste_id) | |
| local cr=df.creature_raw.find(race_id) | |
| return cr.caste[caste_id] | |
| end | |
| function CreateUnit(race_id,caste_id) | |
| local race=df.creature_raw.find(race_id) | |
| if race==nil then error("Invalid race_id") end | |
| local caste=getCaste(race_id,caste_id) | |
| local unit=df.unit:new() | |
| unit.race=race_id | |
| unit.caste=caste_id | |
| unit.id=df.global.unit_next_id | |
| local body=unit.body | |
| body.body_plan=caste.body_info | |
| local body_part_count=#body.body_plan.body_parts | |
| local layer_count=#body.body_plan.layer_part | |
| --components | |
| unit.relations.birth_year=df.global.cur_year | |
| --unit.relations.birth_time=?? | |
| unit.relations.old_year=df.global.cur_year+1 --TODO add normal age | |
| --unit.relations.old_time=?? --TODO add normal age | |
| local cp=body.components | |
| cp.body_part_status:resize(body_part_count) | |
| cp.numbered_masks:resize(#body.body_plan.numbered_masks) | |
| for num,v in ipairs(body.body_plan.numbered_masks) do | |
| cp.numbered_masks[num]=v | |
| end | |
| cp.body_layer_338:resize(layer_count) | |
| cp.body_layer_348:resize(layer_count) | |
| cp.body_layer_358:resize(layer_count) | |
| cp.body_layer_368:resize(layer_count) | |
| cp.body_layer_378:resize(layer_count) | |
| --maybe physical_attr | |
| body.blood_max=7000 --TODO normal values | |
| body.blood_count=7000 | |
| body.unk_494=0 | |
| unit.status2.body_part_temperature:resize(body_part_count) | |
| for k,v in pairs(unit.status2.body_part_temperature) do | |
| unit.status2.body_part_temperature[k]={new=true,whole=10067,fraction=0} | |
| end | |
| -------------------- | |
| local stuff=unit.enemy | |
| stuff.body_part_878:resize(body_part_count) -- all = 3 | |
| stuff.body_part_888:resize(body_part_count) -- all = 3 | |
| stuff.body_part_relsize:resize(body_part_count) | |
| --TODO add correct sizes. | |
| stuff.were_race=race_id | |
| stuff.were_caste=caste_id | |
| stuff.normal_race=race_id | |
| stuff.normal_caste=caste_id | |
| stuff.body_part_8a8:resize(body_part_count) -- all = 1 | |
| stuff.body_part_base_ins:resize(body_part_count) | |
| stuff.body_part_clothing_ins:resize(body_part_count) | |
| stuff.body_part_8d8:resize(body_part_count) | |
| unit.recuperation.healing_rate:resize(layer_count) | |
| --appearance | |
| local app=unit.appearance | |
| app.body_modifiers:resize(#caste.body_appearance_modifiers) --3 | |
| app.bp_modifiers:resize(#caste.bp_appearance.modifier_idx) --0 | |
| --app.unk_4c8:resize(33)--33 | |
| app.tissue_style:resize(#caste.bp_appearance.style_layer_idx) | |
| app.tissue_style_civ_id:resize(#caste.bp_appearance.style_layer_idx) | |
| app.tissue_style_id:resize(#caste.bp_appearance.style_layer_idx) | |
| app.tissue_style_type:resize(#caste.bp_appearance.style_layer_idx) | |
| app.tissue_length:resize(#caste.bp_appearance.style_layer_idx) | |
| app.genes.appearance:resize(#caste.body_appearance_modifiers+#caste.bp_appearance.modifiers) --3 | |
| app.genes.colors:resize(#caste.color_modifiers*2) --??? | |
| app.colors:resize(#caste.color_modifiers)--3 | |
| -- maybe add a soul? | |
| df.global.world.units.all:insert("#",unit) | |
| --df.global.world.units.bad:insert("#",unit) | |
| df.global.world.units.active:insert("#",unit) | |
| return unit | |
| end | |
| function PlaceUnit() | |
| trgunit=df.global.world.units.active[0] | |
| local u=CreateUnit(trgunit.race,trgunit.caste) | |
| u.relations.group_leader_id=trgunit.id | |
| local u_nem=dfhack.units.getNemesis(u) | |
| local t_nem=dfhack.units.getNemesis(trgunit) | |
| if u_nem then | |
| u_nem.group_leader_id=t_nem.id | |
| end | |
| if t_nem and u_nem then | |
| t_nem.companions:insert(#t_nem.companions,u_nem.id) | |
| end | |
| u.civ_id=(df.global.world.units.active[0].civ_id) | |
| u.pos:assign(df.global.world.units.active[0].pos) | |
| u.name.first_name="UGABUGA" | |
| u.name.has_name=true | |
| end | |
| PlaceUnit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment