Dwarf Script2010.8.16 Major update: Linux and Windows version 0.13 released.Minor features: - capped views with scrollable output
- commenting is possible in two variants like in C/C++/Java:
/* blah */
// blah
- stack data is now completely separate from type info, allowing faster execution without passing around type info at all.
- stack is restored if execution fails (solved a bunch of problems i didn't want to deal with, implementing the above)
- ascii 0-32 show as "?" inside strings in stack.
- \123 inside string constants converts to ascii char 123
- bitwise not
- the ability to set or unset flags (untested)
- loop mismatch error is more informative
- rearranged views
- used commands are now shown for easy copy/paste until history scrolling works.
- history scrolling is now also implemented (use up and down keys)
- added intellisense coloring
Bug fixes: - view disruption is fixed through capping and scrollable output
- fixed disruptions caused by ascii chars 0-31 in strings on the stack
- $ now displays in execution view
- code now fetched rather than recompiled at every function call, and various sleeping bugs that this triggered
- enter no longer executes when there are parse errors
- fixed a bunch of memory leaks
- multiline text outputs is now clean
- functions should now list correctly
- linux: fixed read4 bug when highest bit set, due to pread having a stupid 2G limit so switched to pread64
2010.8.7 Major update: Linux and Windows version 0.12 released.
Addresses/offsets for linux added, except for skills vector
Also fixed:
using escape characters no longer leave the escape character used
errors during execution are now no longer overwritten
linux "reads" reads now full string, not just first character + garbage
linux "readstl" fixed
made possible negative numbers
"set" now works again
new feature:
getfirstnames gets the dwarf first names rather than nicknames - can be combined with nicknames
2010.8.5 Major update: Linux version 0.11b released.
- bug fix on swapping floating points
2010.8.4 Major update: New version 0.11 released.
- Fixed bug occurring accessing names from a higher scope in a loop due to name stack popping incorrectly
- added bitwise operators(and, or, xor, left shift, right shift), modulo, independent stack pop and character value extraction from strings (needed for making a scanner function)
- included current main.ds which has functions for writing labours, attributes, traits and skills (as well reading the latter.)
2010.8.3 Updated: Added mental attributes and traits, and converted all names to lowercase, and spaces are now underscores
When starting the program:

Getting the nicknames:

stop hauling those stones

Done!

After a couple of weeks of banging on the keyboard, I'm finally able to present to you a program that allows you to... well... pretty much anything, that you can script them to do
Initially, I only intended to make a DF therapist and runesmith replacement although it isn't really suppose to be a replacement, but for those who like text based interface rather than the GUIs of DF therapist and runesmith, this program is for you. I had a difficult time to a) find the right dwarf and b) find the right job on that huge spreadsheet of DF therapist and if you had the same problem, then this program is also for you. Because you can simply do:
urist mining on
And urist will have his mining job activated. And when you're done, you can decativate it by typing:
urist mining off
And if that's too much to type you can make a function:
(mining on)mine;
and then:
urist mine
will do the same thing as "urist mining on". Of course nothing prevents you from having "p" stand for "urist mining on"
At the moment the script still has limited functionality, but isn't as buggy as I thought it would be.
This is a checklist of things to do or are done:
1. more labours you can set [DONE]
2. attributes
- physical [DONE]
- mental [DONE]
3. traits [DONE]
4. skills [DONE]
5. preferences
6. looks
7. flags [DONE?]
8. etc.. (other dwarf properties)
9. the ability to set jobs of several dwarves at once (dwarf sets)
10. the ability to set several jobs at once (job sets)
11. having a dwarf automatically switch jobs at a regular interval
12. having a job set when a certain amount of an item is available
13. having a job unset when exp reaches certain lvl (e.g. to stop your supposedly civilian dwarf from training too much)
14 saving and loading your dwarf into a file, so you can play it in another fortress or in another version of df.
15. And more...
I would also appreciate any help making more scripts, ideas for new scripts, pseudocode for scripts if you can't bother learning postfix, and any information regarding how things are stored (non-creature stuff, as I have a fairly good picture of creatures) in df. Also feedback of any kind, positive and negative, would be appreciated, and any suggestions for further developement.
Instructions:1.
Download DS for
Windows or
Linux2. open the main.ds file in a plain text editor3. copy and paste the following script (because I will be updating this often):($ 4 + read4 swap read4 - 4 /)count;
(4* swap read4 + read4)idx;
(24 + read4)strcap;
(20 + read4)strlen;
memoffset 0x0169575c +4+ df:
(0x001C +) nick;
0x07A0 soul:
(soul + read4)getsoul;
0x88 mattr:
0x04AC pattr:
0x0224 trait:
0x07BC labour:
0x087C happiness:
0x0114 id:
0x008C race:
0x00F8 flags1:
0x00FC flags2:
0x0298 birthyear:
0x0110 sex:
0x0088 profession:
0x07A0 likes:
0x01FC 4 + skills:
0x0 looks:
2 traitsize:
(getsoul 0 traitsize * trait + +)nervousness;
(getsoul 1 traitsize * trait + +)rage;
(getsoul 2 traitsize * trait + +)depression;
(getsoul 3 traitsize * trait + +)neurosis;
(getsoul 4 traitsize * trait + +)urge;
(getsoul 5 traitsize * trait + +)stress;
(getsoul 6 traitsize * trait + +)friendly;
(getsoul 7 traitsize * trait + +)company;
(getsoul 8 traitsize * trait + +)leadership;
(getsoul 9 traitsize * trait + +)activeness;
(getsoul 10 traitsize * trait + +)thrillseeking;
(getsoul 11 traitsize * trait + +)optimism;
(getsoul 12 traitsize * trait + +)imagination;
(getsoul 13 traitsize * trait + +)artistic;
(getsoul 14 traitsize * trait + +)emotion;
(getsoul 15 traitsize * trait + +)adventure;
(getsoul 16 traitsize * trait + +)thinking;
(getsoul 17 traitsize * trait + +)rebelliousness;
(getsoul 18 traitsize * trait + +)trusting;
(getsoul 19 traitsize * trait + +)honesty;
(getsoul 20 traitsize * trait + +)helpfulness;
(getsoul 21 traitsize * trait + +)compromising;
(getsoul 22 traitsize * trait + +)modesty;
(getsoul 23 traitsize * trait + +)compassion;
(getsoul 24 traitsize * trait + +)confidence;
(getsoul 25 traitsize * trait + +)organization;
(getsoul 26 traitsize * trait + +)lawfulness;
(getsoul 27 traitsize * trait + +)excellence;
(getsoul 28 traitsize * trait + +)perseverance;
(getsoul 29 traitsize * trait + +)cautiousness;
(getsoul 0 attrsize * mattr + +)analytical_ability;
(getsoul 1 attrsize * mattr + +)focus;
(getsoul 2 attrsize * mattr + +)willpower;
(getsoul 3 attrsize * mattr + +)creativity;
(getsoul 4 attrsize * mattr + +)intuition;
(getsoul 5 attrsize * mattr + +)patience;
(getsoul 6 attrsize * mattr + +)memory;
(getsoul 7 attrsize * mattr + +)linguistic_ability;
(getsoul 8 attrsize * mattr + +)spatial_sense;
(getsoul 9 attrsize * mattr + +)musicality;
(getsoul 10 attrsize * mattr + +)kinesthetic_sense;
(getsoul 11 attrsize * mattr + +)empathy;
(getsoul 12 attrsize * mattr + +)social_awareness;
0x1C attrsize:
(0 attrsize* pattr+ +)strength;
(1 attrsize* pattr+ +)agility;
(2 attrsize* pattr+ +)toughness;
(3 attrsize* pattr+ +)endurance;
(4 attrsize* pattr+ +)recuperation;
(5 attrsize* pattr+ +)disease_resistance;
0 Mining:
1 Wood_Cutting:
2 Carpentry:
49 Bowmaking:
3 Engraving:
4 Masonry:
5 Animal_Training:
6 Animal_Caretaking:
7 Fish_Dissection:
8 Animal_Dissection:
9 Fish_Cleaning:
10 Butchery:
11 Trapping:
22 Growing:
23 Herbalism:
57 Ambush:
71 Swimming:
72 Persuasion:
73 Negotiation:
74 Judging_Intent:
75 Appraisal:
76 Organization:
77 Record_Keeping:
78 Lying:
79 Intimidation:
80 Conversation:
81 Comedy:
82 Flattery:
83 Consoling:
84 Pacification:
85 Tracking:
24 Fishing:
25 Furnace_Operation:
26 Strand_Extraction:
67 Soap_Making:
68 Potash_Making:
66 Lye_Making:
65 Wood_Burning:
27 Weaponsmithing:
28 Armorsmithing:
29 Metalsmithing:
30 Gem_Cutting:
31 Gem_Setting:
32 Wood_Crafting:
33 Stone_Crafting:
34 Metal_Crafting:
35 Glassmaking:
86 Studying:
87 Concentration:
88 Discipline:
89 Observation:
90 Writing:
91 Prose:
92 Poetry:
93 Reading:
94 Speaking:
95 Coordination:
96 Balance:
97 Leadership:
98 Teaching:
99 Fighting:
100 Archery:
101 Wrestling:
102 Biting:
103 Striking:
104 Kicking:
105 Dodging:
38 Axe:
39 Sword:
41 Mace:
42 Hammer:
43 Spear:
44 Crossbow:
50 Pike:
52 Bow:
45 Shield:
46 Armor:
47 Siege_Engineering:
48 Siege_Operation:
70 Pump_Operation:
36 Leatherworkering:
12 Tanning:
69 Dyeing:
37 Bone_Carving:
13 Weaving:
14 Brewing:
16 Clothes_Making:
17 Milling:
18 Threshing:
53 Blowgun:
54 Throwing:
55 Machinery:
56 Nature:
40 Knife:
51 Lash:
21 Cooking:
15 Alchemy:
58 Building_Design:
19 Cheese_Making:
20 Milking:
106 Misc_Object:
59 Wound_Dressing:
60 Diagnostics:
61 Surgery:
62 Bone_Setting:
63 Suturing:
64 Crutch_walking:
(t. getsoul skills + s. 0 0 s count(1 - i. L. X. s i idx l. l read1 t == (l 4+ read1 l 8+ read2 0)(L X i)?)@ )readskill;
(X. L. t. getsoul skills + s. s count(1 - i. s i idx l. l read1 t == (l 4+ L write1 l 8+ X write2 0)(i)?)@ )writeskill;
(i. getsoul skills + i idx l. l read1 l 4+ read1 l 8+ read2)getskill;
0 labour+ mining:
1 labour+ stone_hauling:
2 labour+ wood_hauling:
3 labour+ burial:
4 labour+ food_hauling:
5 labour+ refuse_hauling:
6 labour+ item_hauling:
7 labour+ furniture_hauling:
8 labour+ animal_hauling:
9 labour+ cleaning:
10 labour+ wood_cutting:
11 labour+ carpentry:
12 labour+ stone_detailing:
13 labour+ masonry:
14 labour+ architecture:
15 labour+ animal_training:
16 labour+ animal_care:
17 labour+ diagnosis:
18 labour+ surgery:
19 labour+ setting_bones:
20 labour+ suturing:
21 labour+ dressing_wounds:
22 labour+ feed:
23 labour+ recovering_wounded:
24 labour+ butchery:
25 labour+ trapping:
26 labour+ small_animal_dissection:
27 labour+ leatherworking:
28 labour+ tanning:
29 labour+ brewing:
30 labour+ alchemy:
31 labour+ soap_maker:
32 labour+ weaving:
33 labour+ clothesmaking:
34 labour+ milling:
35 labour+ plant_processing:
36 labour+ cheese_making:
37 labour+ milking:
38 labour+ cooking:
39 labour+ farming:
40 labour+ plant_gathering:
41 labour+ fishing:
42 labour+ fish_cleaning:
43 labour+ fish_dissection:
44 labour+ hunting:
45 labour+ furnace_operating:
46 labour+ weaponsmithing:
47 labour+ armoring:
48 labour+ blacksmithing:
49 labour+ metalcrafting:
50 labour+ gem_cutting:
51 labour+ gem_setting:
52 labour+ woodcrafting:
53 labour+ stonecrafting:
54 labour+ bone_carving:
55 labour+ glassmaking:
56 labour+ strand_extraction:
57 labour+ siege_engineering:
58 labour+ siege_operating:
59 labour+ crossbow_making:
60 labour+ mechanics:
61 labour+ potash_making:
62 labour+ lye_making:
63 labour+ dyeing:
64 labour+ wood_burning:
65 labour+ pump_operating:
(+ 0 write1)off;
(+ 1 write1)on;
(n. + n write2)set;
(df count (1- i. df i idx l. l nick n. n strlen (l n readstl : )()? i)@)getnicks;
(df count (1- i. df i idx l. l nick n. n strlen (n readstl #)()? i)@)shownicks;
4. run ds.exe
5. type
getnicks to read the nicks off your dwarves, note, you should set a nick on your dwarves or it can't handle them. Unless you make a script for that of course.
6. start using the various functions provided in the script, or just play around with the functions specified in the language reference. Available functions:
labours dwarf labour ondwarf labour offattributesdwarf attribute value settraitsdwarf trait value setskillsdwarf skillname readskilldwarf skillname skilllevel experience writeskill7. when you're done, you type
quitYou can also edit main.ds and add say
labour 2+ whaul: (I am just guessing that wood hauling is the next. If it isn't, you can just change the name. I will have to write a reference on how exactly the script works. Its basically a reverse polish (postfix) notated language with a few other features I will have to explain.
Btw, I couldn't have done this without
peterix and
chmod whose code and memory offsets I've been studying, so special thanks goes to you guys.
Upcoming features for next version: more string related functions, sets and set manipulation, duplication visible in the debug print, and the ability to call functions defined within the same string being evaluated, thus also calling functions outside functions directly in main.ds such as getnicks. [/u]