(I realize this is an old thread, but it's connected to a popular item on the Eternal Suggestions, so I'm refreshing it
I am assuming based on what I remember of discussions elsewhere that the job code at the moment works something like:
* Periodically check the jobs list
* For each job, check if there is a suitable dwarf available.
* If so, assign job to dwarf
So what it seems like is how can we structure the quoted AI behavior, so that the player specifies their preference per dwarf and/or globally.
First up, there already must exist a list of dwarves, in order for the job engine to search for a suitable dwarf. It could be as simple as the list of all player dwarves, and will probably contain about 7~200 entries -- a tiny search space. By tiny, I mean that there is no significant speed gain from implementing an O(log N) type search, instead of a simple O(N) scan. Overhead consumes the difference.
Second, the list very likely has the property of ranking the dwarves. First dwarf looked at, second dwarf, last dwarf. And ranking the dwarves is what we really want to do, yeah? So all that is required is to gather the dwarves into a list, and then sort that list on some property (we'll get to that in a minute), so that a dwarf is favored to do a job by being at the top of the list, or is unlikely to be selected because other eligible dwarves are above on the list.
For a given dwarf there are many jobs he can do (sorted in order of player preference), and for a given job there are many dwarves that can do it. In database terminology this is called a Many-To-Many relationship.
When a given job goes searching for a dwarf, it finds a dwarf and looks at that dwarf's priorities (or the global one if the dwarf doesn't have a specific set). The job finds itself named on the dwarf's job list or skips the dwarf. the
Rank is how far down the dwarf's priority list that job is located.
The job that is looking for a worker makes a temporary table, listing each dwarf and the priority rank the dwarf gave that job (1st position, 2nd choice, 3rd in list, and so on). Then sort the temporary table on rankings, and pick the dwarf who gave that job the highest priority (lowest number).
The temporary tables would only need to be updated when there is a change in dwarves and/or their priorities.
-Cheers,
AngleWyrm