|
|
@ -434,9 +434,6 @@ static void manageJobCompletedEvent(color_ostream& out) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
static int32_t last_tick = -1;
|
|
|
|
static int32_t last_tick = -1;
|
|
|
|
int32_t tick = df::global::world->frame_counter;
|
|
|
|
int32_t tick = df::global::world->frame_counter;
|
|
|
|
if(tick < last_tick){
|
|
|
|
|
|
|
|
last_tick = tick;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
multimap<Plugin*,EventHandler> copy(handlers[EventType::JOB_COMPLETED].begin(), handlers[EventType::JOB_COMPLETED].end());
|
|
|
|
multimap<Plugin*,EventHandler> copy(handlers[EventType::JOB_COMPLETED].begin(), handlers[EventType::JOB_COMPLETED].end());
|
|
|
|
map<int32_t, df::job*> nowJobs;
|
|
|
|
map<int32_t, df::job*> nowJobs;
|
|
|
@ -508,21 +505,20 @@ static void manageJobCompletedEvent(color_ostream& out) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if it happened within a tick, must have been cancelled by the user or a plugin: not completed
|
|
|
|
|
|
|
|
if (last_tick < tick ) {
|
|
|
|
|
|
|
|
last_tick = tick;
|
|
|
|
for (auto &iter : copy) {
|
|
|
|
for (auto &iter : copy) {
|
|
|
|
auto &handler = iter.second;
|
|
|
|
auto &handler = iter.second;
|
|
|
|
if (tick - eventLastTick[handler.eventHandler] >= handler.freq) {
|
|
|
|
if (tick - eventLastTick[handler.eventHandler] >= handler.freq) {
|
|
|
|
eventLastTick[handler.eventHandler] = tick;
|
|
|
|
eventLastTick[handler.eventHandler] = tick;
|
|
|
|
for ( auto i = prevJobs.begin(); i != prevJobs.end(); i++ ) {
|
|
|
|
for (auto job_iter = prevJobs.begin(); job_iter != prevJobs.end(); ++job_iter) {
|
|
|
|
//if it happened within a tick, must have been cancelled by the user or a plugin: not completed
|
|
|
|
if (nowJobs.find((*job_iter).first) != nowJobs.end()) {
|
|
|
|
if (tick <= last_tick )
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( nowJobs.find((*i).first) != nowJobs.end() ) {
|
|
|
|
|
|
|
|
//could have just finished if it's a repeat job
|
|
|
|
//could have just finished if it's a repeat job
|
|
|
|
df::job& job0 = *(*i).second;
|
|
|
|
df::job &job0 = *(*job_iter).second;
|
|
|
|
if (!job0.flags.bits.repeat)
|
|
|
|
if (!job0.flags.bits.repeat)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
df::job& job1 = *nowJobs[(*i).first];
|
|
|
|
df::job &job1 = *nowJobs[(*job_iter).first];
|
|
|
|
if (job0.completion_timer != 0)
|
|
|
|
if (job0.completion_timer != 0)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
if (job1.completion_timer != -1)
|
|
|
|
if (job1.completion_timer != -1)
|
|
|
@ -534,32 +530,31 @@ static void manageJobCompletedEvent(color_ostream& out) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//recently finished or cancelled job
|
|
|
|
//recently finished or cancelled job
|
|
|
|
df::job& job0 = *(*i).second;
|
|
|
|
df::job &job0 = *(*job_iter).second;
|
|
|
|
if (job0.flags.bits.repeat || job0.completion_timer != 0)
|
|
|
|
if (job0.flags.bits.repeat || job0.completion_timer != 0)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
handler.eventHandler(out, (void*) &job0);
|
|
|
|
handler.eventHandler(out, (void*) &job0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//erase old jobs, copy over possibly altered jobs
|
|
|
|
//erase old jobs, copy over possibly altered jobs
|
|
|
|
for ( auto i = prevJobs.begin(); i != prevJobs.end(); i++ ) {
|
|
|
|
for (auto job_iter = prevJobs.begin(); job_iter != prevJobs.end(); ++job_iter ) {
|
|
|
|
Job::deleteJobStruct((*i).second, true);
|
|
|
|
Job::deleteJobStruct((*job_iter).second, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prevJobs.clear();
|
|
|
|
prevJobs.clear();
|
|
|
|
|
|
|
|
|
|
|
|
//create new jobs
|
|
|
|
//create new jobs
|
|
|
|
for ( auto j = nowJobs.begin(); j != nowJobs.end(); j++ ) {
|
|
|
|
for (auto job_iter = nowJobs.begin(); job_iter != nowJobs.end(); ++job_iter ) {
|
|
|
|
/*map<int32_t, df::job*>::iterator i = prevJobs.find((*j).first);
|
|
|
|
/*map<int32_t, df::job*>::iterator i = prevJobs.find((*job_iter).first);
|
|
|
|
if ( i != prevJobs.end() ) {
|
|
|
|
if ( i != prevJobs.end() ) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
df::job* newJob = Job::cloneJobStruct((*j).second, true);
|
|
|
|
df::job* newJob = Job::cloneJobStruct((*job_iter).second, true);
|
|
|
|
prevJobs[newJob->id] = newJob;
|
|
|
|
prevJobs[newJob->id] = newJob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last_tick = tick;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void manageUnitDeathEvent(color_ostream& out) {
|
|
|
|
static void manageUnitDeathEvent(color_ostream& out) {
|
|
|
@ -657,21 +652,21 @@ static void manageBuildingEvent(color_ostream& out) {
|
|
|
|
handler.eventHandler(out, (void*)intptr_t(a));
|
|
|
|
handler.eventHandler(out, (void*)intptr_t(a));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nextBuilding = *df::global::building_next_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//now alert people about destroyed buildings
|
|
|
|
//now alert people about destroyed buildings
|
|
|
|
for ( auto a = buildings.begin(); a != buildings.end(); ) {
|
|
|
|
for (auto building_iter = buildings.begin(); building_iter != buildings.end(); ) {
|
|
|
|
int32_t id = *a;
|
|
|
|
int32_t id = *building_iter;
|
|
|
|
int32_t index = df::building::binsearch_index(df::global::world->buildings.all,id);
|
|
|
|
int32_t index = df::building::binsearch_index(df::global::world->buildings.all,id);
|
|
|
|
if ( index != -1 ) {
|
|
|
|
if ( index != -1 ) {
|
|
|
|
a++;
|
|
|
|
++building_iter;
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handler.eventHandler(out, (void*)intptr_t(id));
|
|
|
|
handler.eventHandler(out, (void*)intptr_t(id));
|
|
|
|
a = buildings.erase(a);
|
|
|
|
building_iter = buildings.erase(building_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nextBuilding = *df::global::building_next_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void manageConstructionEvent(color_ostream& out) {
|
|
|
|
static void manageConstructionEvent(color_ostream& out) {
|
|
|
@ -685,24 +680,22 @@ static void manageConstructionEvent(color_ostream& out) {
|
|
|
|
auto &handler = iter.second;
|
|
|
|
auto &handler = iter.second;
|
|
|
|
if (tick - eventLastTick[handler.eventHandler] >= handler.freq) {
|
|
|
|
if (tick - eventLastTick[handler.eventHandler] >= handler.freq) {
|
|
|
|
eventLastTick[handler.eventHandler] = tick;
|
|
|
|
eventLastTick[handler.eventHandler] = tick;
|
|
|
|
for ( auto a = constructions.begin(); a != constructions.end(); ) {
|
|
|
|
for (auto constru_iter = constructions.begin(); constru_iter != constructions.end();) {
|
|
|
|
df::construction& construction = (*a).second;
|
|
|
|
df::construction &construction = (*constru_iter).second;
|
|
|
|
if (df::construction::find(construction.pos) != NULL) {
|
|
|
|
if (df::construction::find(construction.pos) != NULL) {
|
|
|
|
a++;
|
|
|
|
++constru_iter;
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//construction removed
|
|
|
|
//construction removed
|
|
|
|
//out.print("Removed construction (%d,%d,%d)\n", construction.pos.x,construction.pos.y,construction.pos.z);
|
|
|
|
//out.print("Removed construction (%d,%d,%d)\n", construction.pos.x,construction.pos.y,construction.pos.z);
|
|
|
|
handler.eventHandler(out, (void*) &construction);
|
|
|
|
handler.eventHandler(out, (void*) &construction);
|
|
|
|
a = constructions.erase(a);
|
|
|
|
constru_iter = constructions.erase(constru_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//for ( auto a = constructionsNow.begin(); a != constructionsNow.end(); a++ ) {
|
|
|
|
//for ( auto a = constructionsNow.begin(); a != constructionsNow.end(); ++a ) {
|
|
|
|
for ( auto a = df::global::world->constructions.begin(); a != df::global::world->constructions.end(); a++ ) {
|
|
|
|
for (auto constru_iter = df::global::world->constructions.begin(); constru_iter != df::global::world->constructions.end(); ++constru_iter) {
|
|
|
|
df::construction* construction = *a;
|
|
|
|
df::construction* construction = *constru_iter;
|
|
|
|
bool b = constructions.find(construction->pos) != constructions.end();
|
|
|
|
if (!constructions.emplace(construction->pos, *construction).second)
|
|
|
|
constructions[construction->pos] = *construction;
|
|
|
|
continue; //not a new insertion, skip
|
|
|
|
if ( b )
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//construction created
|
|
|
|
//construction created
|
|
|
|
//out.print("Created construction (%d,%d,%d)\n", construction->pos.x,construction->pos.y,construction->pos.z);
|
|
|
|
//out.print("Created construction (%d,%d,%d)\n", construction->pos.x,construction->pos.y,construction->pos.z);
|
|
|
|
handler.eventHandler(out, (void*) construction);
|
|
|
|
handler.eventHandler(out, (void*) construction);
|
|
|
|