· 9 years ago · Feb 02, 2017, 06:58 AM
1rimworld defines <workType> field to contain the following (in 15a? or 14a....) ;
2
3 [Flags]
4 public enum WorkTags
5 {
6 None = 0,
7 Intellectual = 2,
8 ManualDumb = 4,
9 ManualSkilled = 8,
10 Violent = 16,
11 Caring = 32,
12 Social = 64,
13 Scary = 128,
14 Animals = 256,
15 Artistic = 512,
16 Crafting = 1024,
17 Cooking = 2048,
18 Firefighting = 4096,
19 Cleaning = 8192,
20 Hauling = 16384,
21 PlantWork = 32768,
22 Mining = 65536
23 }
24
25more may have been added since then as these are a bit out dated, like adding drug-making for example.
26
27to add functionality to a robot, the <workTag> field contains a number composed of one or more of the numbers listed above added together.
28
29For example, let's say I want a robot that can mine rock, and can commit violence. The list above provides the numbers we'll need. 8 for manual skilled labor (mining needs that apparently), 16 to set "is capable of violence", and 65536 for mining itself. Now that we know that we can add them all together (8 + 16 + 65,536 = 65,560) and that result will become our new worktag as defined in the xml as
30
31<workTag>65560</workTag>
32
33
34it may also be needed to change the <workTypeDefs> field depending on what you want the bot to be allowed to do...
35But I forget where the workTypeDefs are defined! You should probably look in "./mods/core/" and look at random pawn definitions to see what worktypedefs are used by the default game.
36
37
38---------
39
40now for patrol routes... unless something already exists; you'll likely need to use a lot of C# code. You'd need to choose how to define where the points are that you would like them to patrol, and then manipulate the ai path finding stuff to send them on their way... This is much more complicated. I'd strongly suggest trying to find something that acts similar to what you want and see how it works; or you'll likely just need to suggest it on the forums and hope someone who writes a lot of C# mods fullfills your request.
41
42==========
43==TRIVIA== incase you wanted to learn something else that's actually useful:
44==========
45
46<workTags>'s numbers are not random. They are powers of 2 for a reason. They are binary "flags" that control state for the robots (or any pawn in rimworld)
47
48Decimal is likely the numbering system you're familiar with.
49Decimal is base 10, using the numbers 0,1,2,3,4,5,6,7,8, and 9, and will be represented by a lower-case "d" (example 5d)
50Binary is base 2, using the numbers 0 and 1, and will be represented by a lower-case "b" (example: 0101b)
51
52In Decimal, when you reach the end of the amount of numbers you have (start at 0 count to 9) you run out of symbols to represent the value you're trying to express. To solve this, we use "columbs". the number 10 says that there is 1 in the "tens" columb, and 0 in the "ones" columb. As such, we have one "tens" and zero "ones" for a total of... well, ten. Now 11 is one "tens" and one "ones"... now you can see how this continues (99 + 1 = 100 ... 999 + 1 = 1000 ... 9999 + 1 = 10000 ...) Note that each columb is a power of 10.
53
54The same concept exists in binary, and each columb is a power of 2 as you can only cound using 0 and 1. Once the "ones" columb fills up and we run out of symbols to represent the value we wish to express, (0 + 1 = 1) If we add another 1, we need to create a new columb to represent the new number ( 1 + 1 = 10 ) as now we have 1 in the "twos" columb, and 0 in the "ones" columb. Add another ( 10 + 1 = 11), and now we have one in the twos, and 1 in the ones, for a total of three. Add another (11 + 1 = 100) as now we have one in the "fours" columb, zero in the "twos" and zero in the "ones"...
55
56So a little conversion table to help you get the pattern. Please note; the total number of things is the same. These are merely just ways of displaying the same information in different systems. A binary ten is equal to a decimal ten...
57
58bINARY = dECIMAL
59/-------------\
60|0001b = 0001d|
61|0010b = 0002d|
62|0011b = 0003d|
63|0100b = 0004d|
64|0101b = 0005d|
65|0110b = 0006d|
66|0111b = 0007d|
67|1000b = 0008d|
68|1001b = 0009d|
69|1010b = 0010d|
70|.............|
71|1111b = 0015d|
72\-------------/
73
74The numbers for the workTag field are powers of two, and as such they corrispond to a columb.
75
76for example, the senario I gave for explaining the WorkTag field, I gave a tag to enable skilled manual labor, violence, and mining
77
78now we can see how this works under the hood of the game!!
79
8010000000000000000b = mining ( 65536d )
8100000000000010000b = violent ( 16d )
8200000000000001000b = skilled ( 8d )
83
84add them all together into one number and you get 65560d which when displayed in binary is 10000000000011000b
85
86In binary logic, "0" is false, "1" is true. So when the program looks at our decimal number in binary (how it's stored on the machine), it can tell that the first 'bit' is true, and that means mining is enabled. A bunch of bits are false, so it won't allow those things, and then the 16th columb, and 8th columb, are both true as well, so it will enable violence and skilled labor.
87
88This allows a bunch of "boolean" (true/false) flags to be compact and fit in a single integer number taking up very little space.
89
90--------------- DOUBLE EXTRA TRIVIA!!
91
92Want to learn a cool consiquence of binary? "bit-shifting"!
93bit shifting in C is a low-level operation that takes all the bits, and moves them left or right.
94
95The syntax is "(data to be manipulated) (operator) (amount)"
96Operators are << for bitshift left and >> for bitshift right.
97
98example 1 : 0001 << 2 results in the output being 0100
99example 2 : 1010 >> 1 results in 0101
100example 3 : 1011 >> 1 results in 0101
101
102By moving the bits, you change which columb the "1" is in, as such, 0010b (aka 2d) bitshift << by 1 is 0100b (aka 4d), and then 0100b bitshift >> by 2 is 0001b (aka 1d)
103
104bitshift "amount" is the same as multiplying or dividing by 2 (amount) times.
105
106so 0100b (4d) bitshift >> by 1 is 0010b (2d) as such, the operation is equivilent in effect as ( 4/(2 * amount) )
107so 0100b (4d) bitshift << by 1 is 1000b (8d) as such, the operation is equivilent in effect as ( 4*(2 * amount) )
108
109cool, eh?
110
111like in decimal, if you took 10d, and moved everything to the left by 1 space, you move it up by a power of 10 ( 10d << 1d = 100d )
112but in binary, since its base 2, you move up and down by a power of 2 rather than decimal's power of 10.
113
114Random note; division on computers is hard... and very slow! (sometimes multiplication too but no where near as bad...) if you know your dividing by a power of two, it's faster to bitshift! (though people may yell at you for 'pre-mature micro-optimization'...)