autogems: avoid crash with non-workshop links, add some logging

Also update changelog, including revflood change

Fixes #1303
develop
lethosor 2018-06-12 12:16:01 -04:00
parent 8717144f14
commit 40d0d946a4
2 changed files with 17 additions and 9 deletions

@ -41,9 +41,12 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- Fixed ``-g`` flag (GDB) in Linux ``dfhack`` script (particularly on x64) - Fixed ``-g`` flag (GDB) in Linux ``dfhack`` script (particularly on x64)
- `autochop`, `autodump`, `autogems`, `automelt`, `autotrade`, `buildingplan`, `dwarfmonitor`, `fix-unit-occupancy`, `fortplan`, `stockflow`: fix issues with periodic tasks not working for some time after save/load cycles - `autochop`, `autodump`, `autogems`, `automelt`, `autotrade`, `buildingplan`, `dwarfmonitor`, `fix-unit-occupancy`, `fortplan`, `stockflow`: fix issues with periodic tasks not working for some time after save/load cycles
- `buildingplan`, `fortplan`: stop running before a world has fully loaded - `buildingplan`, `fortplan`: stop running before a world has fully loaded
- `autogems`: stop running repeatedly when paused - `autogems`:
- stop running repeatedly when paused
- fixed crash when furnaces are linked to same stockpiles as jeweler's workshops
- `ban-cooking`: fixed errors introduced by kitchen structure changes in 0.44.10-r1 - `ban-cooking`: fixed errors introduced by kitchen structure changes in 0.44.10-r1
- `remove-stress`: fixed an error when running on soul-less units (e.g. with ``-all``) - `remove-stress`: fixed an error when running on soul-less units (e.g. with ``-all``)
- `revflood`: stopped revealing tiles adjacent to tiles above open space inappropriately
## Misc Improvements ## Misc Improvements
- Added script name to messages produced by ``qerror()`` in Lua scripts - Added script name to messages produced by ``qerror()`` in Lua scripts

@ -136,10 +136,13 @@ void create_jobs() {
std::set<item_id> stockpiled; std::set<item_id> stockpiled;
std::set<df::building_workshopst*> unlinked; std::set<df::building_workshopst*> unlinked;
gem_map available; gem_map available;
auto workshops = &world->buildings.other[df::buildings_other_id::WORKSHOP_JEWELER];
for (auto w = workshops->begin(); w != workshops->end(); ++w) { for (df::building *building : world->buildings.other[df::buildings_other_id::WORKSHOP_JEWELER]) {
auto workshop = virtual_cast<df::building_workshopst>(*w); auto workshop = virtual_cast<df::building_workshopst>(building);
if (!workshop) {
Core::printerr("autogems: invalid building %i (not a workshop)\n", building->id);
continue;
}
auto links = workshop->profile.links.take_from_pile; auto links = workshop->profile.links.take_from_pile;
if (workshop->construction_stage < 3) { if (workshop->construction_stage < 3) {
@ -167,11 +170,13 @@ void create_jobs() {
} }
// Decrement current jobs from all linked workshops, not just this one. // Decrement current jobs from all linked workshops, not just this one.
auto outbound = stockpile->links.give_to_workshop; for (auto bld : stockpile->links.give_to_workshop) {
for (auto ws = outbound.begin(); ws != outbound.end(); ++ws) { auto shop = virtual_cast<df::building_workshopst>(bld);
auto shop = virtual_cast<df::building_workshopst>(*ws); if (!shop) {
for (auto j = shop->jobs.begin(); j != shop->jobs.end(); ++j) { // e.g. furnace
auto job = *j; continue;
}
for (auto job : shop->jobs) {
if (job->job_type == df::job_type::CutGems) { if (job->job_type == df::job_type::CutGems) {
if (job->flags.bits.repeat) { if (job->flags.bits.repeat) {
piled[job->mat_index] = 0; piled[job->mat_index] = 0;