-
Notifications
You must be signed in to change notification settings - Fork 493
helper functions for creating and assigning jobs #5535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Edit: I don't think I'd use the proposed job creation code. I want fine-grained control, and I want to add the job to the world as the last step, in case something goes wrong during my job creation. If I were ever to assign units to jobs, I would probably like to use this code in order to handle all cases, including cases I'm not aware exist. At a glance, I don't like the name Same for Or just fold these tests into I might like to have a Consider renaming |
Usually, I tend to check all the conditions that are necessary to create a job before attempting the creation. For tools that immediately attach workers, that includes looking whether there is an available worker. So it makes a lot of sense to keep the test separate from There isn't really much that can "go wrong" in setting job parameters and adding general references. In fact, if memory serves me right, DF links jobs into the world as part of the constructor. That is of course very restrictive because it doesn't allow you to store and pass around (unlinked) copies of jobs.
If the goal is to get work done, then the preferred way is probably you just post the job and let the game handle the rest. |
library/modules/Units.cpp
Outdated
| static const need_types_set pray_needs = need_types_set() | ||
| .set(df::need_type::PrayOrMeditate); | ||
|
|
||
| static const need_types_set socialize_needs = need_types_set() | ||
| .set(df::need_type::Socialize) | ||
| .set(df::need_type::BeCreative) | ||
| .set(df::need_type::Excitement) | ||
| .set(df::need_type::AdmireArt); | ||
|
|
||
| static const need_types_set read_needs = need_types_set() | ||
| .set(df::need_type::ThinkAbstractly) | ||
| .set(df::need_type::LearnSomething); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that these be constexpr but std::bitset's operators aren't constexpr until C++23, so I'm going to put this here as a vague reminder to reconsider if/when we move to C++23 compliance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I share your sentiment. This is why I left a comment a few lines above the lines you selected.
ab9rf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new methods need to be documented in docs/dev/Lua API.rst
Otherwise, looks good to me
"bailable" is literally Tarn's term for this: this function is a (fairly faithful) reimplementation of a function in Bay12 code called
This is correct. DF just doesn't have a concept of a job that isn't on the master job list. While it might be nice to have a job that isn't linked in some situations, this doesn't agree with how DF conceptualizes jobs. While I don't think the game will actively misoperate if a job that isn't linked gets referred to, I wouldn't count on this and it's generally best that we not blithely violate the assumptions of the core game engine without carefully considering what the consequence of such violations are. As such, I'm not in favor of having a utility function that creates jobs but doesn't link them, without a specific demonstration of a meritorious use case for such a utility function. If the only situation you can come up with is "something could go wrong during job construction", the solution to that is "verify that all of your preconditions are satisfied before you actually create the job". |
Presumably you mean that functions should be exported to lua and documented in Looking at the signatures, I think that everything other than the |
| auto pdata = Lua::make_lua_userdata<PerlinNoise3D<float>>(L); | ||
| pdata->init(*prng); | ||
| lua_pushcclosure(L, eval_perlin_3, 1); | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
above and beyond, well done
library/LuaApi.cpp
Outdated
| for (int i = 2; i <= top; ++i) { | ||
| try { | ||
| needs.set(luaL_checkint(L, i)); | ||
| } catch (const std::out_of_range &e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omit the e here, since you don't use it
I finally got around to following up on this discussion concerning
unitst::have_unbailable_sp_activitiesThe motivation for this is that we now have several tools that create jobs and immediately assign them to dwarves (
idle-crafting,autocheese,immortal-cravings). This has led to a bunch of code duplication and cross-importing between those tools. I would like to clean this up a bit by putting some of the frequently used functionality on a more solid footing and moving it into the C++ libraries.@ab9rf It would be nice if you could take a look at
unbailableSocialActivityand see if it needs any corrections or extensions for our purposes.