Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 5 6 [7] 8 9 ... 42

Author Topic: [DFHack] Roses' Script Collection Updated 5/4/15  (Read 125203 times)

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: DFHack Spells (linked to DFHack script collection) Overhaul
« Reply #90 on: March 19, 2014, 02:20:35 pm »

Alrighty. I'm not sure how to investigate the vmethods either, so I will ask around and see what I can come up with.
Dissassemble, or interpose it and try to make sense of it. (or ask for someone to do it :) ). I only got that the 4th being triggered when applying(?) the effect. And the first value is probably target unit.

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells (linked to DFHack script collection) Overhaul
« Reply #91 on: March 21, 2014, 06:09:51 pm »

Alrighty. I'm not sure how to investigate the vmethods either, so I will ask around and see what I can come up with.
Dissassemble, or interpose it and try to make sense of it. (or ask for someone to do it :) ). I only got that the 4th being triggered when applying(?) the effect. And the first value is probably target unit.

Hmm, might be out of my league. I know how to program for work, but I never have to deal with disassembles. Although it might be a useful learning experience.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack Spells (linked to DFHack script collection) Overhaul
« Reply #92 on: March 21, 2014, 06:48:26 pm »

Interposition isn't too hard, from what I've seen.

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells (linked to DFHack script collection) Overhaul
« Reply #93 on: April 01, 2014, 03:53:14 pm »

There is a new script coming soon which opens up a wide variety of new effects. I call it 'counters'!

Here's how it works, each unit is assigned one (or more as needed) persistent variable(s) and there are global counters available as well. These variables track 'counters' calls. The counters are then increased (or decreased) as necessary and the attached script is run, the counter is then reset to zero. A given unit can have as many counters on them as you want (although I don't know how much memory storage or anything like that persistent variables take up).

Here's an example, after 10 times the given script will run.
[SYN_CLASS:counters]
[SYN_CLASS:\UNIT_ID] <- unit id or global
[SYN_CLASS:COUNTER] <- Here is your custom counter name (i.e. FIRE, POISON, FURY, whatever you want!)
[SYN_CLASS:minimum_10] <-minimum or percentage then the number
[SYN_CLASS:1] <- amount the counter changes
[SYN_CLASS:script_args]

Here's another example, this has a percentage chance to trigger each use, with the percentage going up each use (linearly), e.g. first use is 10%, second is 20% etc...
[SYN_CLASS:counters]
[SYN_CLASS:\UNIT_ID]
[SYN_CLASS:COUNTER]
[SYN_CLASS:percentage_10]
[SYN_CLASS:1]
[SYN_CLASS:script_args]

Finally another example, this time its a global counter, everytime any unit uses this it goes up, when it reaches a hundred, BAM script
[SYN_CLASS:counters]
[SYN_CLASS:global]
[SYN_CLASS:COUNTER]
[SYN_CLASS:minimum_100]
[SYN_CLASS:1]
[SYN_CLASS:script_args]

NOTE: I have the script written, I am just currently bug testing it and playing with some neat examples (like a blood lust that increases strength on each cast, and after ten casts makes the user CRAZED]
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack Spells *New Scripts incoming soon!*
« Reply #94 on: April 01, 2014, 04:44:53 pm »

If I could, I would outright hire you to write some Warlock spells. :)

That counter system looks extremely useful, and dozens of different effects come to mind, especially since Magic the Gathering uses tokens to the same effect. Can this somehow be applied to kills or deaths as well? If race:goblin deaths > 100, then run script that makes goblins stronger. Things like that... a level scaling system for the invaders. ^^
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: DFHack Spells *New Scripts incoming soon!*
« Reply #95 on: April 01, 2014, 04:51:28 pm »

If I could, I would outright hire you to write some Warlock spells. :)

That counter system looks extremely useful, and dozens of different effects come to mind, especially since Magic the Gathering uses tokens to the same effect. Can this somehow be applied to kills or deaths as well? If race:goblin deaths > 100, then run script that makes goblins stronger. Things like that... a level scaling system for the invaders. ^^

I actually do want to figure out how to use counters for other things as well (like kills and deaths, possibly migrant waves, megabeast attacks, any number of things). I think it should be pretty simple to do a global death/kill count (e.g. 100 goblins have died at your fort now goblins arrive with better skills/stats, or your dwarfs have killed 100 enemies here is a random gift from Armok)

What might be a little more challenging (and what I would like to ultimately do) is have a kill counter for each unit (e.g. Urist McDwarf has killed 10 enemies he now has 1 skill point to use, etc...). I have only lightly dabbled in the eventful scripts, so there may be a handy way to track kills/deaths that way. Otherwise I think I would need to do a daily check of your Dwarfs. It means the affects would be delayed, but not by too much.
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack Spells *New Scripts incoming soon!*
« Reply #96 on: April 01, 2014, 04:55:04 pm »

Which might kill your FPS, in a 200+ dwarf fort. Or so I would assume. Have you spoken to IndigoFenix about ths? It appears that his druidism / animal-merit system could help you. He uses points/counters that are global.
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: DFHack Spells *New Scripts incoming soon!*
« Reply #97 on: April 01, 2014, 07:59:30 pm »

Well there is onUnitDeath(unit_id) in the eventful listing, so then I could check which unit killed them and add the counter to the killing unit. Shouldn't impact FPS more than any of the other eventful plugins (like itemsyndrome).

Global counters should have very little impact on FPS, the only question that remains is if I have two Dwarfs that increase a counter at the same time will it register both or just one. Not sure how dfhack scripts work when there are dozens being used in very close proximity (time wise) to eachother.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack Spells *New Scripts incoming soon!*
« Reply #98 on: April 01, 2014, 08:54:14 pm »

