Moving to new LuaWrapper.

develop
Warmist 2012-03-24 14:47:51 +02:00
parent 7fe5fc9a90
commit 99da37ae46
6 changed files with 26 additions and 23 deletions

@ -20,6 +20,7 @@
#include "functioncall.h"
#include "lua_FunctionCall.h"
#include "lua_Offsets.h"
#include "DataDefs.h"
using std::vector;
using std::string;
@ -45,6 +46,8 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
{
lua::state st=lua::glua::Get();
//maybe remake it to run automaticaly
DFHack::AttachDFGlobals(st);
lua::RegisterConsole(st);
lua::RegisterProcess(st);
lua::RegisterHexsearch(st);

@ -371,12 +371,12 @@ function GetRaceToken(p) --actually gets token...
end
function BuildNameTable()
local rtbl={}
local vec=df.world.raws.creatures.all
local vec=df.global.world.raws.creatures.all
--print(string.format("Vector start:%x",vec.st))
--print(string.format("Vector end:%x",vec.en))
--print("Creature count:"..vec.size)
for k,v in iter(vec) do
local name=v:deref().creature_id
for k=0,#vec-1 do
local name=vec[k].creature_id
--print(k.." "..tostring(name))
rtbl[name]=k
end
@ -468,29 +468,29 @@ function ParseNames(path)
return ret
end
function getSelectedUnit()
local unit_indx=df.ui_selected_unit
if unit_indx<df.world.units.other[0].size then
return df.world.units.other[0][unit_indx]:deref()
local unit_indx=df.global.ui_selected_unit
if unit_indx<#df.global.world.units.other[0]-1 then
return df.global.world.units.other[0][unit_indx]
else
return nil
end
end
function getxyz() -- this will return pointers x,y and z coordinates.
local x=df.cursor.x
local y=df.cursor.y
local z=df.cursor.z
local x=df.global.cursor.x
local y=df.global.cursor.y
local z=df.global.cursor.z
return x,y,z -- return the coords
end
function getCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord
--local x,y,z=getxyz() --get 'X' coords
local vector=df.world.units.all -- load all creatures
for i = 0, vector.size-1 do -- look into all creatures offsets
local curpos=vector[i]:deref().pos --get its coordinates
local vector=df.global.world.units.all -- load all creatures
for i = 0, #vector-1 do -- look into all creatures offsets
local curpos=vector[i].pos --get its coordinates
local cx=curpos.x
local cy=curpos.y
local cz=curpos.z
if cx==x and cy==y and cz==z then --compare them
return vector[i]:deref() --return index
return vector[i] --return index
end
end
print("Creature not found!")

@ -42,7 +42,7 @@ function embark(names)
count=MakeTable(modpos,modsize,names) --just remake tables
else
tofind=addressOf(df.ui,"race_id")
_,tofind=df.sizeof(df.global.ui:_field("race_id"))
loc=offsets.find(stoff,0x0f,0xb7,0x0d,DWORD_,tofind) --MOVZX ECX,WORD PTR[]

@ -1,7 +1,7 @@
function friendship_in.patch()
UpdateRanges()
pos=GetTextRegion().start
local crace=addressOf(df.ui,"race_id")--VersionInfo.getGroup("Creatures"):getAddress("current_race")
local _,crace=df.sizeof(df.global.ui:_field("race_id"))
hits={}
i=1
repeat

@ -57,7 +57,7 @@ dofile("dfusion/common.lua")
dofile("dfusion/utils.lua")
dofile("dfusion/offsets_misc.lua")
dofile("dfusion/editor.lua")
dofile("dfusion/xml_struct.lua")
--dofile("dfusion/xml_struct.lua")
unlockDF()
plugins={}
table.insert(plugins,{"simple_embark","A simple embark dwarf count editor"})

@ -2,7 +2,7 @@ tools={}
tools.menu=MakeMenu()
function tools.setrace()
RaceTable=BuildNameTable()
print("Your current race is:"..GetRaceToken(df.ui.race_id))
print("Your current race is:"..GetRaceToken(df.global.ui.race_id))
print("Type new race's token name in full caps (q to quit):")
repeat
entry=getline()
@ -11,7 +11,7 @@ function tools.setrace()
end
id=RaceTable[entry]
until id~=nil
df.ui.race_id=id
df.global.ui.race_id=id
end
tools.menu:add("Set current race",tools.setrace)
function tools.GiveSentience(names) --TODO make pattern...
@ -32,15 +32,15 @@ function tools.GiveSentience(names) --TODO make pattern...
end
end
for _,id in pairs(ids) do
local races=df.world.raws.creatures.all
local races=df.global.world.raws.creatures.all
local castes=races[id]:deref().caste
local castes=races[id].caste
print(string.format("Caste count:%i",castes.size))
for i =0,castes.size-1 do
for i =0,#castes-1 do
print("Caste name:"..castes[i]:deref().caste_id.."...")
print("Caste name:"..castes[i].caste_id.."...")
local flags=castes[i]:deref().flags
local flags=castes[i].flags
--print(string.format("%x",flagoffset))
if flags.CAN_SPEAK then
print("\tis sentient.")