2012-03-16 22:45:52 -06:00
|
|
|
#include "Core.h"
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2012-09-13 13:42:17 -06:00
|
|
|
#include "modules/Units.h"
|
2012-04-05 00:33:26 -06:00
|
|
|
#include "modules/World.h"
|
|
|
|
|
2012-03-16 22:45:52 -06:00
|
|
|
// DF data structure definition headers
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include <df/ui.h>
|
|
|
|
#include <df/world.h>
|
|
|
|
#include <df/unit.h>
|
|
|
|
#include <df/unit_soul.h>
|
|
|
|
#include <df/unit_labor.h>
|
|
|
|
#include <df/unit_skill.h>
|
|
|
|
#include <df/job.h>
|
2012-03-22 01:33:18 -06:00
|
|
|
#include <df/building.h>
|
|
|
|
#include <df/workshop_type.h>
|
2012-03-16 22:45:52 -06:00
|
|
|
#include <df/unit_misc_trait.h>
|
2012-04-26 08:38:25 -06:00
|
|
|
#include <df/entity_position_responsibility.h>
|
|
|
|
#include <df/historical_figure.h>
|
|
|
|
#include <df/historical_entity.h>
|
|
|
|
#include <df/histfig_entity_link.h>
|
|
|
|
#include <df/histfig_entity_link_positionst.h>
|
|
|
|
#include <df/entity_position_assignment.h>
|
|
|
|
#include <df/entity_position.h>
|
2012-04-26 12:46:38 -06:00
|
|
|
#include <df/building_tradedepotst.h>
|
2012-07-22 11:16:50 -06:00
|
|
|
#include <df/building_stockpilest.h>
|
|
|
|
#include <df/items_other_id.h>
|
|
|
|
#include <df/ui.h>
|
|
|
|
#include <df/activity_info.h>
|
2012-04-26 08:38:25 -06:00
|
|
|
|
|
|
|
#include <MiscUtils.h>
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-22 11:16:50 -06:00
|
|
|
#include "modules/MapCache.h"
|
|
|
|
#include "modules/Items.h"
|
2015-01-28 14:26:17 -07:00
|
|
|
#include "modules/Units.h"
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-04-02 23:12:06 -06:00
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
2013-10-08 07:41:49 -06:00
|
|
|
using std::vector;
|
2012-03-16 22:45:52 -06:00
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
2014-12-02 19:44:20 -07:00
|
|
|
|
|
|
|
DFHACK_PLUGIN("autolabor");
|
|
|
|
REQUIRE_GLOBAL(ui);
|
|
|
|
REQUIRE_GLOBAL(world);
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-03-22 01:33:18 -06:00
|
|
|
#define ARRAY_COUNT(array) (sizeof(array)/sizeof((array)[0]))
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-04-04 00:26:15 -06:00
|
|
|
/*
|
|
|
|
* Autolabor module for dfhack
|
|
|
|
*
|
|
|
|
* The idea behind this module is to constantly adjust labors so that the right dwarves
|
|
|
|
* are assigned to new tasks. The key is that, for almost all labors, once a dwarf begins
|
|
|
|
* a job it will finish that job even if the associated labor is removed. Thus the
|
|
|
|
* strategy is to frequently decide, for each labor, which dwarves should possibly take
|
|
|
|
* a new job for that labor if it comes in and which shouldn't, and then set the labors
|
|
|
|
* appropriately. The updating should happen as often as can be reasonably done without
|
|
|
|
* causing lag.
|
|
|
|
*
|
|
|
|
* The obvious thing to do is to just set each labor on a single idle dwarf who is best
|
|
|
|
* suited to doing new jobs of that labor. This works in a way, but it leads to a lot
|
|
|
|
* of idle dwarves since only one dwarf will be dispatched for each labor in an update
|
|
|
|
* cycle, and dwarves that finish tasks will wait for the next update before being
|
|
|
|
* dispatched. An improvement is to also set some labors on dwarves that are currently
|
|
|
|
* doing a job, so that they will immediately take a new job when they finish. The
|
|
|
|
* details of which dwarves should have labors set is mostly a heuristic.
|
|
|
|
*
|
|
|
|
* A complication to the above simple scheme is labors that have associated equipment.
|
|
|
|
* Enabling/disabling these labors causes dwarves to change equipment, and disabling
|
|
|
|
* them in the middle of a job may cause the job to be abandoned. Those labors
|
|
|
|
* (mining, hunting, and woodcutting) need to be handled carefully to minimize churn.
|
|
|
|
*/
|
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFHACK_PLUGIN_IS_ENABLED(enable_autolabor);
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-04-02 21:55:02 -06:00
|
|
|
static bool print_debug = 0;
|
|
|
|
|
2012-04-02 23:12:06 -06:00
|
|
|
static std::vector<int> state_count(5);
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-04-05 00:33:26 -06:00
|
|
|
static PersistentDataItem config;
|
|
|
|
|
|
|
|
enum ConfigFlags {
|
|
|
|
CF_ENABLED = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-03-16 22:45:52 -06:00
|
|
|
// Here go all the command declarations...
|
|
|
|
// mostly to allow having the mandatory stuff on top of the file and commands on the bottom
|
|
|
|
command_result autolabor (color_ostream &out, std::vector <std::string> & parameters);
|
|
|
|
|
2012-08-02 19:28:29 -06:00
|
|
|
static void generate_labor_to_skill_map();
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-03-16 22:45:52 -06:00
|
|
|
enum labor_mode {
|
2012-07-17 09:27:30 -06:00
|
|
|
DISABLE,
|
|
|
|
HAULERS,
|
|
|
|
AUTOMATIC,
|
2012-03-16 22:45:52 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
enum dwarf_state {
|
2012-07-17 09:27:30 -06:00
|
|
|
// Ready for a new task
|
|
|
|
IDLE,
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Busy with a useful task
|
|
|
|
BUSY,
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2015-05-07 21:41:11 -06:00
|
|
|
// Busy with a useful task that requires a tool
|
|
|
|
EXCLUSIVE,
|
2015-05-07 19:08:02 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// In the military, can't work
|
|
|
|
MILITARY,
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Child or noble, can't work
|
|
|
|
CHILD,
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Doing something that precludes working, may be busy for a while
|
|
|
|
OTHER
|
2012-03-16 22:45:52 -06:00
|
|
|
};
|
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
const int NUM_STATE = 6;
|
2012-04-02 23:12:06 -06:00
|
|
|
|
2012-04-02 21:55:02 -06:00
|
|
|
static const char *state_names[] = {
|
2012-07-17 09:27:30 -06:00
|
|
|
"IDLE",
|
|
|
|
"BUSY",
|
2015-05-07 21:41:11 -06:00
|
|
|
"EXCLUSIVE",
|
2012-07-17 09:27:30 -06:00
|
|
|
"MILITARY",
|
|
|
|
"CHILD",
|
|
|
|
"OTHER",
|
2012-04-02 21:55:02 -06:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:45:52 -06:00
|
|
|
static const dwarf_state dwarf_states[] = {
|
2012-07-17 09:27:30 -06:00
|
|
|
BUSY /* CarveFortification */,
|
|
|
|
BUSY /* DetailWall */,
|
|
|
|
BUSY /* DetailFloor */,
|
2015-05-07 19:08:02 -06:00
|
|
|
EXCLUSIVE /* Dig */,
|
|
|
|
EXCLUSIVE /* CarveUpwardStaircase */,
|
|
|
|
EXCLUSIVE /* CarveDownwardStaircase */,
|
|
|
|
EXCLUSIVE /* CarveUpDownStaircase */,
|
|
|
|
EXCLUSIVE /* CarveRamp */,
|
|
|
|
EXCLUSIVE /* DigChannel */,
|
|
|
|
EXCLUSIVE /* FellTree */,
|
2012-07-17 09:27:30 -06:00
|
|
|
BUSY /* GatherPlants */,
|
|
|
|
BUSY /* RemoveConstruction */,
|
|
|
|
BUSY /* CollectWebs */,
|
|
|
|
BUSY /* BringItemToDepot */,
|
|
|
|
BUSY /* BringItemToShop */,
|
|
|
|
OTHER /* Eat */,
|
|
|
|
OTHER /* GetProvisions */,
|
|
|
|
OTHER /* Drink */,
|
|
|
|
OTHER /* Drink2 */,
|
|
|
|
OTHER /* FillWaterskin */,
|
|
|
|
OTHER /* FillWaterskin2 */,
|
|
|
|
OTHER /* Sleep */,
|
|
|
|
BUSY /* CollectSand */,
|
|
|
|
BUSY /* Fish */,
|
2015-05-07 19:08:02 -06:00
|
|
|
EXCLUSIVE /* Hunt */,
|
2012-07-17 09:27:30 -06:00
|
|
|
OTHER /* HuntVermin */,
|
|
|
|
BUSY /* Kidnap */,
|
|
|
|
BUSY /* BeatCriminal */,
|
|
|
|
BUSY /* StartingFistFight */,
|
|
|
|
BUSY /* CollectTaxes */,
|
|
|
|
BUSY /* GuardTaxCollector */,
|
|
|
|
BUSY /* CatchLiveLandAnimal */,
|
|
|
|
BUSY /* CatchLiveFish */,
|
|
|
|
BUSY /* ReturnKill */,
|
|
|
|
BUSY /* CheckChest */,
|
|
|
|
BUSY /* StoreOwnedItem */,
|
|
|
|
BUSY /* PlaceItemInTomb */,
|
|
|
|
BUSY /* StoreItemInStockpile */,
|
|
|
|
BUSY /* StoreItemInBag */,
|
|
|
|
BUSY /* StoreItemInHospital */,
|
|
|
|
BUSY /* StoreItemInChest */,
|
|
|
|
BUSY /* StoreItemInCabinet */,
|
|
|
|
BUSY /* StoreWeapon */,
|
|
|
|
BUSY /* StoreArmor */,
|
|
|
|
BUSY /* StoreItemInBarrel */,
|
|
|
|
BUSY /* StoreItemInBin */,
|
|
|
|
BUSY /* SeekArtifact */,
|
|
|
|
BUSY /* SeekInfant */,
|
|
|
|
OTHER /* AttendParty */,
|
|
|
|
OTHER /* GoShopping */,
|
|
|
|
OTHER /* GoShopping2 */,
|
|
|
|
BUSY /* Clean */,
|
|
|
|
OTHER /* Rest */,
|
2015-05-07 19:08:02 -06:00
|
|
|
EXCLUSIVE /* PickupEquipment */,
|
2012-07-17 09:27:30 -06:00
|
|
|
BUSY /* DumpItem */,
|
|
|
|
OTHER /* StrangeMoodCrafter */,
|
|
|
|
OTHER /* StrangeMoodJeweller */,
|
|
|
|
OTHER /* StrangeMoodForge */,
|
|
|
|
OTHER /* StrangeMoodMagmaForge */,
|
|
|
|
OTHER /* StrangeMoodBrooding */,
|
|
|
|
OTHER /* StrangeMoodFell */,
|
|
|
|
OTHER /* StrangeMoodCarpenter */,
|
|
|
|
OTHER /* StrangeMoodMason */,
|
|
|
|
OTHER /* StrangeMoodBowyer */,
|
|
|
|
OTHER /* StrangeMoodTanner */,
|
|
|
|
OTHER /* StrangeMoodWeaver */,
|
|
|
|
OTHER /* StrangeMoodGlassmaker */,
|
|
|
|
OTHER /* StrangeMoodMechanics */,
|
|
|
|
BUSY /* ConstructBuilding */,
|
|
|
|
BUSY /* ConstructDoor */,
|
|
|
|
BUSY /* ConstructFloodgate */,
|
|
|
|
BUSY /* ConstructBed */,
|
|
|
|
BUSY /* ConstructThrone */,
|
|
|
|
BUSY /* ConstructCoffin */,
|
|
|
|
BUSY /* ConstructTable */,
|
|
|
|
BUSY /* ConstructChest */,
|
|
|
|
BUSY /* ConstructBin */,
|
|
|
|
BUSY /* ConstructArmorStand */,
|
|
|
|
BUSY /* ConstructWeaponRack */,
|
|
|
|
BUSY /* ConstructCabinet */,
|
|
|
|
BUSY /* ConstructStatue */,
|
|
|
|
BUSY /* ConstructBlocks */,
|
|
|
|
BUSY /* MakeRawGlass */,
|
|
|
|
BUSY /* MakeCrafts */,
|
|
|
|
BUSY /* MintCoins */,
|
|
|
|
BUSY /* CutGems */,
|
|
|
|
BUSY /* CutGlass */,
|
|
|
|
BUSY /* EncrustWithGems */,
|
|
|
|
BUSY /* EncrustWithGlass */,
|
|
|
|
BUSY /* DestroyBuilding */,
|
|
|
|
BUSY /* SmeltOre */,
|
|
|
|
BUSY /* MeltMetalObject */,
|
|
|
|
BUSY /* ExtractMetalStrands */,
|
|
|
|
BUSY /* PlantSeeds */,
|
|
|
|
BUSY /* HarvestPlants */,
|
|
|
|
BUSY /* TrainHuntingAnimal */,
|
|
|
|
BUSY /* TrainWarAnimal */,
|
|
|
|
BUSY /* MakeWeapon */,
|
|
|
|
BUSY /* ForgeAnvil */,
|
|
|
|
BUSY /* ConstructCatapultParts */,
|
|
|
|
BUSY /* ConstructBallistaParts */,
|
|
|
|
BUSY /* MakeArmor */,
|
|
|
|
BUSY /* MakeHelm */,
|
|
|
|
BUSY /* MakePants */,
|
|
|
|
BUSY /* StudWith */,
|
|
|
|
BUSY /* ButcherAnimal */,
|
|
|
|
BUSY /* PrepareRawFish */,
|
|
|
|
BUSY /* MillPlants */,
|
|
|
|
BUSY /* BaitTrap */,
|
|
|
|
BUSY /* MilkCreature */,
|
|
|
|
BUSY /* MakeCheese */,
|
|
|
|
BUSY /* ProcessPlants */,
|
|
|
|
BUSY /* ProcessPlantsBag */,
|
|
|
|
BUSY /* ProcessPlantsVial */,
|
|
|
|
BUSY /* ProcessPlantsBarrel */,
|
|
|
|
BUSY /* PrepareMeal */,
|
|
|
|
BUSY /* WeaveCloth */,
|
|
|
|
BUSY /* MakeGloves */,
|
|
|
|
BUSY /* MakeShoes */,
|
|
|
|
BUSY /* MakeShield */,
|
|
|
|
BUSY /* MakeCage */,
|
|
|
|
BUSY /* MakeChain */,
|
|
|
|
BUSY /* MakeFlask */,
|
|
|
|
BUSY /* MakeGoblet */,
|
|
|
|
BUSY /* MakeInstrument */,
|
|
|
|
BUSY /* MakeToy */,
|
|
|
|
BUSY /* MakeAnimalTrap */,
|
|
|
|
BUSY /* MakeBarrel */,
|
|
|
|
BUSY /* MakeBucket */,
|
|
|
|
BUSY /* MakeWindow */,
|
|
|
|
BUSY /* MakeTotem */,
|
|
|
|
BUSY /* MakeAmmo */,
|
|
|
|
BUSY /* DecorateWith */,
|
|
|
|
BUSY /* MakeBackpack */,
|
|
|
|
BUSY /* MakeQuiver */,
|
|
|
|
BUSY /* MakeBallistaArrowHead */,
|
|
|
|
BUSY /* AssembleSiegeAmmo */,
|
|
|
|
BUSY /* LoadCatapult */,
|
|
|
|
BUSY /* LoadBallista */,
|
|
|
|
BUSY /* FireCatapult */,
|
|
|
|
BUSY /* FireBallista */,
|
|
|
|
BUSY /* ConstructMechanisms */,
|
|
|
|
BUSY /* MakeTrapComponent */,
|
|
|
|
BUSY /* LoadCageTrap */,
|
|
|
|
BUSY /* LoadStoneTrap */,
|
|
|
|
BUSY /* LoadWeaponTrap */,
|
|
|
|
BUSY /* CleanTrap */,
|
|
|
|
BUSY /* CastSpell */,
|
|
|
|
BUSY /* LinkBuildingToTrigger */,
|
|
|
|
BUSY /* PullLever */,
|
|
|
|
BUSY /* BrewDrink */,
|
|
|
|
BUSY /* ExtractFromPlants */,
|
|
|
|
BUSY /* ExtractFromRawFish */,
|
|
|
|
BUSY /* ExtractFromLandAnimal */,
|
|
|
|
BUSY /* TameVermin */,
|
|
|
|
BUSY /* TameAnimal */,
|
|
|
|
BUSY /* ChainAnimal */,
|
|
|
|
BUSY /* UnchainAnimal */,
|
|
|
|
BUSY /* UnchainPet */,
|
|
|
|
BUSY /* ReleaseLargeCreature */,
|
|
|
|
BUSY /* ReleasePet */,
|
|
|
|
BUSY /* ReleaseSmallCreature */,
|
|
|
|
BUSY /* HandleSmallCreature */,
|
|
|
|
BUSY /* HandleLargeCreature */,
|
|
|
|
BUSY /* CageLargeCreature */,
|
|
|
|
BUSY /* CageSmallCreature */,
|
|
|
|
BUSY /* RecoverWounded */,
|
|
|
|
BUSY /* DiagnosePatient */,
|
|
|
|
BUSY /* ImmobilizeBreak */,
|
|
|
|
BUSY /* DressWound */,
|
|
|
|
BUSY /* CleanPatient */,
|
|
|
|
BUSY /* Surgery */,
|
|
|
|
BUSY /* Suture */,
|
|
|
|
BUSY /* SetBone */,
|
|
|
|
BUSY /* PlaceInTraction */,
|
|
|
|
BUSY /* DrainAquarium */,
|
|
|
|
BUSY /* FillAquarium */,
|
|
|
|
BUSY /* FillPond */,
|
|
|
|
BUSY /* GiveWater */,
|
|
|
|
BUSY /* GiveFood */,
|
|
|
|
BUSY /* GiveWater2 */,
|
|
|
|
BUSY /* GiveFood2 */,
|
|
|
|
BUSY /* RecoverPet */,
|
|
|
|
BUSY /* PitLargeAnimal */,
|
|
|
|
BUSY /* PitSmallAnimal */,
|
|
|
|
BUSY /* SlaughterAnimal */,
|
|
|
|
BUSY /* MakeCharcoal */,
|
|
|
|
BUSY /* MakeAsh */,
|
|
|
|
BUSY /* MakeLye */,
|
|
|
|
BUSY /* MakePotashFromLye */,
|
|
|
|
BUSY /* FertilizeField */,
|
|
|
|
BUSY /* MakePotashFromAsh */,
|
|
|
|
BUSY /* DyeThread */,
|
|
|
|
BUSY /* DyeCloth */,
|
|
|
|
BUSY /* SewImage */,
|
|
|
|
BUSY /* MakePipeSection */,
|
|
|
|
BUSY /* OperatePump */,
|
|
|
|
OTHER /* ManageWorkOrders */,
|
|
|
|
OTHER /* UpdateStockpileRecords */,
|
|
|
|
OTHER /* TradeAtDepot */,
|
|
|
|
BUSY /* ConstructHatchCover */,
|
|
|
|
BUSY /* ConstructGrate */,
|
|
|
|
BUSY /* RemoveStairs */,
|
|
|
|
BUSY /* ConstructQuern */,
|
|
|
|
BUSY /* ConstructMillstone */,
|
|
|
|
BUSY /* ConstructSplint */,
|
|
|
|
BUSY /* ConstructCrutch */,
|
|
|
|
BUSY /* ConstructTractionBench */,
|
|
|
|
BUSY /* CleanSelf */,
|
|
|
|
BUSY /* BringCrutch */,
|
|
|
|
BUSY /* ApplyCast */,
|
|
|
|
BUSY /* CustomReaction */,
|
|
|
|
BUSY /* ConstructSlab */,
|
|
|
|
BUSY /* EngraveSlab */,
|
|
|
|
BUSY /* ShearCreature */,
|
|
|
|
BUSY /* SpinThread */,
|
|
|
|
BUSY /* PenLargeAnimal */,
|
|
|
|
BUSY /* PenSmallAnimal */,
|
|
|
|
BUSY /* MakeTool */,
|
|
|
|
BUSY /* CollectClay */,
|
|
|
|
BUSY /* InstallColonyInHive */,
|
|
|
|
BUSY /* CollectHiveProducts */,
|
|
|
|
OTHER /* CauseTrouble */,
|
|
|
|
OTHER /* DrinkBlood */,
|
|
|
|
OTHER /* ReportCrime */,
|
|
|
|
OTHER /* ExecuteCriminal */,
|
2012-09-13 13:42:17 -06:00
|
|
|
BUSY /* TrainAnimal */,
|
|
|
|
BUSY /* CarveTrack */,
|
|
|
|
BUSY /* PushTrackVehicle */,
|
|
|
|
BUSY /* PlaceTrackVehicle */,
|
2014-12-02 15:30:16 -07:00
|
|
|
BUSY /* StoreItemInVehicle */,
|
2016-02-22 10:40:52 -07:00
|
|
|
BUSY /* GeldAnimal */,
|
|
|
|
BUSY /* MakeFigurine */,
|
|
|
|
BUSY /* MakeAmulet */,
|
|
|
|
BUSY /* MakeScepter */,
|
|
|
|
BUSY /* MakeCrown */,
|
|
|
|
BUSY /* MakeRing */,
|
|
|
|
BUSY /* MakeEarring */,
|
|
|
|
BUSY /* MakeBracelet */,
|
2017-12-27 11:48:53 -07:00
|
|
|
BUSY /* MakeGem */,
|
|
|
|
BUSY /* PutItemOnDisplay */,
|
2012-03-16 22:45:52 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct labor_info
|
2012-04-05 00:33:26 -06:00
|
|
|
{
|
|
|
|
PersistentDataItem config;
|
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
bool is_exclusive;
|
|
|
|
int active_dwarfs;
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_mode mode() { return (labor_mode) config.ival(0); }
|
|
|
|
void set_mode(labor_mode mode) { config.ival(0) = mode; }
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
int minimum_dwarfs() { return config.ival(1); }
|
|
|
|
void set_minimum_dwarfs(int minimum_dwarfs) { config.ival(1) = minimum_dwarfs; }
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
int maximum_dwarfs() { return config.ival(2); }
|
|
|
|
void set_maximum_dwarfs(int maximum_dwarfs) { config.ival(2) = maximum_dwarfs; }
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2014-11-27 07:56:14 -07:00
|
|
|
int talent_pool() { return config.ival(3); }
|
|
|
|
void set_talent_pool(int talent_pool) { config.ival(3) = talent_pool; }
|
2012-04-05 00:33:26 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct labor_default
|
2012-03-16 22:45:52 -06:00
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_mode mode;
|
|
|
|
bool is_exclusive;
|
|
|
|
int minimum_dwarfs;
|
|
|
|
int maximum_dwarfs;
|
|
|
|
int active_dwarfs;
|
2012-03-16 22:45:52 -06:00
|
|
|
};
|
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
// The percentage of the dwarves assigned as haulers at any one time.
|
2012-07-05 08:59:28 -06:00
|
|
|
static int hauler_pct = 33;
|
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
// The maximum percentage of dwarves who will be allowed to be idle.
|
|
|
|
// Decreasing this will encourage autolabor to keep dwarves busy,
|
|
|
|
// at the expense of making it harder for dwarves to specialize in
|
|
|
|
// specific skills.
|
|
|
|
static int idler_pct = 10;
|
|
|
|
|
2012-04-05 00:33:26 -06:00
|
|
|
static std::vector<struct labor_info> labor_infos;
|
2012-03-28 09:25:36 -06:00
|
|
|
|
2012-04-05 00:33:26 -06:00
|
|
|
static const struct labor_default default_labor_infos[] = {
|
2012-09-13 13:42:17 -06:00
|
|
|
/* MINE */ {AUTOMATIC, true, 2, 200, 0},
|
|
|
|
/* HAUL_STONE */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* HAUL_WOOD */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* HAUL_BODY */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* HAUL_FOOD */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* HAUL_REFUSE */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* HAUL_ITEM */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* HAUL_FURNITURE */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* HAUL_ANIMAL */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* CLEAN */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* CUTWOOD */ {AUTOMATIC, true, 1, 200, 0},
|
|
|
|
/* CARPENTER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* DETAIL */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* MASON */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* ARCHITECT */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* ANIMALTRAIN */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* ANIMALCARE */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* DIAGNOSE */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* SURGERY */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* BONE_SETTING */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* SUTURING */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* DRESSING_WOUNDS */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* FEED_WATER_CIVILIANS */ {AUTOMATIC, false, 200, 200, 0},
|
|
|
|
/* RECOVER_WOUNDED */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* BUTCHER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* TRAPPER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* DISSECT_VERMIN */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* LEATHER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* TANNER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* BREWER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* ALCHEMIST */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* SOAP_MAKER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* WEAVER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* CLOTHESMAKER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* MILLER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* PROCESS_PLANT */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* MAKE_CHEESE */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* MILK */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* COOK */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* PLANT */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* HERBALIST */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* FISH */ {AUTOMATIC, false, 1, 1, 0},
|
|
|
|
/* CLEAN_FISH */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* DISSECT_FISH */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* HUNT */ {AUTOMATIC, true, 1, 1, 0},
|
|
|
|
/* SMELT */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* FORGE_WEAPON */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* FORGE_ARMOR */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* FORGE_FURNITURE */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* METAL_CRAFT */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* CUT_GEM */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* ENCRUST_GEM */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* WOOD_CRAFT */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* STONE_CRAFT */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* BONE_CARVE */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* GLASSMAKER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* EXTRACT_STRAND */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* SIEGECRAFT */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* SIEGEOPERATE */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* BOWYER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* MECHANIC */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* POTASH_MAKING */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* LYE_MAKING */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* DYER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* BURN_WOOD */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* OPERATE_PUMP */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* SHEARER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* SPINNER */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* POTTERY */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* GLAZING */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* PRESSING */ {AUTOMATIC, false, 1, 200, 0},
|
2014-11-07 17:45:20 -07:00
|
|
|
/* BEEKEEPING */ {AUTOMATIC, false, 1, 200, 0},
|
2012-09-13 13:42:17 -06:00
|
|
|
/* WAX_WORKING */ {AUTOMATIC, false, 1, 200, 0},
|
2014-08-15 13:12:57 -06:00
|
|
|
/* HANDLE_VEHICLES */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* HAUL_TRADE */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* PULL_LEVER */ {HAULERS, false, 1, 200, 0},
|
|
|
|
/* REMOVE_CONSTRUCTION */ {HAULERS, false, 1, 200, 0},
|
2014-12-02 15:30:16 -07:00
|
|
|
/* HAUL_WATER */ {HAULERS, false, 1, 200, 0},
|
2014-12-21 14:42:12 -07:00
|
|
|
/* GELD */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* BUILD_ROAD */ {AUTOMATIC, false, 1, 200, 0},
|
2015-12-09 18:03:35 -07:00
|
|
|
/* BUILD_CONSTRUCTION */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* PAPERMAKING */ {AUTOMATIC, false, 1, 200, 0},
|
|
|
|
/* BOOKBINDING */ {AUTOMATIC, false, 1, 200, 0}
|
2012-03-16 22:45:52 -06:00
|
|
|
};
|
|
|
|
|
2012-04-26 08:38:25 -06:00
|
|
|
static const int responsibility_penalties[] = {
|
2012-09-13 13:42:17 -06:00
|
|
|
0, /* LAW_MAKING */
|
|
|
|
0, /* LAW_ENFORCEMENT */
|
|
|
|
3000, /* RECEIVE_DIPLOMATS */
|
|
|
|
0, /* MEET_WORKERS */
|
|
|
|
1000, /* MANAGE_PRODUCTION */
|
|
|
|
3000, /* TRADE */
|
|
|
|
1000, /* ACCOUNTING */
|
|
|
|
0, /* ESTABLISH_COLONY_TRADE_AGREEMENTS */
|
|
|
|
0, /* MAKE_INTRODUCTIONS */
|
|
|
|
0, /* MAKE_PEACE_AGREEMENTS */
|
|
|
|
0, /* MAKE_TOPIC_AGREEMENTS */
|
|
|
|
0, /* COLLECT_TAXES */
|
|
|
|
0, /* ESCORT_TAX_COLLECTOR */
|
|
|
|
0, /* EXECUTIONS */
|
|
|
|
0, /* TAME_EXOTICS */
|
|
|
|
0, /* RELIGION */
|
|
|
|
0, /* ATTACK_ENEMIES */
|
|
|
|
0, /* PATROL_TERRITORY */
|
|
|
|
0, /* MILITARY_GOALS */
|
|
|
|
0, /* MILITARY_STRATEGY */
|
|
|
|
0, /* UPGRADE_SQUAD_EQUIPMENT */
|
|
|
|
0, /* EQUIPMENT_MANIFESTS */
|
|
|
|
0, /* SORT_AMMUNITION */
|
|
|
|
0, /* BUILD_MORALE */
|
|
|
|
5000 /* HEALTH_MANAGEMENT */
|
2012-03-16 22:45:52 -06:00
|
|
|
};
|
|
|
|
|
2012-03-29 12:00:26 -06:00
|
|
|
struct dwarf_info_t
|
2012-03-16 22:45:52 -06:00
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
int highest_skill;
|
|
|
|
int total_skill;
|
|
|
|
int mastery_penalty;
|
|
|
|
int assigned_jobs;
|
|
|
|
dwarf_state state;
|
|
|
|
bool has_exclusive_labor;
|
2012-04-26 08:38:25 -06:00
|
|
|
int noble_penalty; // penalty for assignment due to noble status
|
|
|
|
bool medical; // this dwarf has medical responsibility
|
2012-04-26 12:46:38 -06:00
|
|
|
bool trader; // this dwarf has trade responsibility
|
2012-08-02 09:32:25 -06:00
|
|
|
bool diplomacy; // this dwarf meets with diplomats
|
2012-03-16 22:45:52 -06:00
|
|
|
};
|
|
|
|
|
2012-04-05 00:33:26 -06:00
|
|
|
static bool isOptionEnabled(unsigned flag)
|
|
|
|
{
|
|
|
|
return config.isValid() && (config.ival(0) & flag) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setOptionEnabled(ConfigFlags flag, bool on)
|
|
|
|
{
|
|
|
|
if (!config.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (on)
|
|
|
|
config.ival(0) |= flag;
|
|
|
|
else
|
|
|
|
config.ival(0) &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup_state()
|
|
|
|
{
|
2013-09-30 03:19:51 -06:00
|
|
|
enable_autolabor = false;
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_infos.clear();
|
2012-04-05 00:33:26 -06:00
|
|
|
}
|
|
|
|
|
2012-09-13 13:42:17 -06:00
|
|
|
static void reset_labor(df::unit_labor labor)
|
2012-04-05 00:33:26 -06:00
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_infos[labor].set_minimum_dwarfs(default_labor_infos[labor].minimum_dwarfs);
|
|
|
|
labor_infos[labor].set_maximum_dwarfs(default_labor_infos[labor].maximum_dwarfs);
|
2014-11-27 07:56:14 -07:00
|
|
|
labor_infos[labor].set_talent_pool(200);
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_infos[labor].set_mode(default_labor_infos[labor].mode);
|
2012-04-05 00:33:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void init_state()
|
|
|
|
{
|
2012-10-06 03:46:20 -06:00
|
|
|
config = World::GetPersistentData("autolabor/config");
|
2012-04-05 00:33:26 -06:00
|
|
|
if (config.isValid() && config.ival(0) == -1)
|
|
|
|
config.ival(0) = 0;
|
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
enable_autolabor = isOptionEnabled(CF_ENABLED);
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (!enable_autolabor)
|
|
|
|
return;
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-10-06 03:46:20 -06:00
|
|
|
auto cfg_haulpct = World::GetPersistentData("autolabor/haulpct");
|
2012-08-02 09:32:25 -06:00
|
|
|
if (cfg_haulpct.isValid())
|
|
|
|
{
|
|
|
|
hauler_pct = cfg_haulpct.ival(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hauler_pct = 33;
|
|
|
|
}
|
2012-07-05 08:59:28 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Load labors from save
|
|
|
|
labor_infos.resize(ARRAY_COUNT(default_labor_infos));
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
std::vector<PersistentDataItem> items;
|
2012-10-06 03:46:20 -06:00
|
|
|
World::GetPersistentData(&items, "autolabor/labors/", true);
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
for (auto p = items.begin(); p != items.end(); p++)
|
|
|
|
{
|
|
|
|
string key = p->key();
|
2012-09-13 13:42:17 -06:00
|
|
|
df::unit_labor labor = (df::unit_labor) atoi(key.substr(strlen("autolabor/labors/")).c_str());
|
2018-04-10 12:29:00 -06:00
|
|
|
if (labor >= 0 && size_t(labor) < labor_infos.size())
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
|
|
|
labor_infos[labor].config = *p;
|
|
|
|
labor_infos[labor].is_exclusive = default_labor_infos[labor].is_exclusive;
|
|
|
|
labor_infos[labor].active_dwarfs = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add default labors for those not in save
|
2018-04-06 00:18:15 -06:00
|
|
|
for (size_t i = 0; i < ARRAY_COUNT(default_labor_infos); i++) {
|
2012-07-17 09:27:30 -06:00
|
|
|
if (labor_infos[i].config.isValid())
|
|
|
|
continue;
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
std::stringstream name;
|
|
|
|
name << "autolabor/labors/" << i;
|
2012-04-05 21:34:06 -06:00
|
|
|
|
2012-10-06 03:46:20 -06:00
|
|
|
labor_infos[i].config = World::AddPersistentData(name.str());
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_infos[i].is_exclusive = default_labor_infos[i].is_exclusive;
|
|
|
|
labor_infos[i].active_dwarfs = 0;
|
2012-09-13 13:42:17 -06:00
|
|
|
reset_labor((df::unit_labor) i);
|
2012-04-05 00:33:26 -06:00
|
|
|
}
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
generate_labor_to_skill_map();
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-04-05 00:33:26 -06:00
|
|
|
}
|
|
|
|
|
2012-07-22 11:16:50 -06:00
|
|
|
static df::job_skill labor_to_skill[ENUM_LAST_ITEM(unit_labor) + 1];
|
|
|
|
|
|
|
|
static void generate_labor_to_skill_map()
|
|
|
|
{
|
2012-08-02 09:32:25 -06:00
|
|
|
// Generate labor -> skill mapping
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
for (int i = 0; i <= ENUM_LAST_ITEM(unit_labor); i++)
|
2012-09-13 13:42:17 -06:00
|
|
|
labor_to_skill[i] = job_skill::NONE;
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
FOR_ENUM_ITEMS(job_skill, skill)
|
|
|
|
{
|
|
|
|
int labor = ENUM_ATTR(job_skill, labor, skill);
|
2012-09-13 13:42:17 -06:00
|
|
|
if (labor != unit_labor::NONE)
|
2012-08-02 09:32:25 -06:00
|
|
|
{
|
2012-07-22 11:16:50 -06:00
|
|
|
/*
|
2012-08-02 09:32:25 -06:00
|
|
|
assert(labor >= 0);
|
|
|
|
assert(labor < ARRAY_COUNT(labor_to_skill));
|
|
|
|
*/
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
labor_to_skill[labor] = skill;
|
|
|
|
}
|
|
|
|
}
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-04-05 00:33:26 -06:00
|
|
|
}
|
|
|
|
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-04-05 00:33:26 -06:00
|
|
|
static void enable_plugin(color_ostream &out)
|
|
|
|
{
|
|
|
|
if (!config.isValid())
|
|
|
|
{
|
2012-10-06 03:46:20 -06:00
|
|
|
config = World::AddPersistentData("autolabor/config");
|
2012-04-05 00:33:26 -06:00
|
|
|
config.ival(0) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setOptionEnabled(CF_ENABLED, true);
|
|
|
|
enable_autolabor = true;
|
2015-10-30 16:41:09 -06:00
|
|
|
out << "Enabling autolabor." << endl;
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
cleanup_state();
|
|
|
|
init_state();
|
2012-04-05 00:33:26 -06:00
|
|
|
}
|
|
|
|
|
2012-03-22 01:33:18 -06:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
2012-03-28 18:49:44 -06:00
|
|
|
// initialize labor infos table from default table
|
|
|
|
if(ARRAY_COUNT(default_labor_infos) != ENUM_LAST_ITEM(unit_labor) + 1)
|
2014-12-02 15:58:30 -07:00
|
|
|
{
|
|
|
|
out.printerr("autolabor: labor size mismatch\n");
|
2012-03-28 18:49:44 -06:00
|
|
|
return CR_FAILURE;
|
2014-12-02 15:58:30 -07:00
|
|
|
}
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-03-28 18:49:44 -06:00
|
|
|
// Fill the command list with your commands.
|
2012-03-22 01:33:18 -06:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"autolabor", "Automatically manage dwarf labors.",
|
|
|
|
autolabor, false, /* true means that the command can't be used from non-interactive user interface */
|
|
|
|
// Extended help string. Used by CR_WRONG_USAGE and the help command:
|
|
|
|
" autolabor enable\n"
|
2012-07-17 09:27:30 -06:00
|
|
|
" autolabor disable\n"
|
|
|
|
" Enables or disables the plugin.\n"
|
2014-11-27 07:56:14 -07:00
|
|
|
" autolabor <labor> <minimum> [<maximum>] [<talent pool>]\n"
|
2012-07-17 09:27:30 -06:00
|
|
|
" Set number of dwarves assigned to a labor.\n"
|
|
|
|
" autolabor <labor> haulers\n"
|
|
|
|
" Set a labor to be handled by hauler dwarves.\n"
|
|
|
|
" autolabor <labor> disable\n"
|
|
|
|
" Turn off autolabor for a specific labor.\n"
|
|
|
|
" autolabor <labor> reset\n"
|
|
|
|
" Return a labor to the default handling.\n"
|
|
|
|
" autolabor reset-all\n"
|
|
|
|
" Return all labors to the default handling.\n"
|
|
|
|
" autolabor list\n"
|
|
|
|
" List current status of all labors.\n"
|
|
|
|
" autolabor status\n"
|
|
|
|
" Show basic status information.\n"
|
|
|
|
"Function:\n"
|
|
|
|
" When enabled, autolabor periodically checks your dwarves and enables or\n"
|
|
|
|
" disables labors. It tries to keep as many dwarves as possible busy but\n"
|
|
|
|
" also tries to have dwarves specialize in specific skills.\n"
|
|
|
|
" Warning: autolabor will override any manual changes you make to labors\n"
|
|
|
|
" while it is enabled.\n"
|
2013-02-15 20:16:26 -07:00
|
|
|
" To prevent particular dwarves from being managed by autolabor, put them\n"
|
|
|
|
" in any burrow.\n"
|
2014-11-27 13:13:20 -07:00
|
|
|
" To restrict the assignment of a labor to only the top <n> most skilled\n"
|
|
|
|
" dwarves, add a talent pool number <n>.\n"
|
2012-07-17 09:27:30 -06:00
|
|
|
"Examples:\n"
|
|
|
|
" autolabor MINE 2\n"
|
|
|
|
" Keep at least 2 dwarves with mining enabled.\n"
|
|
|
|
" autolabor CUT_GEM 1 1\n"
|
|
|
|
" Keep exactly 1 dwarf with gemcutting enabled.\n"
|
2014-11-27 13:13:20 -07:00
|
|
|
" autolabor COOK 1 1 3\n"
|
|
|
|
" Keep 1 dwarf with cooking enabled, selected only from the top 3.\n"
|
2012-07-17 09:27:30 -06:00
|
|
|
" autolabor FEED_WATER_CIVILIANS haulers\n"
|
|
|
|
" Have haulers feed and water wounded dwarves.\n"
|
|
|
|
" autolabor CUTWOOD disable\n"
|
|
|
|
" Turn off autolabor for wood cutting.\n"
|
2012-03-22 01:33:18 -06:00
|
|
|
));
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
init_state();
|
2012-04-05 00:33:26 -06:00
|
|
|
|
2012-03-22 01:33:18 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
cleanup_state();
|
2012-03-28 09:25:36 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
return CR_OK;
|
2012-03-22 01:33:18 -06:00
|
|
|
}
|
|
|
|
|
2012-03-29 12:00:26 -06:00
|
|
|
// sorting objects
|
|
|
|
struct dwarfinfo_sorter
|
|
|
|
{
|
|
|
|
dwarfinfo_sorter(std::vector <dwarf_info_t> & info):dwarf_info(info){};
|
|
|
|
bool operator() (int i,int j)
|
|
|
|
{
|
|
|
|
if (dwarf_info[i].state == IDLE && dwarf_info[j].state != IDLE)
|
|
|
|
return true;
|
|
|
|
if (dwarf_info[i].state != IDLE && dwarf_info[j].state == IDLE)
|
|
|
|
return false;
|
|
|
|
return dwarf_info[i].mastery_penalty > dwarf_info[j].mastery_penalty;
|
|
|
|
};
|
|
|
|
std::vector <dwarf_info_t> & dwarf_info;
|
|
|
|
};
|
|
|
|
struct laborinfo_sorter
|
|
|
|
{
|
|
|
|
bool operator() (int i,int j)
|
|
|
|
{
|
2015-05-07 21:41:11 -06:00
|
|
|
if (labor_infos[i].mode() != labor_infos[j].mode())
|
|
|
|
return labor_infos[i].mode() < labor_infos[j].mode();
|
|
|
|
if (labor_infos[i].is_exclusive != labor_infos[j].is_exclusive)
|
|
|
|
return labor_infos[i].is_exclusive;
|
|
|
|
if (labor_infos[i].maximum_dwarfs() != labor_infos[j].maximum_dwarfs())
|
|
|
|
return labor_infos[i].maximum_dwarfs() < labor_infos[j].maximum_dwarfs();
|
|
|
|
return false;
|
2012-03-29 12:00:26 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct values_sorter
|
|
|
|
{
|
|
|
|
values_sorter(std::vector <int> & values):values(values){};
|
|
|
|
bool operator() (int i,int j)
|
|
|
|
{
|
|
|
|
return values[i] > values[j];
|
|
|
|
};
|
|
|
|
std::vector<int> & values;
|
|
|
|
};
|
|
|
|
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
static void assign_labor(unit_labor::unit_labor labor,
|
|
|
|
int n_dwarfs,
|
|
|
|
std::vector<dwarf_info_t>& dwarf_info,
|
|
|
|
bool trader_requested,
|
|
|
|
std::vector<df::unit *>& dwarfs,
|
|
|
|
bool has_butchers,
|
|
|
|
bool has_fishery,
|
|
|
|
color_ostream& out)
|
2012-07-22 11:16:50 -06:00
|
|
|
{
|
2012-08-02 09:32:25 -06:00
|
|
|
df::job_skill skill = labor_to_skill[labor];
|
|
|
|
|
|
|
|
if (labor_infos[labor].mode() != AUTOMATIC)
|
|
|
|
return;
|
|
|
|
|
2015-05-07 21:41:11 -06:00
|
|
|
int best_skill = 0;
|
2012-08-02 09:32:25 -06:00
|
|
|
|
|
|
|
std::vector<int> values(n_dwarfs);
|
|
|
|
std::vector<int> candidates;
|
|
|
|
std::map<int, int> dwarf_skill;
|
2014-11-27 07:56:14 -07:00
|
|
|
std::map<int, int> dwarf_skillxp;
|
2012-08-02 09:32:25 -06:00
|
|
|
std::vector<bool> previously_enabled(n_dwarfs);
|
|
|
|
|
|
|
|
// Find candidate dwarfs, and calculate a preference value for each dwarf
|
|
|
|
for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
|
|
|
|
{
|
|
|
|
if (dwarf_info[dwarf].state == CHILD)
|
|
|
|
continue;
|
|
|
|
if (dwarf_info[dwarf].state == MILITARY)
|
|
|
|
continue;
|
|
|
|
if (dwarf_info[dwarf].trader && trader_requested)
|
|
|
|
continue;
|
|
|
|
if (dwarf_info[dwarf].diplomacy)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (labor_infos[labor].is_exclusive && dwarf_info[dwarf].has_exclusive_labor)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int value = dwarf_info[dwarf].mastery_penalty;
|
|
|
|
|
2012-09-13 13:42:17 -06:00
|
|
|
if (skill != job_skill::NONE)
|
2012-08-02 09:32:25 -06:00
|
|
|
{
|
|
|
|
int skill_level = 0;
|
|
|
|
int skill_experience = 0;
|
|
|
|
|
|
|
|
for (auto s = dwarfs[dwarf]->status.souls[0]->skills.begin(); s < dwarfs[dwarf]->status.souls[0]->skills.end(); s++)
|
|
|
|
{
|
|
|
|
if ((*s)->id == skill)
|
|
|
|
{
|
|
|
|
skill_level = (*s)->rating;
|
|
|
|
skill_experience = (*s)->experience;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dwarf_skill[dwarf] = skill_level;
|
2014-11-27 07:56:14 -07:00
|
|
|
dwarf_skillxp[dwarf] = skill_experience;
|
2012-08-02 09:32:25 -06:00
|
|
|
|
2015-05-07 21:41:11 -06:00
|
|
|
if (best_skill < skill_level)
|
|
|
|
best_skill = skill_level;
|
2015-05-07 19:08:02 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
value += skill_level * 100;
|
|
|
|
value += skill_experience / 20;
|
|
|
|
if (skill_level > 0 || skill_experience > 0)
|
|
|
|
value += 200;
|
|
|
|
if (skill_level >= 15)
|
|
|
|
value += 1000 * (skill_level - 14);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwarf_skill[dwarf] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dwarfs[dwarf]->status.labors[labor])
|
|
|
|
{
|
|
|
|
value += 5;
|
|
|
|
if (labor_infos[labor].is_exclusive)
|
|
|
|
value += 350;
|
|
|
|
}
|
|
|
|
|
2015-05-07 21:41:11 -06:00
|
|
|
if (dwarf_info[dwarf].has_exclusive_labor)
|
|
|
|
value -= 500;
|
2015-05-07 19:08:02 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
// bias by happiness
|
|
|
|
|
2014-10-26 07:40:39 -06:00
|
|
|
//value += dwarfs[dwarf]->status.happiness;
|
2012-08-02 09:32:25 -06:00
|
|
|
|
|
|
|
values[dwarf] = value;
|
|
|
|
|
|
|
|
candidates.push_back(dwarf);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-27 07:56:14 -07:00
|
|
|
int pool = labor_infos[labor].talent_pool();
|
2022-05-16 19:41:47 -06:00
|
|
|
if (pool < 200 && candidates.size() > 1 && size_t(abs(pool)) < candidates.size())
|
2014-11-27 07:56:14 -07:00
|
|
|
{
|
|
|
|
// Sort in descending order
|
2014-11-27 16:55:26 -07:00
|
|
|
std::sort(candidates.begin(), candidates.end(), [&](const int lhs, const int rhs) -> bool {
|
2014-11-27 07:56:14 -07:00
|
|
|
if (dwarf_skill[lhs] == dwarf_skill[rhs])
|
2015-03-05 14:47:18 -07:00
|
|
|
if (pool > 0)
|
|
|
|
return dwarf_skillxp[lhs] > dwarf_skillxp[rhs];
|
|
|
|
else
|
|
|
|
return dwarf_skillxp[lhs] < dwarf_skillxp[rhs];
|
2014-11-27 07:56:14 -07:00
|
|
|
else
|
2015-03-05 14:47:18 -07:00
|
|
|
if (pool > 0)
|
|
|
|
return dwarf_skill[lhs] > dwarf_skill[rhs];
|
|
|
|
else
|
|
|
|
return dwarf_skill[lhs] < dwarf_skill[rhs];
|
2014-11-27 07:56:14 -07:00
|
|
|
});
|
|
|
|
|
2014-11-27 13:13:20 -07:00
|
|
|
// Check if all dwarves have equivalent skills, usually zero
|
|
|
|
int first_dwarf = candidates[0];
|
|
|
|
int last_dwarf = candidates[candidates.size() - 1];
|
|
|
|
if (dwarf_skill[first_dwarf] == dwarf_skill[last_dwarf] &&
|
|
|
|
dwarf_skillxp[first_dwarf] == dwarf_skillxp[last_dwarf])
|
|
|
|
{
|
|
|
|
// There's no difference in skill, so change nothing
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-05 14:47:18 -07:00
|
|
|
// Trim down to our top (or not) talents
|
|
|
|
candidates.resize(abs(pool));
|
2014-11-27 13:13:20 -07:00
|
|
|
}
|
2014-11-27 07:56:14 -07:00
|
|
|
}
|
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
// Sort candidates by preference value
|
2012-07-22 11:16:50 -06:00
|
|
|
values_sorter ivs(values);
|
2012-08-02 09:32:25 -06:00
|
|
|
std::sort(candidates.begin(), candidates.end(), ivs);
|
|
|
|
|
|
|
|
// Disable the labor on everyone
|
|
|
|
for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
|
|
|
|
{
|
|
|
|
if (dwarf_info[dwarf].state == CHILD)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
previously_enabled[dwarf] = dwarfs[dwarf]->status.labors[labor];
|
|
|
|
dwarfs[dwarf]->status.labors[labor] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int min_dwarfs = labor_infos[labor].minimum_dwarfs();
|
|
|
|
int max_dwarfs = labor_infos[labor].maximum_dwarfs();
|
|
|
|
|
|
|
|
// Special - don't assign hunt without a butchers, or fish without a fishery
|
2012-09-13 13:42:17 -06:00
|
|
|
if (unit_labor::HUNT == labor && !has_butchers)
|
2012-08-02 09:32:25 -06:00
|
|
|
min_dwarfs = max_dwarfs = 0;
|
2012-09-13 13:42:17 -06:00
|
|
|
if (unit_labor::FISH == labor && !has_fishery)
|
2012-08-02 09:32:25 -06:00
|
|
|
min_dwarfs = max_dwarfs = 0;
|
|
|
|
|
2015-05-07 21:41:11 -06:00
|
|
|
// If there are enough idle dwarves to choose from, enter an aggressive assignment
|
|
|
|
// mode. "Enough" idle dwarves is defined as 2 or 10% of the total number of dwarves,
|
|
|
|
// whichever is higher.
|
|
|
|
//
|
|
|
|
// In aggressive mode, we will always pick at least one idle dwarf for each skill,
|
|
|
|
// in order to try to get the idle dwarves to start doing something. We also pick
|
|
|
|
// any dwarf more preferable to the idle dwarf, since we'd rather have a more
|
|
|
|
// preferable dwarf do a new job if one becomes available (probably because that
|
|
|
|
// dwarf just finished a job).
|
|
|
|
//
|
|
|
|
// In non-aggressive mode, only dwarves that are good at a labor will be assigned
|
|
|
|
// to it. Dwarves good at nothing, or nothing that needs doing, will tend to get
|
|
|
|
// assigned to hauling by the hauler code. If there are no hauling jobs to do,
|
|
|
|
// they will sit around idle and when enough build up they will trigger aggressive
|
|
|
|
// mode again.
|
2015-05-07 19:08:02 -06:00
|
|
|
bool aggressive_mode = state_count[IDLE] >= 2 && state_count[IDLE] >= n_dwarfs * idler_pct / 100;
|
2012-08-02 09:32:25 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Assign dwarfs to this labor. We assign at least the minimum number of dwarfs, in
|
|
|
|
* order of preference, and then assign additional dwarfs that meet any of these conditions:
|
2015-05-07 19:08:02 -06:00
|
|
|
* - We are in aggressive mode and have not yet assigned an idle dwarf
|
2015-05-07 21:41:11 -06:00
|
|
|
* - The dwarf is good at this skill
|
2012-08-02 09:32:25 -06:00
|
|
|
* - The labor is mining, hunting, or woodcutting and the dwarf currently has it enabled.
|
|
|
|
* We stop assigning dwarfs when we reach the maximum allowed.
|
|
|
|
* Note that only idle and busy dwarfs count towards the number of dwarfs. "Other" dwarfs
|
|
|
|
* (sleeping, eating, on break, etc.) will have labors assigned, but will not be counted.
|
|
|
|
* Military and children/nobles will not have labors assigned.
|
2012-07-22 11:16:50 -06:00
|
|
|
* Dwarfs with the "health management" responsibility are always assigned DIAGNOSIS.
|
2012-08-02 09:32:25 -06:00
|
|
|
*/
|
2018-04-06 00:18:15 -06:00
|
|
|
for (size_t i = 0; i < candidates.size() && labor_infos[labor].active_dwarfs < max_dwarfs; i++)
|
2012-08-02 09:32:25 -06:00
|
|
|
{
|
|
|
|
int dwarf = candidates[i];
|
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
if (dwarf_info[dwarf].trader && trader_requested)
|
|
|
|
continue;
|
|
|
|
if (dwarf_info[dwarf].diplomacy)
|
|
|
|
continue;
|
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
assert(dwarf >= 0);
|
|
|
|
assert(dwarf < n_dwarfs);
|
|
|
|
|
|
|
|
bool preferred_dwarf = false;
|
2015-05-07 19:08:02 -06:00
|
|
|
if (dwarf_skillxp[dwarf] > 0 && dwarf_skill[dwarf] >= best_skill / 2)
|
2012-08-02 09:32:25 -06:00
|
|
|
preferred_dwarf = true;
|
2015-05-07 19:08:02 -06:00
|
|
|
if (previously_enabled[dwarf] && labor_infos[labor].is_exclusive && dwarf_info[dwarf].state == EXCLUSIVE)
|
2012-08-02 09:32:25 -06:00
|
|
|
preferred_dwarf = true;
|
2012-07-22 11:16:50 -06:00
|
|
|
if (dwarf_info[dwarf].medical && labor == df::unit_labor::DIAGNOSE)
|
|
|
|
preferred_dwarf = true;
|
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
if (labor_infos[labor].active_dwarfs >= min_dwarfs && !preferred_dwarf && !aggressive_mode)
|
2012-08-02 09:32:25 -06:00
|
|
|
continue;
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
if (!dwarfs[dwarf]->status.labors[labor])
|
|
|
|
dwarf_info[dwarf].assigned_jobs++;
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2015-10-30 16:41:09 -06:00
|
|
|
if (Units::isValidLabor(dwarfs[dwarf], labor))
|
|
|
|
dwarfs[dwarf]->status.labors[labor] = true;
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
if (labor_infos[labor].is_exclusive)
|
|
|
|
{
|
|
|
|
dwarf_info[dwarf].has_exclusive_labor = true;
|
|
|
|
// all the exclusive labors require equipment so this should force the dorf to reequip if needed
|
|
|
|
dwarfs[dwarf]->military.pickup_flags.bits.update = 1;
|
|
|
|
}
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
if (print_debug)
|
|
|
|
out.print("Dwarf %i \"%s\" assigned %s: value %i %s %s\n", dwarf, dwarfs[dwarf]->name.first_name.c_str(), ENUM_KEY_STR(unit_labor, labor).c_str(), values[dwarf], dwarf_info[dwarf].trader ? "(trader)" : "", dwarf_info[dwarf].diplomacy ? "(diplomacy)" : "");
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
if (dwarf_info[dwarf].state == IDLE || dwarf_info[dwarf].state == BUSY || dwarf_info[dwarf].state == EXCLUSIVE)
|
2012-08-02 09:32:25 -06:00
|
|
|
labor_infos[labor].active_dwarfs++;
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
if (dwarf_info[dwarf].state == IDLE)
|
2015-05-07 19:08:02 -06:00
|
|
|
aggressive_mode = false;
|
2012-08-02 09:32:25 -06:00
|
|
|
}
|
|
|
|
}
|
2012-07-22 11:16:50 -06:00
|
|
|
|
|
|
|
|
2012-04-05 00:33:26 -06:00
|
|
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case SC_MAP_LOADED:
|
|
|
|
cleanup_state();
|
|
|
|
init_state();
|
|
|
|
break;
|
|
|
|
case SC_MAP_UNLOADED:
|
|
|
|
cleanup_state();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-16 22:45:52 -06:00
|
|
|
DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
static int step_count = 0;
|
2012-03-31 19:46:17 -06:00
|
|
|
// check run conditions
|
2012-05-23 12:43:41 -06:00
|
|
|
if(!world || !world->map.block_index || !enable_autolabor)
|
2012-03-31 19:46:17 -06:00
|
|
|
{
|
|
|
|
// give up if we shouldn't be running'
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (++step_count < 60)
|
|
|
|
return CR_OK;
|
|
|
|
step_count = 0;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
std::vector<df::unit *> dwarfs;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
bool has_butchers = false;
|
|
|
|
bool has_fishery = false;
|
2012-04-26 12:46:38 -06:00
|
|
|
bool trader_requested = false;
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
for (size_t i = 0; i < world->buildings.all.size(); ++i)
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
|
|
|
df::building *build = world->buildings.all[i];
|
|
|
|
auto type = build->getType();
|
2012-09-13 13:42:17 -06:00
|
|
|
if (building_type::Workshop == type)
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
df::workshop_type subType = (df::workshop_type)build->getSubtype();
|
|
|
|
if (workshop_type::Butchers == subType)
|
2012-07-17 09:27:30 -06:00
|
|
|
has_butchers = true;
|
2012-09-13 13:42:17 -06:00
|
|
|
if (workshop_type::Fishery == subType)
|
2012-07-17 09:27:30 -06:00
|
|
|
has_fishery = true;
|
|
|
|
}
|
2012-09-13 13:42:17 -06:00
|
|
|
else if (building_type::TradeDepot == type)
|
2012-04-26 12:46:38 -06:00
|
|
|
{
|
|
|
|
df::building_tradedepotst* depot = (df::building_tradedepotst*) build;
|
2012-11-16 12:09:05 -07:00
|
|
|
trader_requested = trader_requested || depot->trade_flags.bits.trader_requested;
|
2012-04-26 12:46:38 -06:00
|
|
|
if (print_debug)
|
2012-08-02 09:32:25 -06:00
|
|
|
{
|
|
|
|
if (trader_requested)
|
|
|
|
out.print("Trade depot found and trader requested, trader will be excluded from all labors.\n");
|
|
|
|
else
|
|
|
|
out.print("Trade depot found but trader is not requested.\n");
|
|
|
|
}
|
2012-04-26 12:46:38 -06:00
|
|
|
}
|
2012-07-17 09:27:30 -06:00
|
|
|
}
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
for (size_t i = 0; i < world->units.active.size(); ++i)
|
2012-03-16 22:45:52 -06:00
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
df::unit* cre = world->units.active[i];
|
|
|
|
if (Units::isCitizen(cre))
|
2012-08-02 09:32:25 -06:00
|
|
|
{
|
|
|
|
if (cre->burrows.size() > 0)
|
|
|
|
continue; // dwarfs assigned to burrows are skipped entirely
|
2012-07-17 09:27:30 -06:00
|
|
|
dwarfs.push_back(cre);
|
2012-03-16 22:45:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
int n_dwarfs = dwarfs.size();
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (n_dwarfs == 0)
|
|
|
|
return CR_OK;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
std::vector<dwarf_info_t> dwarf_info(n_dwarfs);
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Find total skill and highest skill for each dwarf. More skilled dwarves shouldn't be used for minor tasks.
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
|
|
|
|
{
|
2012-04-26 08:38:25 -06:00
|
|
|
if (dwarfs[dwarf]->status.souls.size() <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// compute noble penalty
|
|
|
|
|
|
|
|
int noble_penalty = 0;
|
|
|
|
|
|
|
|
df::historical_figure* hf = df::historical_figure::find(dwarfs[dwarf]->hist_figure_id);
|
2013-10-20 12:50:22 -06:00
|
|
|
if(hf!=NULL) //can be NULL. E.g. script created citizens
|
2018-04-06 00:18:15 -06:00
|
|
|
for (size_t i = 0; i < hf->entity_links.size(); i++)
|
2012-08-02 09:32:25 -06:00
|
|
|
{
|
2012-04-26 08:38:25 -06:00
|
|
|
df::histfig_entity_link* hfelink = hf->entity_links.at(i);
|
2012-08-02 09:32:25 -06:00
|
|
|
if (hfelink->getType() == df::histfig_entity_link_type::POSITION)
|
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
df::histfig_entity_link_positionst *epos =
|
2012-04-26 08:38:25 -06:00
|
|
|
(df::histfig_entity_link_positionst*) hfelink;
|
|
|
|
df::historical_entity* entity = df::historical_entity::find(epos->entity_id);
|
2012-07-17 09:27:30 -06:00
|
|
|
if (!entity)
|
2012-04-26 08:38:25 -06:00
|
|
|
continue;
|
|
|
|
df::entity_position_assignment* assignment = binsearch_in_vector(entity->positions.assignments, epos->assignment_id);
|
|
|
|
if (!assignment)
|
|
|
|
continue;
|
|
|
|
df::entity_position* position = binsearch_in_vector(entity->positions.own, assignment->position_id);
|
|
|
|
if (!position)
|
|
|
|
continue;
|
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
for (int n = 0; n < 25; n++)
|
|
|
|
if (position->responsibilities[n])
|
2012-04-26 08:38:25 -06:00
|
|
|
noble_penalty += responsibility_penalties[n];
|
|
|
|
|
|
|
|
if (position->responsibilities[df::entity_position_responsibility::HEALTH_MANAGEMENT])
|
|
|
|
dwarf_info[dwarf].medical = true;
|
|
|
|
|
2012-04-26 12:46:38 -06:00
|
|
|
if (position->responsibilities[df::entity_position_responsibility::TRADE])
|
|
|
|
dwarf_info[dwarf].trader = true;
|
|
|
|
|
2012-04-26 08:38:25 -06:00
|
|
|
}
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-04-26 08:38:25 -06:00
|
|
|
}
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
dwarf_info[dwarf].noble_penalty = noble_penalty;
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
// identify dwarfs who are needed for meetings and mark them for exclusion
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
for (size_t i = 0; i < ui->activities.size(); ++i)
|
2012-08-02 09:32:25 -06:00
|
|
|
{
|
|
|
|
df::activity_info *act = ui->activities[i];
|
|
|
|
if (!act) continue;
|
2014-04-04 12:34:39 -06:00
|
|
|
bool p1 = act->unit_actor == dwarfs[dwarf];
|
|
|
|
bool p2 = act->unit_noble == dwarfs[dwarf];
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
if (p1 || p2)
|
|
|
|
{
|
|
|
|
dwarf_info[dwarf].diplomacy = true;
|
|
|
|
if (print_debug)
|
|
|
|
out.print("Dwarf %i \"%s\" has a meeting, will be cleared of all labors\n", dwarf, dwarfs[dwarf]->name.first_name.c_str());
|
|
|
|
break;
|
|
|
|
}
|
2012-04-26 08:38:25 -06:00
|
|
|
}
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
for (auto s = dwarfs[dwarf]->status.souls[0]->skills.begin(); s != dwarfs[dwarf]->status.souls[0]->skills.end(); s++)
|
|
|
|
{
|
|
|
|
df::job_skill skill = (*s)->id;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
df::job_skill_class skill_class = ENUM_ATTR(job_skill, type, skill);
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
int skill_level = (*s)->rating;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Track total & highest skill among normal/medical skills. (We don't care about personal or social skills.)
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-09-13 13:42:17 -06:00
|
|
|
if (skill_class != job_skill_class::Normal && skill_class != job_skill_class::Medical)
|
2012-07-17 09:27:30 -06:00
|
|
|
continue;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (dwarf_info[dwarf].highest_skill < skill_level)
|
|
|
|
dwarf_info[dwarf].highest_skill = skill_level;
|
|
|
|
dwarf_info[dwarf].total_skill += skill_level;
|
|
|
|
}
|
|
|
|
}
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Calculate a base penalty for using each dwarf for a task he isn't good at.
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
|
|
|
|
{
|
|
|
|
dwarf_info[dwarf].mastery_penalty -= 40 * dwarf_info[dwarf].highest_skill;
|
|
|
|
dwarf_info[dwarf].mastery_penalty -= 10 * dwarf_info[dwarf].total_skill;
|
2012-04-26 08:38:25 -06:00
|
|
|
dwarf_info[dwarf].mastery_penalty -= dwarf_info[dwarf].noble_penalty;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-09-13 13:42:17 -06:00
|
|
|
FOR_ENUM_ITEMS(unit_labor, labor)
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
if (labor == unit_labor::NONE)
|
2012-07-17 09:27:30 -06:00
|
|
|
continue;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (labor_infos[labor].is_exclusive && dwarfs[dwarf]->status.labors[labor])
|
|
|
|
dwarf_info[dwarf].mastery_penalty -= 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the activity state for each dwarf. It's important to get this right - a dwarf who we think is IDLE but
|
|
|
|
// can't work will gum everything up. In the future I might add code to auto-detect slacker dwarves.
|
|
|
|
|
|
|
|
state_count.clear();
|
|
|
|
state_count.resize(NUM_STATE);
|
|
|
|
|
|
|
|
for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
|
|
|
|
{
|
2015-01-28 14:26:17 -07:00
|
|
|
if (Units::isBaby(dwarfs[dwarf]) ||
|
|
|
|
Units::isChild(dwarfs[dwarf]) ||
|
2012-09-13 13:42:17 -06:00
|
|
|
dwarfs[dwarf]->profession == profession::DRUNK)
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
|
|
|
dwarf_info[dwarf].state = CHILD;
|
|
|
|
}
|
|
|
|
else if (ENUM_ATTR(profession, military, dwarfs[dwarf]->profession))
|
|
|
|
dwarf_info[dwarf].state = MILITARY;
|
|
|
|
else if (dwarfs[dwarf]->job.current_job == NULL)
|
|
|
|
{
|
2018-11-24 12:52:26 -07:00
|
|
|
if (Units::getMiscTrait(dwarfs[dwarf], misc_trait_type::Migrant))
|
2012-07-17 09:27:30 -06:00
|
|
|
dwarf_info[dwarf].state = OTHER;
|
|
|
|
else if (dwarfs[dwarf]->specific_refs.size() > 0)
|
|
|
|
dwarf_info[dwarf].state = OTHER;
|
|
|
|
else
|
|
|
|
dwarf_info[dwarf].state = IDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int job = dwarfs[dwarf]->job.current_job->job_type;
|
2018-04-06 00:18:15 -06:00
|
|
|
if (job >= 0 && size_t(job) < ARRAY_COUNT(dwarf_states))
|
2012-09-13 13:42:17 -06:00
|
|
|
dwarf_info[dwarf].state = dwarf_states[job];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.print("Dwarf %i \"%s\" has unknown job %i\n", dwarf, dwarfs[dwarf]->name.first_name.c_str(), job);
|
|
|
|
dwarf_info[dwarf].state = OTHER;
|
|
|
|
}
|
2012-07-17 09:27:30 -06:00
|
|
|
}
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
state_count[dwarf_info[dwarf].state]++;
|
2012-04-02 21:55:02 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (print_debug)
|
|
|
|
out.print("Dwarf %i \"%s\": penalty %i, state %s\n", dwarf, dwarfs[dwarf]->name.first_name.c_str(), dwarf_info[dwarf].mastery_penalty, state_names[dwarf_info[dwarf].state]);
|
|
|
|
}
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
std::vector<df::unit_labor> labors;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
FOR_ENUM_ITEMS(unit_labor, labor)
|
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
if (labor == unit_labor::NONE)
|
2012-07-17 09:27:30 -06:00
|
|
|
continue;
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_infos[labor].active_dwarfs = 0;
|
2012-04-02 23:12:06 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
labors.push_back(labor);
|
|
|
|
}
|
2012-03-29 12:00:26 -06:00
|
|
|
laborinfo_sorter lasorter;
|
2012-07-17 09:27:30 -06:00
|
|
|
std::sort(labors.begin(), labors.end(), lasorter);
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2015-05-06 21:57:43 -06:00
|
|
|
// Handle DISABLED skills (just bookkeeping).
|
2015-05-07 21:41:11 -06:00
|
|
|
// Note that autolabor should *NEVER* enable or disable a skill that has been marked as DISABLED, for any reason.
|
|
|
|
// The user has told us that they want manage this skill manually, and we must respect that.
|
2012-07-17 09:27:30 -06:00
|
|
|
for (auto lp = labors.begin(); lp != labors.end(); ++lp)
|
|
|
|
{
|
|
|
|
auto labor = *lp;
|
2012-04-02 21:55:02 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (labor_infos[labor].mode() != DISABLE)
|
|
|
|
continue;
|
2012-04-02 21:55:02 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
|
|
|
|
{
|
|
|
|
if (dwarfs[dwarf]->status.labors[labor])
|
|
|
|
{
|
|
|
|
if (labor_infos[labor].is_exclusive)
|
|
|
|
dwarf_info[dwarf].has_exclusive_labor = true;
|
2012-04-02 21:55:02 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
dwarf_info[dwarf].assigned_jobs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-02 21:55:02 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Handle all skills except those marked HAULERS
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
for (auto lp = labors.begin(); lp != labors.end(); ++lp)
|
|
|
|
{
|
|
|
|
auto labor = *lp;
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-08-02 09:32:25 -06:00
|
|
|
assign_labor(labor, n_dwarfs, dwarf_info, trader_requested, dwarfs, has_butchers, has_fishery, out);
|
2012-07-17 09:27:30 -06:00
|
|
|
}
|
2012-03-16 22:45:52 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// Set about 1/3 of the dwarfs as haulers. The haulers have all HAULER labors enabled. Having a lot of haulers helps
|
|
|
|
// make sure that hauling jobs are handled quickly rather than building up.
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
int num_haulers = state_count[IDLE] + (state_count[BUSY] + state_count[EXCLUSIVE]) * hauler_pct / 100;
|
2012-07-05 08:59:28 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (num_haulers < 1)
|
|
|
|
num_haulers = 1;
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
std::vector<int> hauler_ids;
|
|
|
|
for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
|
|
|
|
{
|
2012-07-22 11:16:50 -06:00
|
|
|
if ((dwarf_info[dwarf].trader && trader_requested) ||
|
2012-08-02 09:32:25 -06:00
|
|
|
dwarf_info[dwarf].diplomacy)
|
|
|
|
{
|
|
|
|
FOR_ENUM_ITEMS(unit_labor, labor)
|
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
if (labor == unit_labor::NONE)
|
2012-08-02 09:32:25 -06:00
|
|
|
continue;
|
|
|
|
if (labor_infos[labor].mode() != HAULERS)
|
|
|
|
continue;
|
|
|
|
dwarfs[dwarf]->status.labors[labor] = false;
|
|
|
|
}
|
2017-06-27 12:47:33 -06:00
|
|
|
if (dwarf_info[dwarf].state == IDLE || dwarf_info[dwarf].state == BUSY || dwarf_info[dwarf].state == EXCLUSIVE)
|
|
|
|
{
|
|
|
|
num_haulers--;
|
|
|
|
}
|
2012-04-30 08:01:48 -06:00
|
|
|
continue;
|
2012-08-02 09:32:25 -06:00
|
|
|
}
|
2012-07-11 13:30:47 -06:00
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
if (dwarf_info[dwarf].state == IDLE || dwarf_info[dwarf].state == BUSY || dwarf_info[dwarf].state == EXCLUSIVE)
|
2012-07-17 09:27:30 -06:00
|
|
|
hauler_ids.push_back(dwarf);
|
|
|
|
}
|
2012-03-29 12:00:26 -06:00
|
|
|
dwarfinfo_sorter sorter(dwarf_info);
|
2012-07-17 09:27:30 -06:00
|
|
|
// Idle dwarves come first, then we sort from least-skilled to most-skilled.
|
|
|
|
std::sort(hauler_ids.begin(), hauler_ids.end(), sorter);
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
// don't set any haulers if everyone is off drinking or something
|
|
|
|
if (hauler_ids.size() == 0) {
|
|
|
|
num_haulers = 0;
|
|
|
|
}
|
2012-03-27 20:39:06 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
FOR_ENUM_ITEMS(unit_labor, labor)
|
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
if (labor == unit_labor::NONE)
|
2012-07-17 09:27:30 -06:00
|
|
|
continue;
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (labor_infos[labor].mode() != HAULERS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int i = 0; i < num_haulers; i++)
|
|
|
|
{
|
2018-04-06 00:18:15 -06:00
|
|
|
assert(size_t(i) < hauler_ids.size());
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
int dwarf = hauler_ids[i];
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
assert(dwarf >= 0);
|
|
|
|
assert(dwarf < n_dwarfs);
|
|
|
|
dwarfs[dwarf]->status.labors[labor] = true;
|
|
|
|
dwarf_info[dwarf].assigned_jobs++;
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2015-05-07 19:08:02 -06:00
|
|
|
if (dwarf_info[dwarf].state == IDLE || dwarf_info[dwarf].state == BUSY || dwarf_info[dwarf].state == EXCLUSIVE)
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_infos[labor].active_dwarfs++;
|
2012-04-02 21:55:02 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (print_debug)
|
|
|
|
out.print("Dwarf %i \"%s\" assigned %s: hauler\n", dwarf, dwarfs[dwarf]->name.first_name.c_str(), ENUM_KEY_STR(unit_labor, labor).c_str());
|
|
|
|
}
|
2012-04-02 23:12:06 -06:00
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
for (size_t i = num_haulers; i < hauler_ids.size(); i++)
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
|
|
|
assert(i < hauler_ids.size());
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
int dwarf = hauler_ids[i];
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
assert(dwarf >= 0);
|
|
|
|
assert(dwarf < n_dwarfs);
|
2012-03-22 01:33:18 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
dwarfs[dwarf]->status.labors[labor] = false;
|
|
|
|
}
|
|
|
|
}
|
2012-04-02 21:55:02 -06:00
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
print_debug = 0;
|
2012-04-02 21:55:02 -06:00
|
|
|
|
2012-03-16 22:45:52 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-13 13:42:17 -06:00
|
|
|
void print_labor (df::unit_labor labor, color_ostream &out)
|
2012-04-02 23:12:06 -06:00
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
string labor_name = ENUM_KEY_STR(unit_labor, labor);
|
|
|
|
out << labor_name << ": ";
|
|
|
|
for (int i = 0; i < 20 - (int)labor_name.length(); i++)
|
|
|
|
out << ' ';
|
|
|
|
if (labor_infos[labor].mode() == DISABLE)
|
|
|
|
out << "disabled" << endl;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (labor_infos[labor].mode() == HAULERS)
|
|
|
|
out << "haulers";
|
|
|
|
else
|
2014-11-27 07:56:14 -07:00
|
|
|
out << "minimum " << labor_infos[labor].minimum_dwarfs() << ", maximum " << labor_infos[labor].maximum_dwarfs()
|
|
|
|
<< ", pool " << labor_infos[labor].talent_pool();
|
2012-07-17 09:27:30 -06:00
|
|
|
out << ", currently " << labor_infos[labor].active_dwarfs << " dwarfs" << endl;
|
|
|
|
}
|
2012-04-02 23:12:06 -06:00
|
|
|
}
|
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFhackCExport command_result plugin_enable ( color_ostream &out, bool enable )
|
|
|
|
{
|
|
|
|
if (!Core::getInstance().isWorldLoaded()) {
|
|
|
|
out.printerr("World is not loaded: please load a game first.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enable && !enable_autolabor)
|
|
|
|
{
|
|
|
|
enable_plugin(out);
|
|
|
|
}
|
|
|
|
else if(!enable && enable_autolabor)
|
|
|
|
{
|
|
|
|
enable_autolabor = false;
|
|
|
|
setOptionEnabled(CF_ENABLED, false);
|
|
|
|
|
|
|
|
out << "Autolabor is disabled." << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-07-22 11:16:50 -06:00
|
|
|
|
2012-03-16 22:45:52 -06:00
|
|
|
command_result autolabor (color_ostream &out, std::vector <std::string> & parameters)
|
|
|
|
{
|
2012-04-05 00:33:26 -06:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
|
|
|
if (!Core::getInstance().isWorldLoaded()) {
|
|
|
|
out.printerr("World is not loaded: please load a game first.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
if (parameters.size() == 1 &&
|
|
|
|
(parameters[0] == "0" || parameters[0] == "enable" ||
|
|
|
|
parameters[0] == "1" || parameters[0] == "disable"))
|
2012-03-16 22:45:52 -06:00
|
|
|
{
|
2012-04-05 00:33:26 -06:00
|
|
|
bool enable = (parameters[0] == "1" || parameters[0] == "enable");
|
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
return plugin_enable(out, enable);
|
2012-03-16 22:45:52 -06:00
|
|
|
}
|
2012-08-02 09:32:25 -06:00
|
|
|
else if (parameters.size() == 2 && parameters[0] == "haulpct")
|
|
|
|
{
|
|
|
|
if (!enable_autolabor)
|
|
|
|
{
|
|
|
|
out << "Error: The plugin is not enabled." << endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pct = atoi (parameters[1].c_str());
|
|
|
|
hauler_pct = pct;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2014-11-27 07:56:14 -07:00
|
|
|
else if (parameters.size() >= 2 && parameters.size() <= 4)
|
2012-09-13 13:42:17 -06:00
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
if (!enable_autolabor)
|
|
|
|
{
|
|
|
|
out << "Error: The plugin is not enabled." << endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-09-13 13:42:17 -06:00
|
|
|
df::unit_labor labor = unit_labor::NONE;
|
2012-07-17 09:27:30 -06:00
|
|
|
|
|
|
|
FOR_ENUM_ITEMS(unit_labor, test_labor)
|
|
|
|
{
|
|
|
|
if (parameters[0] == ENUM_KEY_STR(unit_labor, test_labor))
|
|
|
|
labor = test_labor;
|
|
|
|
}
|
|
|
|
|
2012-09-13 13:42:17 -06:00
|
|
|
if (labor == unit_labor::NONE)
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
|
|
|
out.printerr("Could not find labor %s.\n", parameters[0].c_str());
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters[1] == "haulers")
|
|
|
|
{
|
|
|
|
labor_infos[labor].set_mode(HAULERS);
|
|
|
|
print_labor(labor, out);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
if (parameters[1] == "disable")
|
|
|
|
{
|
|
|
|
labor_infos[labor].set_mode(DISABLE);
|
|
|
|
print_labor(labor, out);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
if (parameters[1] == "reset")
|
|
|
|
{
|
|
|
|
reset_labor(labor);
|
|
|
|
print_labor(labor, out);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int minimum = atoi (parameters[1].c_str());
|
|
|
|
int maximum = 200;
|
2014-11-27 07:56:14 -07:00
|
|
|
int pool = 200;
|
|
|
|
|
|
|
|
if (parameters.size() >= 3)
|
2012-07-17 09:27:30 -06:00
|
|
|
maximum = atoi (parameters[2].c_str());
|
2014-11-27 07:56:14 -07:00
|
|
|
if (parameters.size() == 4)
|
|
|
|
pool = std::stoi(parameters[3]);
|
2012-07-17 09:27:30 -06:00
|
|
|
|
2015-03-05 14:47:18 -07:00
|
|
|
if (maximum < minimum || maximum < 0 || minimum < 0)
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
2018-06-11 10:57:06 -06:00
|
|
|
out.printerr("Syntax: autolabor <labor> <minimum> [<maximum>] [<talent pool>], %d > %d\n", maximum, minimum);
|
2012-07-17 09:27:30 -06:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
labor_infos[labor].set_minimum_dwarfs(minimum);
|
|
|
|
labor_infos[labor].set_maximum_dwarfs(maximum);
|
2014-11-27 07:56:14 -07:00
|
|
|
labor_infos[labor].set_talent_pool(pool);
|
2012-07-17 09:27:30 -06:00
|
|
|
labor_infos[labor].set_mode(AUTOMATIC);
|
|
|
|
print_labor(labor, out);
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-09-13 13:42:17 -06:00
|
|
|
else if (parameters.size() == 1 && parameters[0] == "reset-all")
|
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
if (!enable_autolabor)
|
|
|
|
{
|
|
|
|
out << "Error: The plugin is not enabled." << endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-04-06 00:18:15 -06:00
|
|
|
for (size_t i = 0; i < labor_infos.size(); i++)
|
2012-07-17 09:27:30 -06:00
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
reset_labor((df::unit_labor) i);
|
2012-07-17 09:27:30 -06:00
|
|
|
}
|
|
|
|
out << "All labors reset." << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2015-12-13 11:23:56 -07:00
|
|
|
else if (parameters.size() == 1 && (parameters[0] == "list" || parameters[0] == "status"))
|
2012-09-13 13:42:17 -06:00
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
if (!enable_autolabor)
|
|
|
|
{
|
|
|
|
out << "Error: The plugin is not enabled." << endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool need_comma = 0;
|
|
|
|
for (int i = 0; i < NUM_STATE; i++)
|
|
|
|
{
|
|
|
|
if (state_count[i] == 0)
|
|
|
|
continue;
|
|
|
|
if (need_comma)
|
|
|
|
out << ", ";
|
|
|
|
out << state_count[i] << ' ' << state_names[i];
|
|
|
|
need_comma = 1;
|
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
|
|
|
|
if (parameters[0] == "list")
|
|
|
|
{
|
|
|
|
FOR_ENUM_ITEMS(unit_labor, labor)
|
|
|
|
{
|
2012-09-13 13:42:17 -06:00
|
|
|
if (labor == unit_labor::NONE)
|
2012-07-17 09:27:30 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
print_labor(labor, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-08-02 09:32:25 -06:00
|
|
|
else if (parameters.size() == 1 && parameters[0] == "debug")
|
|
|
|
{
|
2012-07-17 09:27:30 -06:00
|
|
|
if (!enable_autolabor)
|
|
|
|
{
|
|
|
|
out << "Error: The plugin is not enabled." << endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_debug = 1;
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else
|
2012-03-16 22:45:52 -06:00
|
|
|
{
|
|
|
|
out.print("Automatically assigns labors to dwarves.\n"
|
2014-11-07 17:45:20 -07:00
|
|
|
"Activate with 'enable autolabor', deactivate with 'disable autolabor'.\n"
|
2012-03-16 22:45:52 -06:00
|
|
|
"Current state: %d.\n", enable_autolabor);
|
|
|
|
|
2012-07-17 09:27:30 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-03-16 22:45:52 -06:00
|
|
|
}
|