How are you storing the unit counters?

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells *New Scripts incoming soon!*
« Reply #99 on: April 01, 2014, 09:08:48 pm »

In persistent variables, the text string stores the information of which counters are in the persistent variable. If you need more than 7 then another persistent variable is created for the unit.

EDIT: I currently don't notice any fps issues with multiple creatures referencing multiple persistent variables. Of course, because of the way persistent variables are handled more than 6 will cause greater slowdowns (still don't think they will be noticeable) as it will create a new persistent variable. Every 7 counters there after (on the same dwarf) will cause another persistent variable to be created. My suggestion to those that might use this system is to limit yourself to less than 13, and preferably, less than 6 custom counters on a given unit. My brief test seemed to indicate that the path finding of a new dwarf or invader causes more of an impact on the fps of your fort then adding the interactions which reference these persistent variables, but these tests were only done up to 100 Dwarfs and 13 counters on each Dwarf.

EDIT2: I should probably add in a deteriorating effect so that the counters slowly click back to zero, and, if they are at zero long enough, disappear from the unit. This will allow more freedom for counters and would be more realistic. You wouldn't expect a POISON counter to stick around for a year and then get triggered at the next invasion.
« Last Edit: April 02, 2014, 12:19:01 am by Roses »
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells *New Scripts incoming soon!*
« Reply #100 on: April 03, 2014, 07:37:56 pm »

For reference, this is the stuff that handles the creation and modification of persistent variables.

Code: [Select]
keys = arg[1] .. '_counters_1'
types = arg[2]
pers,status = dfhack.persistent.get(keys)
num = 1
if not pers then
dfhack.persistent.save({key=keys,value=types,ints={arg[3],0,0,0,0,0,1}})
else
if pers.ints[7] <= 6 then
if string.match(pers.value,types) ~= nil then
local valuea = split(pers.value,'_')
for i,x in ipairs(valuea) do
if x == types then pers.ints[i] = pers.ints[i] + arg[3] end
end
else
if pers.ints[7] < 6 then
pers.value = pers.value .. '_' .. types
pers.ints[7] = pers.ints[7] + 1
pers.ints[pers.ints[7]] = arg[3]
dfhack.persistent.save({key=pers.key,value=pers.value,ints=pers.ints})
elseif pers.ints[7] == 6 then
pers.ints[7] = 7
dfhack.persistent.save({key=arg[1] .. '_counters_2', value=types,ints={arg[3],0,0,0,0,0,0}})
end
end
else
num = math.floor(pers.ints[7]/7)+1
match = false
local valuea = split(pers.value,'_')
for i,x in ipairs(valuea) do
if x == types then
pers.ints[i] = pers.ints[i] + arg[3]
match = true
end
end
if not match then
for j = 2, num, 1 do
keysa = arg[1] .. '_counters_' .. tostring(j)
persa,status = dfhack.persistent.get(keysa)
local valuea = split(persa.value,'_')
for i,x in ipairs(valuea) do
if x == types then
persa.ints[i] = persa.ints[i] + arg[3]
dfhack.persistent.save({key=persa.key,value=persa.value,ints=persa.ints})
match = true
end
end
end
end
if not match then
pers.ints[7] = pers.ints[7] + 1
if math.floor(pers.ints[7]/7) == pers.ints[7]/7 then
print(pers.ints[7])
keysa = arg[1]..'_counters_'..tostring(num+1)
dfhack.persistent.save({key=keysa, value=types,ints={arg[3],0,0,0,0,0,0}})
else
persa.value = persa.value..'_'..types
print(pers.ints[7]-(num-1)*7+1)
persa.ints[pers.ints[7]-(num-1)*7+1] = persa.ints[pers.ints[7]-(num-1)*7+1] + arg[3]
dfhack.persistent.save({key=persa.key,value=persa.value,ints=persa.ints})
end
end
end
dfhack.persistent.save({key=pers.key,value=pers.value,ints=pers.ints})
end

I just got rid of the last bug that was bothering me, so I will be uploading the script (and a few others, like a delay script) this weekend most likely.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells (linked to DFHack script collection) Overhaul
« Reply #101 on: April 06, 2014, 09:30:25 pm »

Alrighty. I'm not sure how to investigate the vmethods either, so I will ask around and see what I can come up with.
Dissassemble, or interpose it and try to make sense of it. (or ask for someone to do it :) ). I only got that the 4th being triggered when applying(?) the effect. And the first value is probably target unit.

What do you use for interposition of DF code? I figured I should really try and nail this problem down, or lots of the coding I have been doing for scripts will be pretty useless.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells *New Scripts incoming soon!*
« Reply #103 on: April 07, 2014, 09:29:07 am »

Thanks, I will take a look at this, this week. Hopefully I can manage to figure something out.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack Spells *New Scripts incoming soon!*
« Reply #104 on: April 09, 2014, 04:15:12 pm »

So using those links that Putnam gave, I have started to play with Interposing the vmethod. So far I have

Spoiler: interposetest.cpp (click to show/hide)

Which I got by copying the eventful.cpp and readjusting it for the vmethod I am interested in. The only problem I am having now is the bolded parts in the code, namely;

1. I don't know how to reference the specific vmethod I am interested in. The eventful.cpp ones all have names for their vmethods, and the one I am interested in does not.
2. Similarly, I am unsure what the proper way to reference a pointer is without knowing what it is pointing to. The eventful.cpp ones have things like df::unit*, but again, I do not know anything about the pointers.

Any thoughts? I may move this question over to the DFHack main thread, since it is getting far from the point of this thread, but I figured I would ask here first since we have already been talking about it.
Logged
Pages: 1 ... 5 6 [7] 8 9 ... 42