|
|
@ -372,7 +372,7 @@ static command_result do_command(color_ostream &out, vector<string> ¶meters)
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
static string getBucket(const df::job_item & ji, const PlannedBuilding & pb, int idx) {
|
|
|
|
static string getBucket(const df::job_item & ji, const PlannedBuilding & pb, int idx) {
|
|
|
|
if (idx < 0 || (size_t)idx < pb.item_filters.size())
|
|
|
|
if (idx < 0 || (size_t)idx >= pb.item_filters.size())
|
|
|
|
return "INVALID";
|
|
|
|
return "INVALID";
|
|
|
|
|
|
|
|
|
|
|
|
std::ostringstream ser;
|
|
|
|
std::ostringstream ser;
|
|
|
@ -428,7 +428,7 @@ vector<df::job_item_vector_id> getVectorIds(color_ostream &out, const df::job_it
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if the filer is for building material, refer to our global settings for
|
|
|
|
// if the filter is for building material, refer to our global settings for
|
|
|
|
// which vectors to search
|
|
|
|
// which vectors to search
|
|
|
|
if (job_item->flags2.bits.building_material)
|
|
|
|
if (job_item->flags2.bits.building_material)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -465,10 +465,11 @@ static bool registerPlannedBuilding(color_ostream &out, PlannedBuilding & pb) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int num_job_items = job_items.size();
|
|
|
|
int num_job_items = (int)job_items.size();
|
|
|
|
int32_t id = bld->id;
|
|
|
|
int32_t id = bld->id;
|
|
|
|
for (int job_item_idx = 0; job_item_idx < num_job_items; ++job_item_idx) {
|
|
|
|
for (int job_item_idx = 0; job_item_idx < num_job_items; ++job_item_idx) {
|
|
|
|
auto job_item = job_items[job_item_idx];
|
|
|
|
int rev_jitem_index = num_job_items - (job_item_idx+1);
|
|
|
|
|
|
|
|
auto job_item = job_items[rev_jitem_index];
|
|
|
|
auto bucket = getBucket(*job_item, pb, job_item_idx);
|
|
|
|
auto bucket = getBucket(*job_item, pb, job_item_idx);
|
|
|
|
|
|
|
|
|
|
|
|
// if there are multiple vector_ids, schedule duplicate tasks. after
|
|
|
|
// if there are multiple vector_ids, schedule duplicate tasks. after
|
|
|
@ -476,11 +477,11 @@ static bool registerPlannedBuilding(color_ostream &out, PlannedBuilding & pb) {
|
|
|
|
// as invalid
|
|
|
|
// as invalid
|
|
|
|
for (auto vector_id : pb.vector_ids[job_item_idx]) {
|
|
|
|
for (auto vector_id : pb.vector_ids[job_item_idx]) {
|
|
|
|
for (int item_num = 0; item_num < job_item->quantity; ++item_num) {
|
|
|
|
for (int item_num = 0; item_num < job_item->quantity; ++item_num) {
|
|
|
|
tasks[vector_id][bucket].emplace_back(id, job_item_idx);
|
|
|
|
tasks[vector_id][bucket].emplace_back(id, rev_jitem_index);
|
|
|
|
DEBUG(status,out).print("added task: %s/%s/%d,%d; "
|
|
|
|
DEBUG(status,out).print("added task: %s/%s/%d,%d; "
|
|
|
|
"%zu vector(s), %zu filter bucket(s), %zu task(s) in bucket",
|
|
|
|
"%zu vector(s), %zu filter bucket(s), %zu task(s) in bucket",
|
|
|
|
ENUM_KEY_STR(job_item_vector_id, vector_id).c_str(),
|
|
|
|
ENUM_KEY_STR(job_item_vector_id, vector_id).c_str(),
|
|
|
|
bucket.c_str(), id, job_item_idx, tasks.size(),
|
|
|
|
bucket.c_str(), id, rev_jitem_index, tasks.size(),
|
|
|
|
tasks[vector_id].size(), tasks[vector_id][bucket].size());
|
|
|
|
tasks[vector_id].size(), tasks[vector_id][bucket].size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -531,17 +532,19 @@ static void printStatus(color_ostream &out) {
|
|
|
|
if (!bld || bld->jobs.size() != 1)
|
|
|
|
if (!bld || bld->jobs.size() != 1)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
auto &job_items = bld->jobs[0]->job_items;
|
|
|
|
auto &job_items = bld->jobs[0]->job_items;
|
|
|
|
if (job_items.size() != pb.vector_ids.size())
|
|
|
|
const size_t num_job_items = job_items.size();
|
|
|
|
|
|
|
|
if (num_job_items != pb.vector_ids.size())
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
++bld_count;
|
|
|
|
++bld_count;
|
|
|
|
int job_item_idx = 0;
|
|
|
|
int job_item_idx = 0;
|
|
|
|
for (auto &vec_ids : pb.vector_ids) {
|
|
|
|
for (auto &vec_ids : pb.vector_ids) {
|
|
|
|
auto &jitem = job_items[job_item_idx++];
|
|
|
|
auto &jitem = job_items[num_job_items - (job_item_idx+1)];
|
|
|
|
int32_t quantity = jitem->quantity;
|
|
|
|
int32_t quantity = jitem->quantity;
|
|
|
|
if (quantity) {
|
|
|
|
if (quantity) {
|
|
|
|
counts[get_desc_string(out, jitem, vec_ids)] += quantity;
|
|
|
|
counts[get_desc_string(out, jitem, vec_ids)] += quantity;
|
|
|
|
total += quantity;
|
|
|
|
total += quantity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++job_item_idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -692,11 +695,9 @@ static bool hasFilter(color_ostream &out, df::building_type type, int16_t subtyp
|
|
|
|
TRACE(status,out).print("entering hasFilter\n");
|
|
|
|
TRACE(status,out).print("entering hasFilter\n");
|
|
|
|
BuildingTypeKey key(type, subtype, custom);
|
|
|
|
BuildingTypeKey key(type, subtype, custom);
|
|
|
|
auto &filters = get_item_filters(out, key);
|
|
|
|
auto &filters = get_item_filters(out, key);
|
|
|
|
for (auto &filter : filters.getItemFilters()) {
|
|
|
|
if (index < 0 || filters.getItemFilters().size() <= (size_t)index)
|
|
|
|
if (!filter.isEmpty())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
return !filters.getItemFilters()[index].isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void clearFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {
|
|
|
|
static void clearFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {
|
|
|
@ -972,10 +973,13 @@ static bool validate_pb(color_ostream &out, df::building *bld, int index) {
|
|
|
|
static string getDescString(color_ostream &out, df::building *bld, int index) {
|
|
|
|
static string getDescString(color_ostream &out, df::building *bld, int index) {
|
|
|
|
DEBUG(status,out).print("entering getDescString\n");
|
|
|
|
DEBUG(status,out).print("entering getDescString\n");
|
|
|
|
if (!validate_pb(out, bld, index))
|
|
|
|
if (!validate_pb(out, bld, index))
|
|
|
|
return 0;
|
|
|
|
return "INVALID";
|
|
|
|
|
|
|
|
|
|
|
|
PlannedBuilding &pb = planned_buildings.at(bld->id);
|
|
|
|
PlannedBuilding &pb = planned_buildings.at(bld->id);
|
|
|
|
auto &jitem = bld->jobs[0]->job_items[index];
|
|
|
|
auto & jitems = bld->jobs[0]->job_items;
|
|
|
|
|
|
|
|
const size_t num_job_items = jitems.size();
|
|
|
|
|
|
|
|
int rev_index = num_job_items - (index + 1);
|
|
|
|
|
|
|
|
auto &jitem = jitems[rev_index];
|
|
|
|
return int_to_string(jitem->quantity) + " " + get_desc_string(out, jitem, pb.vector_ids[index]);
|
|
|
|
return int_to_string(jitem->quantity) + " " + get_desc_string(out, jitem, pb.vector_ids[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -985,7 +989,10 @@ static int getQueuePosition(color_ostream &out, df::building *bld, int index) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
PlannedBuilding &pb = planned_buildings.at(bld->id);
|
|
|
|
PlannedBuilding &pb = planned_buildings.at(bld->id);
|
|
|
|
auto &job_item = bld->jobs[0]->job_items[index];
|
|
|
|
auto & jitems = bld->jobs[0]->job_items;
|
|
|
|
|
|
|
|
const size_t num_job_items = jitems.size();
|
|
|
|
|
|
|
|
int rev_index = num_job_items - (index + 1);
|
|
|
|
|
|
|
|
auto &job_item = jitems[rev_index];
|
|
|
|
|
|
|
|
|
|
|
|
if (job_item->quantity <= 0)
|
|
|
|
if (job_item->quantity <= 0)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -1001,7 +1008,7 @@ static int getQueuePosition(color_ostream &out, df::building *bld, int index) {
|
|
|
|
int bucket_pos = -1;
|
|
|
|
int bucket_pos = -1;
|
|
|
|
for (auto &task : buckets.at(bucket_id)) {
|
|
|
|
for (auto &task : buckets.at(bucket_id)) {
|
|
|
|
++bucket_pos;
|
|
|
|
++bucket_pos;
|
|
|
|
if (bld->id == task.first && index == task.second)
|
|
|
|
if (bld->id == task.first && rev_index == task.second)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bucket_pos++ >= 0)
|
|
|
|
if (bucket_pos++ >= 0)
|
|
|
@ -1018,18 +1025,20 @@ static void makeTopPriority(color_ostream &out, df::building *bld) {
|
|
|
|
|
|
|
|
|
|
|
|
PlannedBuilding &pb = planned_buildings.at(bld->id);
|
|
|
|
PlannedBuilding &pb = planned_buildings.at(bld->id);
|
|
|
|
auto &job_items = bld->jobs[0]->job_items;
|
|
|
|
auto &job_items = bld->jobs[0]->job_items;
|
|
|
|
|
|
|
|
const int num_job_items = (int)job_items.size();
|
|
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < (int)job_items.size(); ++index) {
|
|
|
|
for (int index = 0; index < num_job_items; ++index) {
|
|
|
|
|
|
|
|
int rev_index = num_job_items - (index + 1);
|
|
|
|
for (auto &vec_id : pb.vector_ids[index]) {
|
|
|
|
for (auto &vec_id : pb.vector_ids[index]) {
|
|
|
|
if (!tasks.count(vec_id))
|
|
|
|
if (!tasks.count(vec_id))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
auto &buckets = tasks.at(vec_id);
|
|
|
|
auto &buckets = tasks.at(vec_id);
|
|
|
|
string bucket_id = getBucket(*job_items[index], pb, index);
|
|
|
|
string bucket_id = getBucket(*job_items[rev_index], pb, index);
|
|
|
|
if (!buckets.count(bucket_id))
|
|
|
|
if (!buckets.count(bucket_id))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
auto &bucket = buckets.at(bucket_id);
|
|
|
|
auto &bucket = buckets.at(bucket_id);
|
|
|
|
for (auto taskit = bucket.begin(); taskit != bucket.end(); ++taskit) {
|
|
|
|
for (auto taskit = bucket.begin(); taskit != bucket.end(); ++taskit) {
|
|
|
|
if (bld->id == taskit->first && index == taskit->second) {
|
|
|
|
if (bld->id == taskit->first && rev_index == taskit->second) {
|
|
|
|
auto task_bld_id = taskit->first;
|
|
|
|
auto task_bld_id = taskit->first;
|
|
|
|
auto task_job_item_idx = taskit->second;
|
|
|
|
auto task_job_item_idx = taskit->second;
|
|
|
|
bucket.erase(taskit);
|
|
|
|
bucket.erase(taskit);
|
|
|
|