2012-01-07 08:21:07 -07:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2012-01-07 08:21:07 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef CL_MOD_JOB
|
|
|
|
#define CL_MOD_JOB
|
|
|
|
|
|
|
|
#include "Export.h"
|
|
|
|
#include "Module.h"
|
2012-11-12 08:17:32 -07:00
|
|
|
#include "Types.h"
|
|
|
|
|
2012-01-07 08:21:07 -07:00
|
|
|
#include <ostream>
|
|
|
|
|
2012-04-29 11:07:39 -06:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/job_item_ref.h"
|
2012-10-17 09:16:18 -06:00
|
|
|
#include "df/item_type.h"
|
2012-04-29 11:07:39 -06:00
|
|
|
|
2012-01-07 08:21:07 -07:00
|
|
|
namespace df
|
|
|
|
{
|
|
|
|
struct job;
|
|
|
|
struct job_item;
|
|
|
|
struct job_item_filter;
|
2012-01-08 09:02:12 -07:00
|
|
|
struct building;
|
2012-04-10 01:43:36 -06:00
|
|
|
struct unit;
|
2012-01-07 08:21:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace DFHack
|
|
|
|
{
|
2012-04-10 01:43:36 -06:00
|
|
|
namespace Job {
|
|
|
|
// Duplicate the job structure. It is not linked into any DF lists.
|
2013-05-25 07:44:17 -06:00
|
|
|
DFHACK_EXPORT df::job *cloneJobStruct(df::job *job, bool keepEverything=false);
|
2012-01-07 08:21:07 -07:00
|
|
|
|
2012-04-10 01:43:36 -06:00
|
|
|
// Delete a cloned structure.
|
2013-05-25 07:44:17 -06:00
|
|
|
DFHACK_EXPORT void deleteJobStruct(df::job *job, bool keptEverything=false);
|
2012-01-07 08:21:07 -07:00
|
|
|
|
2012-04-10 01:43:36 -06:00
|
|
|
DFHACK_EXPORT void printItemDetails(color_ostream &out, df::job_item *item, int idx);
|
|
|
|
DFHACK_EXPORT void printJobDetails(color_ostream &out, df::job *job);
|
|
|
|
|
2012-11-12 08:17:32 -07:00
|
|
|
DFHACK_EXPORT df::general_ref *getGeneralRef(df::job *job, df::general_ref_type type);
|
|
|
|
DFHACK_EXPORT df::specific_ref *getSpecificRef(df::job *job, df::specific_ref_type type);
|
|
|
|
|
2012-04-10 01:43:36 -06:00
|
|
|
DFHACK_EXPORT df::building *getHolder(df::job *job);
|
|
|
|
DFHACK_EXPORT df::unit *getWorker(df::job *job);
|
2012-01-07 08:21:07 -07:00
|
|
|
|
2014-04-15 11:52:39 -06:00
|
|
|
DFHACK_EXPORT void setJobCooldown(df::building *workshop, df::unit *worker, int cooldown = 100);
|
|
|
|
DFHACK_EXPORT bool removeWorker(df::job *job, int cooldown = 100);
|
|
|
|
|
2016-11-24 23:36:11 -07:00
|
|
|
// This helpful method only removes the backref from the item to the job, but it doesn't
|
|
|
|
// remove the item ref from the job's vector, or delete it or anything. Think of it as a method
|
2016-11-25 01:25:18 -07:00
|
|
|
// that does all the needful to make an item ref ready to delete.
|
2016-12-01 21:13:49 -07:00
|
|
|
DFHACK_EXPORT void disconnectJobItem(df::job *job, df::job_item_ref *item);
|
2016-11-24 23:36:11 -07:00
|
|
|
// This helpful method only removes the backref from whatever the general_ref points to,
|
|
|
|
// it doesn't remove the general_ref from the job's vector, or delete it or anything.
|
2016-11-25 01:25:18 -07:00
|
|
|
// Think of it as a method that does all the needful to make a ref ready to delete.
|
2016-11-24 23:36:11 -07:00
|
|
|
// If it returns false, you've found a ref that the method doesn't know how to handle. Congratulations!
|
|
|
|
// You should report that and/or check in a fix.
|
2016-12-01 21:13:49 -07:00
|
|
|
DFHACK_EXPORT bool disconnectJobGeneralRef(df::job *job, df::general_ref *ref);
|
Add job remove method
Job remove eliminates a job's worker & holder references, if any, puts
the worker on cd, if appropriate, removes the job's postings, eliminates
the job from the global linked list, and then finally deletes it. This
code was tested by incorporating it into autochop and it does make the
plugin work. However, chop jobs don't have holder building references,
and anyway, with DF being 90% edge case by volume, this could use a heck
of a lot more testing.
I saw elsewhere code that prevented worker removal if the job was a
special job, and that made me feel funny so I made the job remove method
not work if the job is a special job.
2016-11-17 01:11:15 -07:00
|
|
|
// Delete a job & remove all refs from everywhere.
|
2016-11-25 01:25:18 -07:00
|
|
|
// This method DELETES the job object! Everything related to it will be wiped
|
Add job remove method
Job remove eliminates a job's worker & holder references, if any, puts
the worker on cd, if appropriate, removes the job's postings, eliminates
the job from the global linked list, and then finally deletes it. This
code was tested by incorporating it into autochop and it does make the
plugin work. However, chop jobs don't have holder building references,
and anyway, with DF being 90% edge case by volume, this could use a heck
of a lot more testing.
I saw elsewhere code that prevented worker removal if the job was a
special job, and that made me feel funny so I made the job remove method
not work if the job is a special job.
2016-11-17 01:11:15 -07:00
|
|
|
// clean from the earth, so make sure you pull what you need out before calling this!
|
2016-11-24 23:36:11 -07:00
|
|
|
DFHACK_EXPORT bool removeJob(df::job *job);
|
Add job remove method
Job remove eliminates a job's worker & holder references, if any, puts
the worker on cd, if appropriate, removes the job's postings, eliminates
the job from the global linked list, and then finally deletes it. This
code was tested by incorporating it into autochop and it does make the
plugin work. However, chop jobs don't have holder building references,
and anyway, with DF being 90% edge case by volume, this could use a heck
of a lot more testing.
I saw elsewhere code that prevented worker removal if the job was a
special job, and that made me feel funny so I made the job remove method
not work if the job is a special job.
2016-11-17 01:11:15 -07:00
|
|
|
|
2012-05-12 10:12:09 -06:00
|
|
|
// Instruct the game to check and assign workers
|
|
|
|
DFHACK_EXPORT void checkBuildingsNow();
|
|
|
|
DFHACK_EXPORT void checkDesignationsNow();
|
|
|
|
|
2012-04-10 01:43:36 -06:00
|
|
|
DFHACK_EXPORT bool linkIntoWorld(df::job *job, bool new_id = true);
|
2012-01-08 09:02:12 -07:00
|
|
|
|
2015-11-25 18:33:13 -07:00
|
|
|
// Flag this job's posting as "dead" and set its posting_index to -1
|
|
|
|
// If remove_all is true, flag all postings pointing to this job
|
|
|
|
// Returns true if any postings were removed
|
|
|
|
DFHACK_EXPORT bool removePostings(df::job *job, bool remove_all = false);
|
|
|
|
|
2012-04-10 01:43:36 -06:00
|
|
|
// lists jobs with ids >= *id_var, and sets *id_var = *job_next_id;
|
|
|
|
DFHACK_EXPORT bool listNewlyCreated(std::vector<df::job*> *pvec, int *id_var);
|
2012-04-29 11:07:39 -06:00
|
|
|
|
|
|
|
DFHACK_EXPORT bool attachJobItem(df::job *job, df::item *item,
|
|
|
|
df::job_item_ref::T_role role,
|
|
|
|
int filter_idx = -1, int insert_idx = -1);
|
2012-10-17 09:16:18 -06:00
|
|
|
|
|
|
|
DFHACK_EXPORT bool isSuitableItem(df::job_item *item, df::item_type itype, int isubtype);
|
|
|
|
DFHACK_EXPORT bool isSuitableMaterial(df::job_item *item, int mat_type, int mat_index);
|
2014-04-23 07:03:10 -06:00
|
|
|
DFHACK_EXPORT std::string getName(df::job *job);
|
2012-04-10 01:43:36 -06:00
|
|
|
}
|
2012-01-08 09:02:12 -07:00
|
|
|
|
2012-04-10 01:43:36 -06:00
|
|
|
DFHACK_EXPORT bool operator== (const df::job_item &a, const df::job_item &b);
|
|
|
|
DFHACK_EXPORT bool operator== (const df::job &a, const df::job &b);
|
2012-01-07 08:21:07 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|