2012-04-02 08:07:23 -06:00
|
|
|
// Intention: help with activity zone management (auto-pasture animals, auto-pit goblins, ...)
|
|
|
|
//
|
|
|
|
// the following things would be nice:
|
|
|
|
// - dump info about pastures, pastured animals, count non-pastured tame animals, print gender info
|
|
|
|
// - help finding caged dwarves? (maybe even allow to build their cages for fast release)
|
|
|
|
// - dump info about caged goblins, animals, ...
|
|
|
|
// - count grass tiles on pastures, move grazers to new pasture if old pasture is empty
|
|
|
|
// move hungry unpastured grazers to pasture with grass
|
|
|
|
//
|
|
|
|
// What is working so far:
|
|
|
|
// - print detailed info about activity zone and units under cursor (mostly for checking refs and stuff)
|
|
|
|
// - mark a zone which is used for future assignment commands
|
|
|
|
// - assign single selected creature to a zone
|
2012-04-10 01:15:38 -06:00
|
|
|
// - mass-assign creatures using filters
|
2012-04-02 08:07:23 -06:00
|
|
|
// - unassign single creature under cursor from current zone
|
|
|
|
// - pitting own dwarves :)
|
2012-04-04 06:58:53 -06:00
|
|
|
// - full automation of handling mini-pastures over nestboxes:
|
|
|
|
// go through all pens, check if they are empty and placed over a nestbox
|
|
|
|
// find female tame egg-layer who is not assigned to another pen and assign it to nestbox pasture
|
|
|
|
// maybe check for minimum age? it's not that useful to fill nestboxes with freshly hatched birds
|
2012-04-09 07:03:26 -06:00
|
|
|
// state and sleep setting is saved the first time autonestbox is started (to avoid writing stuff if the plugin is never used)
|
2012-04-06 18:31:10 -06:00
|
|
|
// - full automation of marking live-stock for slaughtering
|
|
|
|
// races can be added to a watchlist and it can be set how many male/female kids/adults are left alive
|
2012-04-07 03:15:49 -06:00
|
|
|
// adding to the watchlist can be automated as well.
|
2012-04-09 07:03:26 -06:00
|
|
|
// config for autobutcher (state and sleep setting) is saved the first time autobutcher is started
|
|
|
|
// config for watchlist entries is saved when they are created or modified
|
2012-04-02 08:07:23 -06:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
2012-04-06 18:31:10 -06:00
|
|
|
#include <algorithm>
|
2012-04-02 08:07:23 -06:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <ctime>
|
|
|
|
#include <cstdio>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "modules/Units.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Gui.h"
|
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "modules/MapCache.h"
|
|
|
|
#include "modules/Buildings.h"
|
2012-04-09 07:03:26 -06:00
|
|
|
#include "modules/World.h"
|
2012-04-02 08:07:23 -06:00
|
|
|
#include "MiscUtils.h"
|
|
|
|
|
|
|
|
#include <df/ui.h>
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/world_raws.h"
|
|
|
|
#include "df/building_def.h"
|
|
|
|
#include "df/building_civzonest.h"
|
|
|
|
#include "df/building_cagest.h"
|
|
|
|
#include "df/building_chainst.h"
|
2012-04-15 13:45:15 -06:00
|
|
|
#include "df/building_nest_boxst.h"
|
2012-04-02 08:07:23 -06:00
|
|
|
#include "df/general_ref_building_civzone_assignedst.h"
|
|
|
|
#include <df/creature_raw.h>
|
2012-04-04 06:58:53 -06:00
|
|
|
#include <df/caste_raw.h>
|
2012-04-02 08:07:23 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::cursor;
|
|
|
|
using df::global::ui;
|
|
|
|
|
|
|
|
using namespace DFHack::Gui;
|
|
|
|
|
|
|
|
command_result df_zone (color_ostream &out, vector <string> & parameters);
|
2012-04-05 12:32:44 -06:00
|
|
|
command_result df_autonestbox (color_ostream &out, vector <string> & parameters);
|
2012-04-06 18:31:10 -06:00
|
|
|
command_result df_autobutcher(color_ostream &out, vector <string> & parameters);
|
2012-04-02 08:07:23 -06:00
|
|
|
|
|
|
|
DFHACK_PLUGIN("zone");
|
|
|
|
|
|
|
|
const string zone_help =
|
2012-04-10 01:15:38 -06:00
|
|
|
"Allows easier management of pens/pastures, pits and cages.\n"
|
2012-04-02 08:07:23 -06:00
|
|
|
"Options:\n"
|
|
|
|
" set - set zone under cursor as default for future assigns\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" assign - assign creature(s) to a pen or pit\n"
|
|
|
|
" if no filters are used, a single unit must be selected.\n"
|
2012-04-10 01:15:38 -06:00
|
|
|
" can be followed by valid building id which will then be set.\n"
|
|
|
|
" building must be a pen/pasture, pit or cage.\n"
|
2012-04-05 12:32:44 -06:00
|
|
|
" slaughter - mark creature(s) for slaughter\n"
|
|
|
|
" if no filters are used, a single unit must be selected.\n"
|
|
|
|
" with filters named units are ignored unless specified.\n"
|
2012-04-10 01:15:38 -06:00
|
|
|
" unassign - unassign selected creature(s) from it's zone or cage\n"
|
2012-04-16 08:31:12 -06:00
|
|
|
" nick - give unit(s) nicknames (e.g. all units in a cage)\n"
|
|
|
|
" remnick - remove nicknames\n"
|
|
|
|
" tocages - assign to (multiple) built cages inside a pen/pasture\n"
|
|
|
|
" spreads creatures evenly among cages for faster hauling.\n"
|
2012-04-02 08:07:23 -06:00
|
|
|
" uinfo - print info about selected unit\n"
|
|
|
|
" zinfo - print info about zone(s) under cursor\n"
|
|
|
|
" verbose - print some more info, mostly useless debug stuff\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" filters - print list of supported filters\n"
|
2012-04-16 08:31:12 -06:00
|
|
|
" examples - print some usage examples\n"
|
|
|
|
;
|
2012-04-04 06:58:53 -06:00
|
|
|
|
|
|
|
const string zone_help_filters =
|
|
|
|
"Filters (to be used in combination with 'all' or 'count'):\n"
|
2012-04-15 11:49:50 -06:00
|
|
|
"These filters can not be used with the prefix 'not':"
|
2012-04-04 06:58:53 -06:00
|
|
|
" all - in combinations with zinfo/uinfo: print all zones/units\n"
|
|
|
|
" in combination with assign: process all units\n"
|
|
|
|
" should be used in combination with further filters\n"
|
|
|
|
" count - must be followed by number. process X units\n"
|
|
|
|
" should be used in combination with further filters\n"
|
|
|
|
" unassigned - not assigned to zone, chain or built cage\n"
|
2012-04-15 11:49:50 -06:00
|
|
|
" age - exact age. must be followed by number\n"
|
|
|
|
" minage - minimum age. must be followed by number\n"
|
|
|
|
" maxage - maximum age. must be followed by number\n"
|
|
|
|
"These filters can be used with the prefix 'not' (e.g. 'not own'):"
|
|
|
|
" race - must be followed by a race raw id (e.g. BIRD_TURKEY)\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" caged - in a built cage\n"
|
2012-04-08 04:51:03 -06:00
|
|
|
" own - from own civilization\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" war - trained war creature\n"
|
|
|
|
" tamed - tamed\n"
|
2012-04-05 12:32:44 -06:00
|
|
|
" named - has name or nickname\n"
|
|
|
|
" can be used to mark named units for slaughter\n"
|
2012-04-08 04:51:03 -06:00
|
|
|
" merchant - is a merchant / belongs to a merchant\n"
|
|
|
|
" can be used to pit merchants and slaughter their animals\n"
|
|
|
|
" (could have weird effects during trading, be careful)\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" trained - obvious\n"
|
2012-04-15 09:40:39 -06:00
|
|
|
" trainablewar - can be trained for war (and is not already trained)\n"
|
|
|
|
" trainablehunt- can be trained for hunting (and is not already trained)\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" male - obvious\n"
|
|
|
|
" female - obvious\n"
|
|
|
|
" egglayer - race lays eggs (use together with 'female')\n"
|
2012-04-09 20:10:07 -06:00
|
|
|
" grazer - is a grazer\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" milkable - race is milkable (use together with 'female')\n"
|
2012-04-15 11:49:50 -06:00
|
|
|
;
|
2012-04-04 06:58:53 -06:00
|
|
|
|
|
|
|
const string zone_help_examples =
|
|
|
|
"Example for assigning single units:\n"
|
2012-04-02 08:07:23 -06:00
|
|
|
" (ingame) move cursor to a pen/pasture or pit zone\n"
|
|
|
|
" (dfhack) 'zone set' to use this zone for future assignments\n"
|
|
|
|
" (dfhack) map 'zone assign' to a hotkey of your choice\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" (ingame) select unit with 'v', 'k' or from unit list or inside a cage\n"
|
2012-04-05 03:40:27 -06:00
|
|
|
" (ingame) press hotkey to assign unit to it's new home (or pit)\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
"Examples for assigning with filters:\n"
|
|
|
|
" (this assumes you have already set up a target zone)\n"
|
|
|
|
" zone assign all own grazer maxage 10\n"
|
2012-04-15 11:49:50 -06:00
|
|
|
" zone assign all own milkable not grazer\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" zone assign count 5 own female milkable\n"
|
|
|
|
" zone assign all own race DWARF maxage 2\n"
|
|
|
|
" throw all useless kids into a pit :)\n"
|
|
|
|
"Notes:\n"
|
2012-04-10 01:15:38 -06:00
|
|
|
" Unassigning per filters ignores built cages and chains currently. Usually you\n"
|
2012-04-09 07:03:26 -06:00
|
|
|
" should always use the filter 'own' (which implies tame) unless you want to\n"
|
|
|
|
" use the zone tool for pitting hostiles. 'own' ignores own dwarves unless you\n"
|
|
|
|
" specify 'race DWARF' and it ignores merchants and their animals unless you\n"
|
|
|
|
" specify 'merchant' (so it's safe to use 'assign all own' to one big pasture\n"
|
2012-04-04 06:58:53 -06:00
|
|
|
" if you want to have all your animals at the same place).\n"
|
|
|
|
" 'egglayer' and 'milkable' should be used together with 'female'\n"
|
2012-04-09 07:03:26 -06:00
|
|
|
" well, unless you have a mod with egg-laying male elves who give milk...\n";
|
2012-04-02 08:07:23 -06:00
|
|
|
|
|
|
|
|
2012-04-05 12:32:44 -06:00
|
|
|
const string autonestbox_help =
|
|
|
|
"Assigns unpastured female egg-layers to nestbox zones.\n"
|
|
|
|
"Requires that you create pen/pasture zones above nestboxes.\n"
|
|
|
|
"If the pen is bigger than 1x1 the nestbox must be in the top left corner.\n"
|
|
|
|
"Only 1 unit will be assigned per pen, regardless of the size.\n"
|
|
|
|
"The age of the units is currently not checked, most birds grow up quite fast.\n"
|
|
|
|
"When called without options autonestbox will instantly run once.\n"
|
|
|
|
"Options:\n"
|
|
|
|
" start - run every X frames (df simulation ticks)\n"
|
|
|
|
" default: X=6000 (~60 seconds at 100fps)\n"
|
|
|
|
" stop - stop running automatically\n"
|
|
|
|
" sleep X - change timer to sleep X frames between runs.\n";
|
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
const string autobutcher_help =
|
|
|
|
"Assigns your lifestock for slaughter once it reaches a specific count. Requires\n"
|
2012-04-09 07:03:26 -06:00
|
|
|
"that you add the target race(s) to a watch list. Only tame units will be\n"
|
|
|
|
"processed. Named units will be completely ignored (you can give animals\n"
|
|
|
|
"nicknames with the tool 'rename unit' to protect them from getting slaughtered\n"
|
|
|
|
"automatically. Trained war or hunting pets will be ignored.\n"
|
2012-04-06 18:31:10 -06:00
|
|
|
"Once you have too much adults, the oldest will be butchered first.\n"
|
|
|
|
"Once you have too much kids, the youngest will be butchered first.\n"
|
|
|
|
"If you don't set a target count the following default will be used:\n"
|
|
|
|
"1 male kid, 5 female kids, 1 male adult, 5 female adults.\n"
|
|
|
|
"Options:\n"
|
|
|
|
" start - run every X frames (df simulation ticks)\n"
|
|
|
|
" default: X=6000 (~60 seconds at 100fps)\n"
|
|
|
|
" stop - stop running automatically\n"
|
|
|
|
" sleep X - change timer to sleep X frames between runs.\n"
|
|
|
|
" watch R - start watching race(s)\n"
|
|
|
|
" R = valid race RAW id (ALPACA, BIRD_TURKEY, etc)\n"
|
2012-04-06 21:05:42 -06:00
|
|
|
" or a list of RAW ids seperated by spaces\n"
|
2012-04-09 08:02:03 -06:00
|
|
|
" or the keyword 'all' which affects your whole current watchlist.\n"
|
2012-04-06 21:05:42 -06:00
|
|
|
" unwatch R - stop watching race(s)\n"
|
2012-04-06 18:31:10 -06:00
|
|
|
" the current target settings will be remembered\n"
|
2012-04-06 21:05:42 -06:00
|
|
|
" forget R - unwatch race(s) and forget target settings for it/them\n"
|
2012-04-07 03:15:49 -06:00
|
|
|
" autowatch - automatically adds all new races (animals you buy\n"
|
|
|
|
" from merchants, tame yourself or get from migrants)\n"
|
|
|
|
" to the watch list using default target count\n"
|
|
|
|
" noautowatch - stop auto-adding new races to the watch list\n"
|
2012-04-09 07:03:26 -06:00
|
|
|
" list - print status and watchlist\n"
|
|
|
|
" list_export - print status and watchlist in batchfile format\n"
|
|
|
|
" can be used to copy settings into another savegame\n"
|
|
|
|
" usage: 'dfhack-run autobutcher list_export > xyz.bat' \n"
|
2012-04-06 18:31:10 -06:00
|
|
|
" target fk mk fa ma R\n"
|
|
|
|
" - set target count for specified race:\n"
|
|
|
|
" fk = number of female kids\n"
|
|
|
|
" mk = number of male kids\n"
|
|
|
|
" fa = number of female adults\n"
|
|
|
|
" ma = number of female adults\n"
|
2012-04-07 03:15:49 -06:00
|
|
|
" R = 'all' sets count for all races on the current watchlist\n"
|
|
|
|
" including the races which are currenly set to 'unwatched'\n"
|
|
|
|
" and sets the new default for future watch commands\n"
|
|
|
|
" R = 'new' sets the new default for future watch commands\n"
|
|
|
|
" without changing your current watchlist\n"
|
2012-04-06 18:31:10 -06:00
|
|
|
" example - print some usage examples\n";
|
|
|
|
|
|
|
|
const string autobutcher_help_example =
|
|
|
|
"Examples:\n"
|
2012-04-06 21:05:42 -06:00
|
|
|
" autobutcher target 4 3 2 1 ALPACA BIRD_TURKEY\n"
|
|
|
|
" autobutcher watch ALPACA BIRD_TURKEY\n"
|
2012-04-06 18:31:10 -06:00
|
|
|
" autobutcher start\n"
|
|
|
|
" This means you want to have max 7 kids (4 female, 3 male) and max 3 adults\n"
|
2012-04-06 21:05:42 -06:00
|
|
|
" (2 female, 1 male) of the races alpaca and turkey. Once the kids grow up the\n"
|
|
|
|
" oldest adults will get slaughtered. Excess kids will get slaughtered starting\n"
|
|
|
|
" the the youngest to allow that the older ones grow into adults.\n"
|
2012-04-07 03:15:49 -06:00
|
|
|
" autobutcher target 0 0 0 0 new\n"
|
|
|
|
" autobutcher autowatch\n"
|
|
|
|
" autobutcher start\n"
|
|
|
|
" This tells autobutcher to automatically put all new races onto the watchlist\n"
|
|
|
|
" and mark unnamed tame units for slaughter as soon as they arrive in your\n"
|
|
|
|
" fortress. Settings already made for some races will be left untouched.\n";
|
2012-04-06 18:31:10 -06:00
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
command_result init_autobutcher(color_ostream &out);
|
|
|
|
command_result cleanup_autobutcher(color_ostream &out);
|
|
|
|
command_result start_autobutcher(color_ostream &out);
|
|
|
|
|
|
|
|
command_result init_autonestbox(color_ostream &out);
|
|
|
|
command_result cleanup_autonestbox(color_ostream &out);
|
|
|
|
command_result start_autonestbox(color_ostream &out);
|
2012-04-05 12:32:44 -06:00
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"zone", "manage activity zones.",
|
|
|
|
df_zone, false,
|
|
|
|
zone_help.c_str()
|
|
|
|
));
|
2012-04-05 12:32:44 -06:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"autonestbox", "auto-assign nestbox zones.",
|
|
|
|
df_autonestbox, false,
|
2012-04-06 18:31:10 -06:00
|
|
|
autonestbox_help.c_str()
|
|
|
|
));
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"autobutcher", "auto-assign lifestock for butchering.",
|
|
|
|
df_autobutcher, false,
|
|
|
|
autobutcher_help.c_str()
|
2012-04-05 12:32:44 -06:00
|
|
|
));
|
2012-04-09 07:03:26 -06:00
|
|
|
init_autobutcher(out);
|
|
|
|
init_autonestbox(out);
|
2012-04-02 08:07:23 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
|
|
|
{
|
2012-04-09 07:03:26 -06:00
|
|
|
cleanup_autobutcher(out);
|
|
|
|
cleanup_autonestbox(out);
|
2012-04-02 08:07:23 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-05 12:32:44 -06:00
|
|
|
///////////////
|
2012-04-06 18:31:10 -06:00
|
|
|
// stuff for autonestbox and autobutcher
|
2012-04-05 12:32:44 -06:00
|
|
|
// should be moved to own plugin once the tool methods it shares with the zone plugin are moved to Unit.h / Building.h
|
|
|
|
|
|
|
|
command_result autoNestbox( color_ostream &out, bool verbose );
|
2012-04-06 18:31:10 -06:00
|
|
|
command_result autoButcher( color_ostream &out, bool verbose );
|
2012-04-05 12:32:44 -06:00
|
|
|
|
|
|
|
static bool enable_autonestbox = false;
|
2012-04-06 18:31:10 -06:00
|
|
|
static bool enable_autobutcher = false;
|
2012-04-07 03:15:49 -06:00
|
|
|
static bool enable_autobutcher_autowatch = false;
|
2012-04-05 12:32:44 -06:00
|
|
|
static size_t sleep_autonestbox = 6000;
|
2012-04-06 18:31:10 -06:00
|
|
|
static size_t sleep_autobutcher = 6000;
|
2012-04-05 12:32:44 -06:00
|
|
|
static bool autonestbox_did_complain = false; // avoids message spam
|
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
static PersistentDataItem config_autobutcher;
|
|
|
|
static PersistentDataItem config_autonestbox;
|
|
|
|
|
|
|
|
|
2012-04-05 12:32:44 -06:00
|
|
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
|
|
|
|
{
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case DFHack::SC_MAP_LOADED:
|
|
|
|
// initialize from the world just loaded
|
2012-04-09 07:03:26 -06:00
|
|
|
init_autobutcher(out);
|
|
|
|
init_autonestbox(out);
|
2012-04-05 12:32:44 -06:00
|
|
|
break;
|
|
|
|
case DFHack::SC_MAP_UNLOADED:
|
|
|
|
enable_autonestbox = false;
|
2012-04-06 18:31:10 -06:00
|
|
|
enable_autobutcher = false;
|
2012-04-05 12:32:44 -06:00
|
|
|
// cleanup
|
2012-04-09 07:03:26 -06:00
|
|
|
cleanup_autobutcher(out);
|
|
|
|
cleanup_autonestbox(out);
|
2012-04-05 12:32:44 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
|
|
|
{
|
|
|
|
static size_t ticks_autonestbox = 0;
|
2012-04-06 18:31:10 -06:00
|
|
|
static size_t ticks_autobutcher = 0;
|
2012-04-05 12:32:44 -06:00
|
|
|
|
|
|
|
if(enable_autonestbox)
|
|
|
|
{
|
|
|
|
if(++ticks_autonestbox >= sleep_autonestbox)
|
|
|
|
{
|
|
|
|
ticks_autonestbox = 0;
|
|
|
|
autoNestbox(out, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
if(enable_autobutcher)
|
2012-04-05 12:32:44 -06:00
|
|
|
{
|
2012-04-06 18:31:10 -06:00
|
|
|
if(++ticks_autobutcher >= sleep_autobutcher)
|
2012-04-05 12:32:44 -06:00
|
|
|
{
|
2012-04-06 18:31:10 -06:00
|
|
|
ticks_autobutcher= 0;
|
|
|
|
autoButcher(out, false);
|
2012-04-05 12:32:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Various small tool functions
|
2012-04-02 08:58:12 -06:00
|
|
|
// probably many of these should be moved to Unit.h and Building.h sometime later...
|
2012-04-04 06:58:53 -06:00
|
|
|
|
|
|
|
int32_t getUnitAge(df::unit* unit);
|
2012-04-02 08:07:23 -06:00
|
|
|
bool isTame(df::unit* unit);
|
|
|
|
bool isTrained(df::unit* unit);
|
2012-04-15 19:31:49 -06:00
|
|
|
bool isWar(df::unit* unit);
|
|
|
|
bool isHunter(df::unit* unit);
|
|
|
|
bool isOwnCiv(df::unit* unit);
|
|
|
|
bool isMerchant(df::unit* unit);
|
|
|
|
bool isForest(df::unit* unit);
|
2012-04-05 12:32:44 -06:00
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
bool isActivityZone(df::building * building);
|
|
|
|
bool isPenPasture(df::building * building);
|
2012-04-11 06:08:47 -06:00
|
|
|
bool isPitPond(df::building * building);
|
2012-04-02 08:07:23 -06:00
|
|
|
bool isActive(df::building * building);
|
2012-04-04 06:58:53 -06:00
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
int32_t findBuildingIndexById(int32_t id);
|
|
|
|
int32_t findPenPitAtCursor();
|
|
|
|
int32_t findCageAtCursor();
|
|
|
|
int32_t findChainAtCursor();
|
|
|
|
|
|
|
|
df::general_ref_building_civzone_assignedst * createCivzoneRef();
|
2012-04-10 01:15:38 -06:00
|
|
|
bool unassignUnitFromBuilding(df::unit* unit);
|
2012-04-02 08:07:23 -06:00
|
|
|
command_result assignUnitToZone(color_ostream& out, df::unit* unit, df::building* building, bool verbose);
|
2012-04-05 12:32:44 -06:00
|
|
|
void unitInfo(color_ostream & out, df::unit* creature, bool verbose);
|
|
|
|
void zoneInfo(color_ostream & out, df::building* building, bool verbose);
|
|
|
|
void cageInfo(color_ostream & out, df::building* building, bool verbose);
|
|
|
|
void chainInfo(color_ostream & out, df::building* building, bool verbose);
|
2012-04-04 06:58:53 -06:00
|
|
|
bool isBuiltCageAtPos(df::coord pos);
|
2012-04-16 08:31:12 -06:00
|
|
|
bool isInBuiltCageRoom(df::unit*);
|
2012-04-20 13:22:20 -06:00
|
|
|
bool isNaked(df::unit *);
|
2012-04-20 13:38:50 -06:00
|
|
|
bool isTamable(df::unit *);
|
2012-04-02 08:07:23 -06:00
|
|
|
|
|
|
|
int32_t getUnitAge(df::unit* unit)
|
|
|
|
{
|
2012-04-05 03:40:27 -06:00
|
|
|
// If the birthday this year has not yet passed, subtract one year.
|
|
|
|
// ASSUMPTION: birth_time is on the same scale as cur_year_tick
|
2012-04-02 08:07:23 -06:00
|
|
|
int32_t yearDifference = *df::global::cur_year - unit->relations.birth_year;
|
|
|
|
if (unit->relations.birth_time >= *df::global::cur_year_tick)
|
|
|
|
yearDifference--;
|
|
|
|
return yearDifference;
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:58:12 -06:00
|
|
|
bool isDead(df::unit* unit)
|
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
return unit->flags1.bits.dead;
|
2012-04-05 03:40:27 -06:00
|
|
|
}
|
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
// ignore vampires, they should be treated like normal dwarves
|
|
|
|
bool isUndead(df::unit* unit)
|
|
|
|
{
|
|
|
|
return (unit->flags3.bits.ghostly ||
|
|
|
|
( (unit->curse.add_tags1.bits.OPPOSED_TO_LIFE || unit->curse.add_tags1.bits.NOT_LIVING)
|
|
|
|
&& !unit->curse.add_tags1.bits.BLOODSUCKER ));
|
|
|
|
}
|
|
|
|
|
2012-04-07 22:25:40 -06:00
|
|
|
bool isMerchant(df::unit* unit)
|
|
|
|
{
|
2012-04-08 04:51:03 -06:00
|
|
|
return unit->flags1.bits.merchant;
|
2012-04-07 22:25:40 -06:00
|
|
|
}
|
|
|
|
|
2012-04-08 00:07:29 -06:00
|
|
|
bool isForest(df::unit* unit)
|
|
|
|
{
|
2012-04-08 04:51:03 -06:00
|
|
|
return unit->flags1.bits.forest;
|
2012-04-08 00:07:29 -06:00
|
|
|
}
|
|
|
|
|
2012-04-05 03:40:27 -06:00
|
|
|
bool isMarkedForSlaughter(df::unit* unit)
|
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
return unit->flags2.bits.slaughter;
|
2012-04-05 03:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void doMarkForSlaughter(df::unit* unit)
|
|
|
|
{
|
|
|
|
unit->flags2.bits.slaughter = 1;
|
2012-04-02 08:58:12 -06:00
|
|
|
}
|
|
|
|
|
2012-04-16 13:37:48 -06:00
|
|
|
// check if creature is tame
|
2012-04-02 08:07:23 -06:00
|
|
|
bool isTame(df::unit* creature)
|
|
|
|
{
|
|
|
|
bool tame = false;
|
|
|
|
if(creature->flags1.bits.tame)
|
|
|
|
{
|
|
|
|
switch (creature->training_level)
|
|
|
|
{
|
|
|
|
case df::animal_training_level::Trained:
|
|
|
|
case df::animal_training_level::WellTrained:
|
|
|
|
case df::animal_training_level::SkilfullyTrained:
|
|
|
|
case df::animal_training_level::ExpertlyTrained:
|
|
|
|
case df::animal_training_level::ExceptionallyTrained:
|
|
|
|
case df::animal_training_level::MasterfullyTrained:
|
|
|
|
case df::animal_training_level::Domesticated:
|
|
|
|
tame=true;
|
|
|
|
break;
|
|
|
|
case df::animal_training_level::SemiWild: //??
|
|
|
|
case df::animal_training_level::Unk8: //??
|
|
|
|
case df::animal_training_level::WildUntamed:
|
|
|
|
default:
|
|
|
|
tame=false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tame;
|
|
|
|
}
|
|
|
|
|
2012-04-16 13:37:48 -06:00
|
|
|
// check if creature is domesticated
|
|
|
|
// seems to be the only way to really tell if it's completely safe to autonestbox it (training can revert)
|
|
|
|
bool isDomesticated(df::unit* creature)
|
|
|
|
{
|
|
|
|
bool tame = false;
|
|
|
|
if(creature->flags1.bits.tame)
|
|
|
|
{
|
|
|
|
switch (creature->training_level)
|
|
|
|
{
|
|
|
|
case df::animal_training_level::Domesticated:
|
|
|
|
tame=true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tame=false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tame;
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
// check if trained (might be useful if pasturing war dogs etc)
|
2012-04-15 19:31:49 -06:00
|
|
|
bool isTrained(df::unit* unit)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-15 19:31:49 -06:00
|
|
|
// case a: trained for war/hunting (those don't have a training level, strangely)
|
|
|
|
if(isWar(unit) || isHunter(unit))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// case b: tamed and trained wild creature, gets a training level
|
2012-04-02 08:07:23 -06:00
|
|
|
bool trained = false;
|
2012-04-15 19:31:49 -06:00
|
|
|
switch (unit->training_level)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-15 19:31:49 -06:00
|
|
|
case df::animal_training_level::Trained:
|
|
|
|
case df::animal_training_level::WellTrained:
|
|
|
|
case df::animal_training_level::SkilfullyTrained:
|
|
|
|
case df::animal_training_level::ExpertlyTrained:
|
|
|
|
case df::animal_training_level::ExceptionallyTrained:
|
|
|
|
case df::animal_training_level::MasterfullyTrained:
|
|
|
|
//case df::animal_training_level::Domesticated:
|
|
|
|
trained = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
return trained;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for profession "war creature"
|
2012-04-15 19:31:49 -06:00
|
|
|
bool isWar(df::unit* unit)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-15 19:31:49 -06:00
|
|
|
if( unit->profession == df::profession::TRAINED_WAR
|
|
|
|
|| unit->profession2 == df::profession::TRAINED_WAR)
|
2012-04-02 08:07:23 -06:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for profession "hunting creature"
|
2012-04-15 19:31:49 -06:00
|
|
|
bool isHunter(df::unit* unit)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-15 19:31:49 -06:00
|
|
|
if( unit->profession == df::profession::TRAINED_HUNTER
|
|
|
|
|| unit->profession2 == df::profession::TRAINED_HUNTER)
|
2012-04-02 08:07:23 -06:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if creature belongs to the player's civilization
|
|
|
|
// (don't try to pasture/slaughter random untame animals)
|
2012-04-15 19:31:49 -06:00
|
|
|
bool isOwnCiv(df::unit* unit)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-15 19:31:49 -06:00
|
|
|
return unit->civ_id == ui->civ_id;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
// check if creature belongs to the player's race
|
|
|
|
// (in combination with check for civ helps to filter out own dwarves)
|
2012-04-15 19:31:49 -06:00
|
|
|
bool isOwnRace(df::unit* unit)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
2012-04-15 19:31:49 -06:00
|
|
|
return unit->race == ui->race_id;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
string getRaceName(int32_t id)
|
|
|
|
{
|
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[id];
|
|
|
|
return raw->creature_id;
|
|
|
|
}
|
2012-04-04 06:58:53 -06:00
|
|
|
string getRaceName(df::unit* unit)
|
|
|
|
{
|
2012-04-05 03:40:27 -06:00
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
2012-04-04 06:58:53 -06:00
|
|
|
return raw->creature_id;
|
|
|
|
}
|
2012-04-05 12:32:44 -06:00
|
|
|
string getRaceBabyName(df::unit* unit)
|
|
|
|
{
|
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
|
|
|
return raw->general_baby_name[0];
|
|
|
|
}
|
|
|
|
string getRaceChildName(df::unit* unit)
|
|
|
|
{
|
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
|
|
|
return raw->general_child_name[0];
|
|
|
|
}
|
2012-04-04 06:58:53 -06:00
|
|
|
|
2012-04-05 03:40:27 -06:00
|
|
|
bool isBaby(df::unit* unit)
|
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
return unit->profession == df::profession::BABY;
|
2012-04-05 03:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isChild(df::unit* unit)
|
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
return unit->profession == df::profession::CHILD;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAdult(df::unit* unit)
|
|
|
|
{
|
|
|
|
return !isBaby(unit) && !isChild(unit);
|
2012-04-05 03:40:27 -06:00
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
bool isEggLayer(df::unit* unit)
|
|
|
|
{
|
2012-04-05 03:40:27 -06:00
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
2012-04-04 06:58:53 -06:00
|
|
|
size_t sizecas = raw->caste.size();
|
|
|
|
for (size_t j = 0; j < sizecas;j++)
|
|
|
|
{
|
|
|
|
df::caste_raw *caste = raw->caste[j];
|
|
|
|
if( caste->flags.is_set(caste_raw_flags::LAYS_EGGS)
|
|
|
|
|| caste->flags.is_set(caste_raw_flags::LAYS_UNUSUAL_EGGS))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isGrazer(df::unit* unit)
|
|
|
|
{
|
2012-04-05 03:40:27 -06:00
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
2012-04-04 06:58:53 -06:00
|
|
|
size_t sizecas = raw->caste.size();
|
|
|
|
for (size_t j = 0; j < sizecas;j++)
|
|
|
|
{
|
|
|
|
df::caste_raw *caste = raw->caste[j];
|
|
|
|
if(caste->flags.is_set(caste_raw_flags::GRAZER))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isMilkable(df::unit* unit)
|
|
|
|
{
|
2012-04-05 03:40:27 -06:00
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
2012-04-04 06:58:53 -06:00
|
|
|
size_t sizecas = raw->caste.size();
|
|
|
|
for (size_t j = 0; j < sizecas;j++)
|
|
|
|
{
|
|
|
|
df::caste_raw *caste = raw->caste[j];
|
|
|
|
if(caste->flags.is_set(caste_raw_flags::MILKABLE))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-15 09:40:39 -06:00
|
|
|
bool isTrainableWar(df::unit* unit)
|
|
|
|
{
|
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
|
|
|
size_t sizecas = raw->caste.size();
|
|
|
|
for (size_t j = 0; j < sizecas;j++)
|
|
|
|
{
|
|
|
|
df::caste_raw *caste = raw->caste[j];
|
|
|
|
if(caste->flags.is_set(caste_raw_flags::TRAINABLE_WAR))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isTrainableHunting(df::unit* unit)
|
|
|
|
{
|
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
|
|
|
size_t sizecas = raw->caste.size();
|
|
|
|
for (size_t j = 0; j < sizecas;j++)
|
|
|
|
{
|
|
|
|
df::caste_raw *caste = raw->caste[j];
|
|
|
|
if(caste->flags.is_set(caste_raw_flags::TRAINABLE_HUNTING))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-20 13:38:50 -06:00
|
|
|
bool isTamable(df::unit* unit)
|
|
|
|
{
|
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race];
|
|
|
|
size_t sizecas = raw->caste.size();
|
|
|
|
for (size_t j = 0; j < sizecas;j++)
|
|
|
|
{
|
|
|
|
df::caste_raw *caste = raw->caste[j];
|
|
|
|
if(caste->flags.is_set(caste_raw_flags::PET) ||
|
|
|
|
caste->flags.is_set(caste_raw_flags::PET_EXOTIC))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
bool isMale(df::unit* unit)
|
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
return unit->sex == 1;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
2012-04-05 12:32:44 -06:00
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
bool isFemale(df::unit* unit)
|
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
return unit->sex == 0;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
// found a unit with weird position values on one of my maps (negative and in the thousands)
|
|
|
|
// it didn't appear in the animal stocks screen, but looked completely fine otherwise (alive, tame, own, etc)
|
2012-04-08 04:51:03 -06:00
|
|
|
// maybe a rare bug, but better avoid assigning such units to zones or slaughter etc.
|
2012-04-06 18:31:10 -06:00
|
|
|
bool hasValidMapPos(df::unit* unit)
|
|
|
|
{
|
|
|
|
if( unit->pos.x >=0 && unit->pos.y >= 0 && unit->pos.z >= 0
|
|
|
|
&& unit->pos.x < world->map.x_count
|
|
|
|
&& unit->pos.y < world->map.y_count
|
|
|
|
&& unit->pos.z < world->map.z_count)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-20 13:22:20 -06:00
|
|
|
bool isNaked(df::unit* unit)
|
|
|
|
{
|
|
|
|
return (unit->inventory.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-09 16:22:38 -06:00
|
|
|
int getUnitIndexFromId(df::unit* unit_)
|
|
|
|
{
|
|
|
|
for (size_t i=0; i < world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit* unit = world->units.all[i];
|
|
|
|
if(unit->id == unit_->id)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
// dump some unit info
|
2012-04-04 06:58:53 -06:00
|
|
|
void unitInfo(color_ostream & out, df::unit* unit, bool verbose = false)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-04 06:58:53 -06:00
|
|
|
out.print("Unit %d ", unit->id); //race %d, civ %d,", creature->race, creature->civ_id
|
2012-04-02 08:07:23 -06:00
|
|
|
if(unit->name.has_name)
|
2012-04-05 03:40:27 -06:00
|
|
|
{
|
|
|
|
// units given a nick with the rename tool might not have a first name (animals etc)
|
|
|
|
string firstname = unit->name.first_name;
|
|
|
|
if(firstname.size() > 0)
|
|
|
|
{
|
|
|
|
firstname[0] = toupper(firstname[0]);
|
|
|
|
out << "Name: " << firstname;
|
|
|
|
}
|
|
|
|
if(unit->name.nickname.size() > 0)
|
|
|
|
out << " '" << unit->name.nickname << "'";
|
2012-04-04 06:58:53 -06:00
|
|
|
out << ", ";
|
2012-04-05 03:40:27 -06:00
|
|
|
}
|
2012-04-05 12:32:44 -06:00
|
|
|
|
|
|
|
if(isAdult(unit))
|
|
|
|
out << "adult";
|
|
|
|
else if(isBaby(unit))
|
|
|
|
out << "baby";
|
|
|
|
else if(isChild(unit))
|
|
|
|
out << "child";
|
|
|
|
out << " ";
|
|
|
|
// sometimes empty even in vanilla RAWS, sometimes contains full race name (e.g. baby alpaca)
|
|
|
|
// all animals I looked at don't have babies anyways, their offspring starts as CHILD
|
|
|
|
//out << getRaceBabyName(unit);
|
|
|
|
//out << getRaceChildName(unit);
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
out << getRaceName(unit) << " (";
|
2012-04-02 08:07:23 -06:00
|
|
|
switch(unit->sex)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
out << "female";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
out << "male";
|
|
|
|
break;
|
2012-04-04 06:58:53 -06:00
|
|
|
case -1:
|
2012-04-02 08:07:23 -06:00
|
|
|
default:
|
2012-04-04 06:58:53 -06:00
|
|
|
out << "n/a";
|
2012-04-02 08:07:23 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
out << ")";
|
|
|
|
out << ", age: " << getUnitAge(unit);
|
2012-04-08 00:07:29 -06:00
|
|
|
|
2012-04-08 04:51:03 -06:00
|
|
|
if(isTame(unit))
|
2012-04-02 08:07:23 -06:00
|
|
|
out << ", tame";
|
|
|
|
if(isOwnCiv(unit))
|
|
|
|
out << ", owned";
|
|
|
|
if(isWar(unit))
|
|
|
|
out << ", war";
|
|
|
|
if(isHunter(unit))
|
|
|
|
out << ", hunter";
|
2012-04-08 04:51:03 -06:00
|
|
|
if(isMerchant(unit))
|
|
|
|
out << ", merchant";
|
|
|
|
if(isForest(unit))
|
|
|
|
out << ", forest";
|
2012-04-09 07:03:26 -06:00
|
|
|
if(isEggLayer(unit))
|
|
|
|
out << ", egglayer";
|
|
|
|
if(isGrazer(unit))
|
|
|
|
out << ", grazer";
|
|
|
|
if(isMilkable(unit))
|
|
|
|
out << ", milkable";
|
2012-04-02 08:07:23 -06:00
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
if(verbose)
|
|
|
|
{
|
2012-04-09 16:22:38 -06:00
|
|
|
out << ". Pos: ("<<unit->pos.x << "/"<< unit->pos.y << "/" << unit->pos.z << ") " << endl;
|
|
|
|
out << "index in units vector: " << getUnitIndexFromId(unit) << endl;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
out << endl;
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
if(!verbose)
|
2012-04-02 08:07:23 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
//out << "number of refs: " << creature->refs.size() << endl;
|
|
|
|
for(size_t r = 0; r<unit->refs.size(); r++)
|
|
|
|
{
|
|
|
|
df::general_ref* ref = unit->refs.at(r);
|
|
|
|
df::general_ref_type refType = ref->getType();
|
|
|
|
out << " ref#" << r <<" refType#" << refType << " "; //endl;
|
|
|
|
switch(refType)
|
|
|
|
{
|
|
|
|
case df::general_ref_type::BUILDING_CIVZONE_ASSIGNED:
|
|
|
|
{
|
|
|
|
out << "assigned to zone";
|
|
|
|
df::building_civzonest * civAss = (df::building_civzonest *) ref->getBuilding();
|
|
|
|
out << " #" << civAss->id;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case df::general_ref_type::CONTAINED_IN_ITEM:
|
|
|
|
out << "contained in item";
|
|
|
|
break;
|
|
|
|
case df::general_ref_type::BUILDING_CAGED:
|
|
|
|
out << "caged";
|
|
|
|
break;
|
|
|
|
case df::general_ref_type::BUILDING_CHAIN:
|
|
|
|
out << "chained";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//out << "unhandled reftype";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
}
|
2012-04-16 08:31:12 -06:00
|
|
|
if(isInBuiltCageRoom(unit))
|
|
|
|
{
|
|
|
|
out << "in a room." << endl;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isActivityZone(df::building * building)
|
|
|
|
{
|
|
|
|
if( building->getType() == building_type::Civzone
|
|
|
|
&& building->getSubtype() == civzone_type::ActivityZone)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isPenPasture(df::building * building)
|
|
|
|
{
|
|
|
|
if(!isActivityZone(building))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
df::building_civzonest * civ = (df::building_civzonest *) building;
|
|
|
|
|
|
|
|
if(civ->zone_flags.bits.pen_pasture)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-11 06:08:47 -06:00
|
|
|
bool isPitPond(df::building * building)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
|
|
|
if(!isActivityZone(building))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
df::building_civzonest * civ = (df::building_civzonest *) building;
|
|
|
|
|
2012-04-11 06:08:47 -06:00
|
|
|
if(civ->zone_flags.bits.pit_pond) // && civ->pit_flags==0)
|
2012-04-02 08:07:23 -06:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isCage(df::building * building)
|
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
return building->getType() == building_type::Cage;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isChain(df::building * building)
|
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
return building->getType() == building_type::Chain;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isActive(df::building * building)
|
|
|
|
{
|
|
|
|
if(!isActivityZone(building))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
df::building_civzonest * civ = (df::building_civzonest *) building;
|
|
|
|
if(civ->zone_flags.bits.active)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t findBuildingIndexById(int32_t id)
|
|
|
|
{
|
|
|
|
for (size_t b = 0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
if(world->buildings.all.at(b)->id == id)
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-04-16 02:15:37 -06:00
|
|
|
int32_t findUnitIndexById(int32_t id)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
if(world->units.all.at(i)->id == id)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::unit* findUnitById(int32_t id)
|
|
|
|
{
|
|
|
|
int32_t index = findUnitIndexById(id);
|
|
|
|
if(index != -1)
|
|
|
|
return world->units.all[index];
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
// returns id of pen/pit at cursor position (-1 if nothing found)
|
|
|
|
int32_t findPenPitAtCursor()
|
|
|
|
{
|
|
|
|
int32_t foundID = -1;
|
|
|
|
|
|
|
|
if(cursor->x == -30000)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (size_t b = 0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
|
|
|
|
// find zone under cursor
|
|
|
|
if (!(building->x1 <= cursor->x && cursor->x <= building->x2 &&
|
|
|
|
building->y1 <= cursor->y && cursor->y <= building->y2 &&
|
|
|
|
building->z == cursor->z))
|
|
|
|
continue;
|
|
|
|
|
2012-04-11 06:08:47 -06:00
|
|
|
if(isPenPasture(building) || isPitPond(building))
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
|
|
|
foundID = building->id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns id of cage at cursor position (-1 if nothing found)
|
|
|
|
int32_t findCageAtCursor()
|
|
|
|
{
|
|
|
|
int32_t foundID = -1;
|
|
|
|
|
|
|
|
if(cursor->x == -30000)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (size_t b = 0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
|
|
|
|
if (!(building->x1 <= cursor->x && cursor->x <= building->x2 &&
|
|
|
|
building->y1 <= cursor->y && cursor->y <= building->y2 &&
|
|
|
|
building->z == cursor->z))
|
|
|
|
continue;
|
|
|
|
|
2012-04-17 10:11:14 -06:00
|
|
|
// don't set id if cage is not constructed yet
|
|
|
|
if(building->getBuildStage()!=building->getMaxBuildStage())
|
|
|
|
break;
|
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
if(isCage(building))
|
|
|
|
{
|
|
|
|
foundID = building->id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundID;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t findChainAtCursor()
|
|
|
|
{
|
|
|
|
int32_t foundID = -1;
|
|
|
|
|
|
|
|
if(cursor->x == -30000)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (size_t b = 0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
|
|
|
|
// find zone under cursor
|
|
|
|
if (!(building->x1 <= cursor->x && cursor->x <= building->x2 &&
|
|
|
|
building->y1 <= cursor->y && cursor->y <= building->y2 &&
|
|
|
|
building->z == cursor->z))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(isChain(building))
|
|
|
|
{
|
|
|
|
foundID = building->id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundID;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::general_ref_building_civzone_assignedst * createCivzoneRef()
|
|
|
|
{
|
|
|
|
static bool vt_initialized = false;
|
|
|
|
df::general_ref_building_civzone_assignedst* newref = NULL;
|
|
|
|
|
|
|
|
// after having run successfully for the first time it's safe to simply create the object
|
|
|
|
if(vt_initialized)
|
|
|
|
{
|
|
|
|
newref = (df::general_ref_building_civzone_assignedst*)
|
|
|
|
df::general_ref_building_civzone_assignedst::_identity.instantiate();
|
|
|
|
return newref;
|
|
|
|
}
|
|
|
|
|
|
|
|
// being called for the first time, need to initialize the vtable
|
|
|
|
for(size_t i = 0; i < world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit * creature = world->units.all[i];
|
|
|
|
for(size_t r = 0; r<creature->refs.size(); r++)
|
|
|
|
{
|
|
|
|
df::general_ref* ref;
|
|
|
|
ref = creature->refs.at(r);
|
|
|
|
if(ref->getType() == df::general_ref_type::BUILDING_CIVZONE_ASSIGNED)
|
|
|
|
{
|
|
|
|
if (strict_virtual_cast<df::general_ref_building_civzone_assignedst>(ref))
|
|
|
|
{
|
|
|
|
// !! calling new() doesn't work, need _identity.instantiate() instead !!
|
|
|
|
newref = (df::general_ref_building_civzone_assignedst*)
|
|
|
|
df::general_ref_building_civzone_assignedst::_identity.instantiate();
|
|
|
|
vt_initialized = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(vt_initialized)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return newref;
|
|
|
|
}
|
|
|
|
|
2012-04-14 16:35:59 -06:00
|
|
|
bool isInBuiltCage(df::unit* unit);
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
// check if assigned to pen, pit, (built) cage or chain
|
|
|
|
// note: BUILDING_CAGED is not set for animals (maybe it's used for dwarves who get caged as sentence)
|
|
|
|
// animals in cages (no matter if built or on stockpile) get the ref CONTAINED_IN_ITEM instead
|
|
|
|
// removing them from cages on stockpiles is no problem even without clearing the ref
|
|
|
|
// and usually it will be desired behavior to do so.
|
|
|
|
bool isAssigned(df::unit* unit)
|
|
|
|
{
|
|
|
|
bool assigned = false;
|
|
|
|
for (size_t r=0; r < unit->refs.size(); r++)
|
|
|
|
{
|
|
|
|
df::general_ref * ref = unit->refs[r];
|
2012-04-05 03:40:27 -06:00
|
|
|
auto rtype = ref->getType();
|
2012-04-04 06:58:53 -06:00
|
|
|
if( rtype == df::general_ref_type::BUILDING_CIVZONE_ASSIGNED
|
2012-04-05 03:40:27 -06:00
|
|
|
|| rtype == df::general_ref_type::BUILDING_CAGED
|
|
|
|
|| rtype == df::general_ref_type::BUILDING_CHAIN
|
2012-04-14 11:06:03 -06:00
|
|
|
|| (rtype == df::general_ref_type::CONTAINED_IN_ITEM && isInBuiltCage(unit))
|
2012-04-05 03:40:27 -06:00
|
|
|
)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
2012-04-05 03:40:27 -06:00
|
|
|
assigned = true;
|
2012-04-04 06:58:53 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return assigned;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if assigned to a chain or built cage
|
|
|
|
// (need to check if the ref needs to be removed, until then touching them is forbidden)
|
|
|
|
bool isChained(df::unit* unit)
|
|
|
|
{
|
|
|
|
bool contained = false;
|
|
|
|
for (size_t r=0; r < unit->refs.size(); r++)
|
|
|
|
{
|
|
|
|
df::general_ref * ref = unit->refs[r];
|
|
|
|
auto rtype = ref->getType();
|
|
|
|
if(rtype == df::general_ref_type::BUILDING_CHAIN)
|
|
|
|
{
|
|
|
|
contained = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contained;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if contained in item (e.g. animals in cages)
|
|
|
|
bool isContainedInItem(df::unit* unit)
|
|
|
|
{
|
|
|
|
bool contained = false;
|
|
|
|
for (size_t r=0; r < unit->refs.size(); r++)
|
|
|
|
{
|
|
|
|
df::general_ref * ref = unit->refs[r];
|
|
|
|
auto rtype = ref->getType();
|
|
|
|
if(rtype == df::general_ref_type::CONTAINED_IN_ITEM)
|
|
|
|
{
|
|
|
|
contained = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contained;
|
|
|
|
}
|
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
bool isInBuiltCage(df::unit* unit)
|
|
|
|
{
|
|
|
|
bool caged = false;
|
|
|
|
for (size_t b=0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
if( building->getType() == building_type::Cage)
|
|
|
|
{
|
2012-04-14 11:06:03 -06:00
|
|
|
df::building_cagest* cage = (df::building_cagest*) building;
|
|
|
|
for(size_t c=0; c<cage->assigned_creature.size(); c++)
|
2012-04-10 01:15:38 -06:00
|
|
|
{
|
2012-04-14 11:06:03 -06:00
|
|
|
if(cage->assigned_creature[c] == unit->id)
|
2012-04-10 01:15:38 -06:00
|
|
|
{
|
|
|
|
caged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(caged)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return caged;
|
|
|
|
}
|
|
|
|
|
2012-04-16 02:15:37 -06:00
|
|
|
// built cage defined as room (supposed to detect zoo cages)
|
|
|
|
bool isInBuiltCageRoom(df::unit* unit)
|
|
|
|
{
|
|
|
|
bool caged_room = false;
|
|
|
|
for (size_t b=0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
2012-04-16 08:31:12 -06:00
|
|
|
|
2012-04-17 08:57:41 -06:00
|
|
|
// !!! building->isRoom() returns true if the building can be made a room but currently isn't
|
|
|
|
// !!! except for coffins/tombs which always return false
|
|
|
|
// !!! using the bool is_room however gives the correct state/value
|
|
|
|
if(!building->is_room)
|
2012-04-16 08:31:12 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if(building->getType() == building_type::Cage)
|
2012-04-16 02:15:37 -06:00
|
|
|
{
|
|
|
|
df::building_cagest* cage = (df::building_cagest*) building;
|
|
|
|
for(size_t c=0; c<cage->assigned_creature.size(); c++)
|
|
|
|
{
|
|
|
|
if(cage->assigned_creature[c] == unit->id)
|
|
|
|
{
|
|
|
|
caged_room = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(caged_room)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return caged_room;
|
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
// check a map position for a built cage
|
|
|
|
// animals in cages are CONTAINED_IN_ITEM, no matter if they are on a stockpile or inside a built cage
|
|
|
|
// if they are on animal stockpiles they should count as unassigned to allow pasturing them
|
|
|
|
// if they are inside built cages they should be ignored in case the cage is a zoo or linked to a lever or whatever
|
|
|
|
bool isBuiltCageAtPos(df::coord pos)
|
|
|
|
{
|
|
|
|
bool cage = false;
|
|
|
|
for (size_t b=0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
if( building->getType() == building_type::Cage
|
|
|
|
&& building->x1 == pos.x
|
|
|
|
&& building->y1 == pos.y
|
|
|
|
&& building->z == pos.z )
|
|
|
|
{
|
|
|
|
cage = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cage;
|
|
|
|
}
|
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
df::building * getBuiltCageAtPos(df::coord pos)
|
|
|
|
{
|
|
|
|
df::building* cage = NULL;
|
|
|
|
for (size_t b=0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
if( building->getType() == building_type::Cage
|
|
|
|
&& building->x1 == pos.x
|
|
|
|
&& building->y1 == pos.y
|
|
|
|
&& building->z == pos.z )
|
|
|
|
{
|
2012-04-17 10:11:14 -06:00
|
|
|
// don't set pointer if not constructed yet
|
|
|
|
if(building->getBuildStage()!=building->getMaxBuildStage())
|
|
|
|
break;
|
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
cage = building;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cage;
|
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
bool isNestboxAtPos(int32_t x, int32_t y, int32_t z)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
for (size_t b=0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
if( building->getType() == building_type::NestBox
|
|
|
|
&& building->x1 == x
|
|
|
|
&& building->y1 == y
|
|
|
|
&& building->z == z )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2012-04-15 13:45:15 -06:00
|
|
|
bool isFreeNestboxAtPos(int32_t x, int32_t y, int32_t z)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
for (size_t b=0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
if( building->getType() == building_type::NestBox
|
|
|
|
&& building->x1 == x
|
|
|
|
&& building->y1 == y
|
|
|
|
&& building->z == z )
|
|
|
|
{
|
|
|
|
df::building_nest_boxst* nestbox = (df::building_nest_boxst*) building;
|
|
|
|
if(nestbox->claimed_by == -1 && nestbox->contained_items.size() == 1)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
bool isEmptyPasture(df::building* building)
|
|
|
|
{
|
|
|
|
if(!isPenPasture(building))
|
|
|
|
return false;
|
|
|
|
df::building_civzonest * civ = (df::building_civzonest *) building;
|
|
|
|
if(civ->assigned_creature.size() == 0)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building* findFreeNestboxZone()
|
|
|
|
{
|
|
|
|
df::building * free_building = NULL;
|
|
|
|
bool cage = false;
|
|
|
|
for (size_t b=0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
if( isEmptyPasture(building) &&
|
2012-04-05 12:32:44 -06:00
|
|
|
isActive(building) &&
|
2012-04-15 13:45:15 -06:00
|
|
|
isFreeNestboxAtPos(building->x1, building->y1, building->z))
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
free_building = building;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return free_building;
|
|
|
|
}
|
|
|
|
|
2012-04-05 12:32:44 -06:00
|
|
|
bool isFreeEgglayer(df::unit * unit)
|
|
|
|
{
|
2012-04-09 07:03:26 -06:00
|
|
|
if( !isDead(unit) && !isUndead(unit)
|
2012-04-05 12:32:44 -06:00
|
|
|
&& isFemale(unit)
|
2012-04-16 13:37:48 -06:00
|
|
|
&& isDomesticated(unit) // better strict than sorry (medium trained wild animals can revert into wild state)
|
2012-04-05 12:32:44 -06:00
|
|
|
&& isOwnCiv(unit)
|
|
|
|
&& isEggLayer(unit)
|
|
|
|
&& !isAssigned(unit)
|
2012-04-08 04:51:03 -06:00
|
|
|
&& !isGrazer(unit) // exclude grazing birds because they're messy
|
|
|
|
&& !isMerchant(unit) // don't steal merchant mounts
|
|
|
|
&& !isForest(unit) // don't steal birds from traders, they hate that
|
2012-04-05 12:32:44 -06:00
|
|
|
)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
df::unit * findFreeEgglayer()
|
|
|
|
{
|
|
|
|
df::unit* free_unit = NULL;
|
|
|
|
for (size_t i=0; i < world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit* unit = world->units.all[i];
|
2012-04-05 12:32:44 -06:00
|
|
|
if(isFreeEgglayer(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
free_unit = unit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return free_unit;
|
|
|
|
}
|
|
|
|
|
2012-04-05 12:32:44 -06:00
|
|
|
size_t countFreeEgglayers()
|
|
|
|
{
|
|
|
|
size_t count = 0;
|
|
|
|
for (size_t i=0; i < world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit* unit = world->units.all[i];
|
|
|
|
if(isFreeEgglayer(unit))
|
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2012-04-04 06:58:53 -06:00
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
// check if unit is already assigned to a zone, remove that ref from unit and old zone
|
2012-04-10 01:15:38 -06:00
|
|
|
// check if unit is already assigned to a cage, remove that ref from the cage
|
|
|
|
// returns false if no cage or pasture information was found
|
2012-04-02 08:07:23 -06:00
|
|
|
// helps as workaround for http://www.bay12games.com/dwarves/mantisbt/view.php?id=4475 by the way
|
|
|
|
// (pastured animals assigned to chains will get hauled back and forth because the pasture ref is not deleted)
|
2012-04-10 01:15:38 -06:00
|
|
|
bool unassignUnitFromBuilding(df::unit* unit)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
|
|
|
bool success = false;
|
2012-04-04 19:00:10 -06:00
|
|
|
for (std::size_t idx = 0; idx < unit->refs.size(); idx++)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-04 19:00:10 -06:00
|
|
|
df::general_ref * oldref = unit->refs[idx];
|
2012-04-10 01:15:38 -06:00
|
|
|
switch(oldref->getType())
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
case df::general_ref_type::BUILDING_CIVZONE_ASSIGNED:
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
unit->refs.erase(unit->refs.begin() + idx);
|
|
|
|
df::building_civzonest * oldciv = (df::building_civzonest *) oldref->getBuilding();
|
|
|
|
for(size_t oc=0; oc<oldciv->assigned_creature.size(); oc++)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
if(oldciv->assigned_creature[oc] == unit->id)
|
|
|
|
{
|
|
|
|
oldciv->assigned_creature.erase(oldciv->assigned_creature.begin() + oc);
|
|
|
|
break;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
2012-04-10 01:15:38 -06:00
|
|
|
delete oldref;
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case df::general_ref_type::CONTAINED_IN_ITEM:
|
|
|
|
{
|
|
|
|
// game does not erase the ref until creature gets removed from cage
|
|
|
|
//unit->refs.erase(unit->refs.begin() + idx);
|
|
|
|
|
|
|
|
// walk through buildings, check cages for inhabitants, compare ids
|
|
|
|
for (size_t b=0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
df::building* building = world->buildings.all[b];
|
|
|
|
if(isCage(building))
|
|
|
|
{
|
|
|
|
df::building_cagest* oldcage = (df::building_cagest*) building;
|
|
|
|
for(size_t oc=0; oc<oldcage->assigned_creature.size(); oc++)
|
|
|
|
{
|
|
|
|
if(oldcage->assigned_creature[oc] == unit->id)
|
|
|
|
{
|
|
|
|
oldcage->assigned_creature.erase(oldcage->assigned_creature.begin() + oc);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(found)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case df::general_ref_type::BUILDING_CHAIN:
|
|
|
|
{
|
|
|
|
// try not erasing the ref and see what happens
|
|
|
|
//unit->refs.erase(unit->refs.begin() + idx);
|
|
|
|
// probably need to delete chain reference here
|
|
|
|
//success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case df::general_ref_type::BUILDING_CAGED:
|
|
|
|
{
|
|
|
|
// not sure what to do here, doesn't seem to get used by the game
|
|
|
|
//unit->refs.erase(unit->refs.begin() + idx);
|
|
|
|
//success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// some reference which probably shouldn't get deleted
|
|
|
|
// (animals who are historical figures and have a NEMESIS reference or whatever)
|
|
|
|
break;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign to pen or pit
|
|
|
|
command_result assignUnitToZone(color_ostream& out, df::unit* unit, df::building* building, bool verbose = false)
|
|
|
|
{
|
|
|
|
// building must be a pen/pasture or pit
|
2012-04-11 06:08:47 -06:00
|
|
|
if(!isPenPasture(building) && !isPitPond(building))
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-11 06:08:47 -06:00
|
|
|
out << "Invalid building type. This is not a pen/pasture or pit/pond." << endl;
|
2012-04-02 08:07:23 -06:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to get a fresh civzone ref
|
|
|
|
df::general_ref_building_civzone_assignedst * ref = createCivzoneRef();
|
|
|
|
if(!ref)
|
|
|
|
{
|
|
|
|
out << "Could not find a clonable activity zone reference" << endl
|
|
|
|
<< "You need to pen/pasture/pit at least one creature" << endl
|
|
|
|
<< "before using 'assign' for the first time." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if unit is already pastured, remove that ref from unit and old pasture
|
2012-04-10 01:15:38 -06:00
|
|
|
// testing showed that removing the ref from the unit only seems to be necessary for pastured creatures
|
2012-04-04 06:58:53 -06:00
|
|
|
// if they are in cages on stockpiles the game unassigns them automatically
|
2012-04-10 01:15:38 -06:00
|
|
|
// if they are in built cages the pointer to the creature needs to be removed from the cage
|
|
|
|
// TODO: check what needs to be done for chains
|
|
|
|
bool cleared_old = unassignUnitFromBuilding(unit);
|
2012-04-04 06:58:53 -06:00
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
if(verbose)
|
|
|
|
{
|
2012-04-04 06:58:53 -06:00
|
|
|
if(cleared_old)
|
2012-04-02 08:07:23 -06:00
|
|
|
out << "old zone info cleared.";
|
|
|
|
else
|
|
|
|
out << "no old zone info found.";
|
|
|
|
}
|
|
|
|
|
2012-04-05 03:40:27 -06:00
|
|
|
ref->building_id = building->id;
|
2012-04-02 08:07:23 -06:00
|
|
|
unit->refs.push_back(ref);
|
|
|
|
|
|
|
|
df::building_civzonest * civz = (df::building_civzonest *) building;
|
|
|
|
civz->assigned_creature.push_back(unit->id);
|
|
|
|
|
|
|
|
out << "Unit " << unit->id
|
2012-04-09 07:03:26 -06:00
|
|
|
<< "(" << getRaceName(unit) << ")"
|
2012-04-02 08:07:23 -06:00
|
|
|
<< " assigned to zone " << building->id;
|
2012-04-11 06:08:47 -06:00
|
|
|
if(isPitPond(building))
|
|
|
|
out << " (pit/pond).";
|
2012-04-02 08:07:23 -06:00
|
|
|
if(isPenPasture(building))
|
|
|
|
out << " (pen/pasture).";
|
|
|
|
out << endl;
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
command_result assignUnitToCage(color_ostream& out, df::unit* unit, df::building* building, bool verbose)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
// building must be a pen/pasture or pit
|
|
|
|
if(!isCage(building))
|
|
|
|
{
|
|
|
|
out << "Invalid building type. This is not a cage." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
2012-04-15 15:21:36 -06:00
|
|
|
// don't assign owned pets to a cage. the owner will release them, resulting into infinite hauling (df bug)
|
|
|
|
if(unit->relations.pet_owner_id != -1)
|
|
|
|
return CR_OK;
|
2012-04-10 01:15:38 -06:00
|
|
|
|
|
|
|
// check if unit is already pastured or caged, remove refs where necessary
|
|
|
|
bool cleared_old = unassignUnitFromBuilding(unit);
|
|
|
|
if(verbose)
|
|
|
|
{
|
|
|
|
if(cleared_old)
|
|
|
|
out << "old zone info cleared.";
|
|
|
|
else
|
|
|
|
out << "no old zone info found.";
|
|
|
|
}
|
|
|
|
|
|
|
|
//ref->building_id = building->id;
|
|
|
|
//unit->refs.push_back(ref);
|
|
|
|
|
|
|
|
df::building_cagest* civz = (df::building_cagest*) building;
|
|
|
|
civz->assigned_creature.push_back(unit->id);
|
|
|
|
|
|
|
|
out << "Unit " << unit->id
|
|
|
|
<< "(" << getRaceName(unit) << ")"
|
|
|
|
<< " assigned to cage " << building->id;
|
|
|
|
out << endl;
|
|
|
|
|
|
|
|
return CR_OK;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
command_result assignUnitToChain(color_ostream& out, df::unit* unit, df::building* building, bool verbose)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
out << "sorry. assigning to chains is not possible yet." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
command_result assignUnitToBuilding(color_ostream& out, df::unit* unit, df::building* building, bool verbose)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
command_result result = CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
if(isActivityZone(building))
|
|
|
|
result = assignUnitToZone(out, unit, building, verbose);
|
|
|
|
else if(isCage(building))
|
|
|
|
result = assignUnitToCage(out, unit, building, verbose);
|
|
|
|
else if(isChain(building))
|
|
|
|
result = assignUnitToChain(out, unit, building, verbose);
|
|
|
|
else
|
|
|
|
out << "Cannot assign units to this type of building!" << endl;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
|
2012-04-16 08:31:12 -06:00
|
|
|
command_result assignUnitsToCagezone(color_ostream& out, vector<df::unit*> units, df::building* building, bool verbose)
|
|
|
|
{
|
|
|
|
command_result result = CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
if(!isPenPasture(building))
|
|
|
|
{
|
|
|
|
out << "A cage zone needs to be a pen/pasture containing at least one cage!" << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t x1 = building->x1;
|
|
|
|
int32_t x2 = building->x2;
|
|
|
|
int32_t y1 = building->y1;
|
|
|
|
int32_t y2 = building->y2;
|
|
|
|
int32_t z = building->z;
|
|
|
|
vector <df::building_cagest*> cages;
|
|
|
|
for (int32_t x = x1; x<=x2; x++)
|
|
|
|
{
|
|
|
|
for (int32_t y = y1; y<=y2; y++)
|
|
|
|
{
|
|
|
|
df::building* cage = getBuiltCageAtPos(df::coord(x,y,z));
|
|
|
|
if(cage)
|
|
|
|
{
|
|
|
|
df::building_cagest* cagest = (df::building_cagest*) cage;
|
|
|
|
cages.push_back(cagest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!cages.size())
|
|
|
|
{
|
|
|
|
out << "No cages found in this zone!" << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "Number of cages: " << cages.size() << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(units.size())
|
|
|
|
{
|
|
|
|
// hrm, better use sort() instead?
|
|
|
|
df::building_cagest * bestcage = cages[0];
|
|
|
|
size_t lowest = cages[0]->assigned_creature.size();
|
|
|
|
for(size_t i=1; i<cages.size(); i++)
|
|
|
|
{
|
|
|
|
if(cages[i]->assigned_creature.size()<lowest)
|
|
|
|
{
|
|
|
|
lowest = cages[i]->assigned_creature.size();
|
|
|
|
bestcage = cages[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
df::unit* unit = units.back();
|
2012-04-16 13:37:48 -06:00
|
|
|
units.pop_back();
|
2012-04-16 08:31:12 -06:00
|
|
|
command_result result = assignUnitToCage(out, unit, (df::building*) bestcage, verbose);
|
|
|
|
if(result!=CR_OK)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-16 02:15:37 -06:00
|
|
|
command_result nickUnitsInZone(color_ostream& out, df::building* building, string nick)
|
|
|
|
{
|
|
|
|
// building must be a pen/pasture or pit
|
|
|
|
if(!isPenPasture(building) && !isPitPond(building))
|
|
|
|
{
|
|
|
|
out << "Invalid building type. This is not a pen/pasture or pit/pond." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building_civzonest * civz = (df::building_civzonest *) building;
|
|
|
|
for(size_t i = 0; i < civz->assigned_creature.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit* unit = findUnitById(civz->assigned_creature[i]);
|
|
|
|
if(unit)
|
|
|
|
Units::setNickname(unit, nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result nickUnitsInCage(color_ostream& out, df::building* building, string nick)
|
|
|
|
{
|
|
|
|
// building must be a pen/pasture or pit
|
|
|
|
if(!isCage(building))
|
|
|
|
{
|
|
|
|
out << "Invalid building type. This is not a cage." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building_cagest* cage = (df::building_cagest*) building;
|
|
|
|
for(size_t i=0; i<cage->assigned_creature.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit* unit = findUnitById(cage->assigned_creature[i]);
|
|
|
|
if(unit)
|
|
|
|
Units::setNickname(unit, nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result nickUnitsInChain(color_ostream& out, df::building* building, string nick)
|
|
|
|
{
|
|
|
|
out << "sorry. nicknaming chained units is not possible yet." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
2012-04-16 08:31:12 -06:00
|
|
|
// give all units inside a pasture or cage the same nickname
|
|
|
|
// (usage example: protect them from being autobutchered)
|
2012-04-16 02:15:37 -06:00
|
|
|
command_result nickUnitsInBuilding(color_ostream& out, df::building* building, string nick)
|
|
|
|
{
|
|
|
|
command_result result = CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
if(isActivityZone(building))
|
|
|
|
result = nickUnitsInZone(out, building, nick);
|
|
|
|
else if(isCage(building))
|
|
|
|
result = nickUnitsInCage(out, building, nick);
|
|
|
|
else if(isChain(building))
|
|
|
|
result = nickUnitsInChain(out, building, nick);
|
|
|
|
else
|
|
|
|
out << "Cannot nickname units in this type of building!" << endl;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
// dump some zone info
|
2012-04-10 01:15:38 -06:00
|
|
|
void zoneInfo(color_ostream & out, df::building* building, bool verbose)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
|
|
|
if(building->getType()!= building_type::Civzone)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(building->getSubtype() != civzone_type::ActivityZone)
|
|
|
|
return;
|
|
|
|
|
|
|
|
string name;
|
|
|
|
building->getName(&name);
|
|
|
|
out.print("Building %i - \"%s\" - type %s (%i)",
|
|
|
|
building->id,
|
|
|
|
name.c_str(),
|
|
|
|
ENUM_KEY_STR(building_type, building->getType()).c_str(),
|
|
|
|
building->getType());
|
|
|
|
out.print(", subtype %s (%i)",
|
|
|
|
ENUM_KEY_STR(civzone_type, (df::civzone_type)building->getSubtype()).c_str(),
|
|
|
|
building->getSubtype());
|
|
|
|
out.print("\n");
|
|
|
|
|
|
|
|
df::building_civzonest * civ = (df::building_civzonest *) building;
|
|
|
|
if(civ->zone_flags.bits.active)
|
|
|
|
out << "active";
|
|
|
|
else
|
|
|
|
out << "not active";
|
|
|
|
|
|
|
|
if(civ->zone_flags.bits.pen_pasture)
|
|
|
|
out << ", pen/pasture";
|
2012-04-11 06:08:47 -06:00
|
|
|
else if (civ->zone_flags.bits.pit_pond)
|
|
|
|
{
|
|
|
|
out << " (pit flags:" << civ->pit_flags << ")";
|
|
|
|
if(civ->pit_flags & 1)
|
|
|
|
out << ", pond";
|
|
|
|
else
|
|
|
|
out << ", pit";
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
out << endl;
|
2012-04-04 06:58:53 -06:00
|
|
|
out << "x1:" <<building->x1
|
2012-04-05 03:40:27 -06:00
|
|
|
<< " x2:" <<building->x2
|
|
|
|
<< " y1:" <<building->y1
|
|
|
|
<< " y2:" <<building->y2
|
|
|
|
<< " z:" <<building->z
|
|
|
|
<< endl;
|
2012-04-02 08:07:23 -06:00
|
|
|
|
|
|
|
int32_t creaturecount = civ->assigned_creature.size();
|
|
|
|
out << "Creatures in this zone: " << creaturecount << endl;
|
|
|
|
for(size_t c = 0; c < creaturecount; c++)
|
|
|
|
{
|
|
|
|
int32_t cindex = civ->assigned_creature.at(c);
|
|
|
|
|
|
|
|
// print list of all units assigned to that zone
|
|
|
|
for(size_t i = 0; i < world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit * creature = world->units.all[i];
|
|
|
|
if(creature->id != cindex)
|
|
|
|
continue;
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
unitInfo(out, creature, verbose);
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// dump some cage info
|
2012-04-10 01:15:38 -06:00
|
|
|
void cageInfo(color_ostream & out, df::building* building, bool verbose)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
|
|
|
if(!isCage(building))
|
|
|
|
return;
|
|
|
|
|
|
|
|
string name;
|
|
|
|
building->getName(&name);
|
|
|
|
out.print("Building %i - \"%s\" - type %s (%i)",
|
|
|
|
building->id,
|
|
|
|
name.c_str(),
|
|
|
|
ENUM_KEY_STR(building_type, building->getType()).c_str(),
|
|
|
|
building->getType());
|
|
|
|
out.print("\n");
|
|
|
|
|
2012-04-05 03:40:27 -06:00
|
|
|
out << "x:" << building->x1
|
|
|
|
<< " y:" << building->y1
|
|
|
|
<< " z:" << building->z
|
|
|
|
<< endl;
|
2012-04-04 06:58:53 -06:00
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
df::building_cagest * cage = (df::building_cagest*) building;
|
2012-04-16 08:31:12 -06:00
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
int32_t creaturecount = cage->assigned_creature.size();
|
|
|
|
out << "Creatures in this cage: " << creaturecount << endl;
|
|
|
|
for(size_t c = 0; c < creaturecount; c++)
|
|
|
|
{
|
|
|
|
int32_t cindex = cage->assigned_creature.at(c);
|
|
|
|
|
|
|
|
// print list of all units assigned to that cage
|
|
|
|
for(size_t i = 0; i < world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit * creature = world->units.all[i];
|
|
|
|
if(creature->id != cindex)
|
|
|
|
continue;
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
unitInfo(out, creature, verbose);
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// dump some chain/restraint info
|
|
|
|
void chainInfo(color_ostream & out, df::building* building, bool list_refs = false)
|
|
|
|
{
|
|
|
|
if(!isChain(building))
|
|
|
|
return;
|
|
|
|
|
|
|
|
string name;
|
|
|
|
building->getName(&name);
|
|
|
|
out.print("Building %i - \"%s\" - type %s (%i)",
|
|
|
|
building->id,
|
|
|
|
name.c_str(),
|
|
|
|
ENUM_KEY_STR(building_type, building->getType()).c_str(),
|
|
|
|
building->getType());
|
|
|
|
out.print("\n");
|
|
|
|
|
|
|
|
df::building_chainst* chain = (df::building_chainst*) building;
|
2012-04-05 03:40:27 -06:00
|
|
|
if(chain->assigned)
|
|
|
|
{
|
|
|
|
out << "assigned: ";
|
|
|
|
unitInfo(out, chain->assigned, true);
|
|
|
|
}
|
|
|
|
if(chain->chained)
|
|
|
|
{
|
|
|
|
out << "chained: ";
|
|
|
|
unitInfo(out, chain->chained, true);
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
command_result df_zone (color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
|
|
|
|
|
|
|
bool need_cursor = false; // for zone_info, zone_assign, ...
|
|
|
|
bool unit_info = false;
|
|
|
|
bool zone_info = false;
|
|
|
|
//bool cage_info = false;
|
|
|
|
//bool chain_info = false;
|
2012-04-05 03:40:27 -06:00
|
|
|
|
2012-04-15 11:49:50 -06:00
|
|
|
bool invert_filter = false;
|
2012-04-05 03:40:27 -06:00
|
|
|
bool find_unassigned = false;
|
|
|
|
bool find_caged = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_caged = false;
|
2012-04-15 09:40:39 -06:00
|
|
|
bool find_trainable_war = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_trainable_war = false;
|
2012-04-15 09:40:39 -06:00
|
|
|
bool find_trainable_hunting = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_trainable_hunting = false;
|
|
|
|
bool find_trained = false;
|
|
|
|
bool find_not_trained = false;
|
2012-04-05 03:40:27 -06:00
|
|
|
bool find_war = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_war = false;
|
|
|
|
bool find_hunter = false;
|
|
|
|
bool find_not_hunter = false;
|
2012-04-05 03:40:27 -06:00
|
|
|
bool find_own = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_own = false;
|
2012-04-05 03:40:27 -06:00
|
|
|
bool find_tame = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_tame = false;
|
2012-04-08 04:51:03 -06:00
|
|
|
bool find_merchant = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_merchant = false;
|
2012-04-04 06:58:53 -06:00
|
|
|
bool find_male = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_male = false;
|
2012-04-04 06:58:53 -06:00
|
|
|
bool find_female = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_female = false;
|
2012-04-04 06:58:53 -06:00
|
|
|
bool find_egglayer = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_egglayer = false;
|
2012-04-04 06:58:53 -06:00
|
|
|
bool find_grazer = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_grazer = false;
|
2012-04-04 06:58:53 -06:00
|
|
|
bool find_milkable = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_milkable = false;
|
2012-04-05 12:32:44 -06:00
|
|
|
bool find_named = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_named = false;
|
2012-04-20 13:22:20 -06:00
|
|
|
bool find_naked = false;
|
|
|
|
bool find_not_naked = false;
|
2012-04-20 13:38:50 -06:00
|
|
|
bool find_tamable = false;
|
|
|
|
bool find_not_tamable = false;
|
2012-04-04 06:58:53 -06:00
|
|
|
|
|
|
|
bool find_agemin = false;
|
|
|
|
bool find_agemax = false;
|
|
|
|
int target_agemin = 0;
|
|
|
|
int target_agemax = 0;
|
|
|
|
|
|
|
|
bool find_count = false;
|
|
|
|
size_t target_count = 0;
|
|
|
|
|
|
|
|
bool find_race = false;
|
2012-04-15 11:49:50 -06:00
|
|
|
bool find_not_race = false;
|
2012-04-05 03:40:27 -06:00
|
|
|
string target_race = "";
|
2012-04-02 08:07:23 -06:00
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
bool building_assign = false;
|
|
|
|
bool building_unassign = false;
|
|
|
|
bool building_set = false;
|
2012-04-16 08:31:12 -06:00
|
|
|
bool cagezone_assign = false;
|
2012-04-02 08:07:23 -06:00
|
|
|
bool verbose = false;
|
|
|
|
bool all = false;
|
2012-04-05 03:40:27 -06:00
|
|
|
bool unit_slaughter = false;
|
2012-04-10 01:15:38 -06:00
|
|
|
static int target_building = -1;
|
2012-04-16 02:15:37 -06:00
|
|
|
bool nick_set = false;
|
|
|
|
string target_nick = "";
|
2012-04-02 08:07:23 -06:00
|
|
|
|
|
|
|
for (size_t i = 0; i < parameters.size(); i++)
|
|
|
|
{
|
|
|
|
string & p = parameters[i];
|
|
|
|
|
|
|
|
if (p == "help" || p == "?")
|
|
|
|
{
|
|
|
|
out << zone_help << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-04-04 06:58:53 -06:00
|
|
|
if (p == "filters")
|
|
|
|
{
|
|
|
|
out << zone_help_filters << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
if (p == "examples")
|
|
|
|
{
|
|
|
|
out << zone_help_examples << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
else if(p == "zinfo")
|
|
|
|
{
|
|
|
|
zone_info = true;
|
2012-04-15 11:49:50 -06:00
|
|
|
invert_filter=false;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
else if(p == "uinfo")
|
|
|
|
{
|
|
|
|
unit_info = true;
|
2012-04-15 11:49:50 -06:00
|
|
|
invert_filter=false;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
else if(p == "verbose")
|
|
|
|
{
|
|
|
|
verbose = true;
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
{
|
|
|
|
verbose = false;
|
|
|
|
invert_filter=false;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
else if(p == "unassign")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
{
|
|
|
|
out << "'not unassign' makes no sense." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
2012-04-10 01:15:38 -06:00
|
|
|
building_unassign = true;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
else if(p == "assign")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
{
|
|
|
|
out << "'not assign' makes no sense. (did you want to use unassign?)" << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
2012-04-04 08:48:22 -06:00
|
|
|
// if followed by another parameter, check if it's numeric
|
|
|
|
if(i < parameters.size()-1)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-04 08:48:22 -06:00
|
|
|
stringstream ss(parameters[i+1]);
|
2012-04-10 01:15:38 -06:00
|
|
|
int new_building = -1;
|
|
|
|
ss >> new_building;
|
|
|
|
if(new_building != -1)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-04 08:48:22 -06:00
|
|
|
i++;
|
2012-04-10 01:15:38 -06:00
|
|
|
target_building = new_building;
|
|
|
|
out << "Assign selected unit(s) to building #" << target_building <<std::endl;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 01:15:38 -06:00
|
|
|
if(target_building == -1)
|
2012-04-04 08:48:22 -06:00
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
out.printerr("No building id specified and current one is invalid!\n");
|
2012-04-04 08:48:22 -06:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
else
|
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
out << "No buiding id specified. Will try to use #" << target_building << endl;
|
|
|
|
building_assign = true;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-16 08:31:12 -06:00
|
|
|
else if(p == "tocages")
|
|
|
|
{
|
|
|
|
if(invert_filter)
|
|
|
|
{
|
|
|
|
out << "'not tocages' makes no sense." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if followed by another parameter, check if it's numeric
|
|
|
|
if(i < parameters.size()-1)
|
|
|
|
{
|
|
|
|
stringstream ss(parameters[i+1]);
|
|
|
|
int new_building = -1;
|
|
|
|
ss >> new_building;
|
|
|
|
if(new_building != -1)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
target_building = new_building;
|
|
|
|
out << "Assign selected unit(s) to cagezone #" << target_building <<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(target_building == -1)
|
|
|
|
{
|
|
|
|
out.printerr("No building id specified and current one is invalid!\n");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "No buiding id specified. Will try to use #" << target_building << endl;
|
|
|
|
cagezone_assign = true;
|
|
|
|
}
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "race" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
if(i == parameters.size()-1)
|
|
|
|
{
|
|
|
|
out.printerr("No race id specified!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-05 03:40:27 -06:00
|
|
|
target_race = parameters[i+1];
|
2012-04-04 06:58:53 -06:00
|
|
|
i++;
|
|
|
|
out << "Filter by race " << target_race << endl;
|
|
|
|
find_race = true;
|
|
|
|
}
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "race" && invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(i == parameters.size()-1)
|
|
|
|
{
|
|
|
|
out.printerr("No race id specified!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target_race = parameters[i+1];
|
|
|
|
i++;
|
|
|
|
out << "Excluding race: " << target_race << endl;
|
|
|
|
find_not_race = true;
|
|
|
|
}
|
|
|
|
invert_filter = false;
|
|
|
|
}
|
|
|
|
else if(p == "not")
|
|
|
|
{
|
|
|
|
invert_filter = true;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
|
|
|
else if(p == "unassigned")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-04 06:58:53 -06:00
|
|
|
out << "Filter by 'unassigned'." << endl;
|
|
|
|
find_unassigned = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "caged" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
out << "Filter by 'caged' (ignores built cages)." << endl;
|
|
|
|
find_caged = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "caged" && invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'not caged'." << endl;
|
|
|
|
find_not_caged = true;
|
|
|
|
invert_filter = false;
|
|
|
|
}
|
|
|
|
else if(p == "trained" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
out << "Filter by 'trained'." << endl;
|
|
|
|
find_trained = true;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "trained" && invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
out << "Filter by 'untrained'." << endl;
|
2012-04-15 11:49:50 -06:00
|
|
|
find_not_trained = true;
|
|
|
|
invert_filter = false;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "trainablewar" && !invert_filter)
|
2012-04-15 09:40:39 -06:00
|
|
|
{
|
|
|
|
out << "Filter by 'trainable for war'." << endl;
|
|
|
|
find_trainable_war = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "trainablewar" && invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'not trainable for war'." << endl;
|
|
|
|
find_not_trainable_war = true;
|
|
|
|
invert_filter = false;
|
|
|
|
}
|
|
|
|
else if(p == "trainablehunt"&& !invert_filter)
|
2012-04-15 09:40:39 -06:00
|
|
|
{
|
|
|
|
out << "Filter by 'trainable for hunting'." << endl;
|
|
|
|
find_trainable_hunting = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "trainablehunt"&& invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'not trainable for hunting'." << endl;
|
|
|
|
find_not_trainable_hunting = true;
|
|
|
|
invert_filter = false;
|
|
|
|
}
|
|
|
|
else if(p == "war" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
out << "Filter by 'trained war creature'." << endl;
|
|
|
|
find_war = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "war" && invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'not a trained war creature'." << endl;
|
|
|
|
find_not_war = true;
|
|
|
|
invert_filter = false;
|
|
|
|
}
|
2012-04-15 19:31:49 -06:00
|
|
|
else if(p == "hunting" && !invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'trained hunting creature'." << endl;
|
|
|
|
find_hunter = true;
|
|
|
|
}
|
|
|
|
else if(p == "hunting" && invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'not a trained hunting creature'." << endl;
|
|
|
|
find_not_hunter = true;
|
|
|
|
invert_filter = false;
|
|
|
|
}else if(p == "own"&& !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
out << "Filter by 'own civilization'." << endl;
|
|
|
|
find_own = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "own" && invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'not own' (i.e. not from the fortress civ, can be a dwarf)." << endl;
|
|
|
|
find_not_own = true;
|
|
|
|
invert_filter = false;
|
|
|
|
}
|
|
|
|
else if(p == "tame" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
out << "Filter by 'tame'." << endl;
|
|
|
|
find_tame = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "tame" && invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'not tame'." << endl;
|
|
|
|
find_not_tame = true;
|
|
|
|
invert_filter=false;
|
|
|
|
}
|
|
|
|
else if(p == "named" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
out << "Filter by 'has name or nickname'." << endl;
|
|
|
|
find_named = true;
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "named" && invert_filter)
|
|
|
|
{
|
|
|
|
out << "Filter by 'has no name or nickname'." << endl;
|
|
|
|
find_not_named = true;
|
|
|
|
invert_filter=false;
|
|
|
|
}
|
2012-04-05 03:40:27 -06:00
|
|
|
else if(p == "slaughter")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-05 03:40:27 -06:00
|
|
|
out << "Assign animals for slaughter." << endl;
|
|
|
|
unit_slaughter = true;
|
|
|
|
}
|
2012-04-04 06:58:53 -06:00
|
|
|
else if(p == "count")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-04 06:58:53 -06:00
|
|
|
if(i == parameters.size()-1)
|
|
|
|
{
|
|
|
|
out.printerr("No count specified!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stringstream ss(parameters[i+1]);
|
|
|
|
i++;
|
|
|
|
ss >> target_count;
|
|
|
|
if(target_count <= 0)
|
|
|
|
{
|
|
|
|
out.printerr("Invalid count specified (must be > 0)!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
find_count = true;
|
|
|
|
out << "Process up to " << target_count << " units." << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(p == "age")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-04 06:58:53 -06:00
|
|
|
if(i == parameters.size()-1)
|
|
|
|
{
|
|
|
|
out.printerr("No age specified!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stringstream ss(parameters[i+1]);
|
|
|
|
i++;
|
|
|
|
ss >> target_agemin;
|
|
|
|
ss >> target_agemax;
|
|
|
|
find_agemin = true;
|
|
|
|
find_agemax = true;
|
|
|
|
out << "Filter by exact age of " << target_agemin << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(p == "minage")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-04 06:58:53 -06:00
|
|
|
if(i == parameters.size()-1)
|
|
|
|
{
|
|
|
|
out.printerr("No age specified!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stringstream ss(parameters[i+1]);
|
|
|
|
i++;
|
|
|
|
ss >> target_agemin;
|
|
|
|
find_agemin = true;
|
|
|
|
out << "Filter by minimum age of " << target_agemin << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(p == "maxage")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-04 06:58:53 -06:00
|
|
|
if(i == parameters.size()-1)
|
|
|
|
{
|
|
|
|
out.printerr("No age specified!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stringstream ss(parameters[i+1]);
|
|
|
|
i++;
|
|
|
|
ss >> target_agemax;
|
|
|
|
find_agemax = true;
|
|
|
|
out << "Filter by maximum age of " << target_agemax << endl;
|
|
|
|
}
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "male" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
find_male = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "female" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
find_female = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "egglayer" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
find_egglayer = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "egglayer" && invert_filter)
|
|
|
|
{
|
|
|
|
find_not_egglayer = true;
|
|
|
|
invert_filter=false;
|
|
|
|
}
|
2012-04-20 13:22:20 -06:00
|
|
|
else if(p == "naked" && !invert_filter)
|
|
|
|
{
|
|
|
|
find_naked = true;
|
|
|
|
}
|
|
|
|
else if(p == "naked" && invert_filter)
|
|
|
|
{
|
|
|
|
find_not_naked = true;
|
|
|
|
invert_filter=false;
|
|
|
|
}
|
2012-04-20 13:38:50 -06:00
|
|
|
else if(p == "tamable" && !invert_filter)
|
|
|
|
{
|
|
|
|
find_tamable = true;
|
|
|
|
}
|
|
|
|
else if(p == "tamable" && invert_filter)
|
|
|
|
{
|
|
|
|
find_not_tamable = true;
|
|
|
|
invert_filter=false;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "grazer" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
find_grazer = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "grazer" && invert_filter)
|
2012-04-09 20:10:07 -06:00
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
find_not_grazer = true;
|
|
|
|
invert_filter=false;
|
2012-04-09 20:10:07 -06:00
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "merchant" && !invert_filter)
|
2012-04-08 04:51:03 -06:00
|
|
|
{
|
|
|
|
find_merchant = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "merchant" && invert_filter)
|
|
|
|
{
|
|
|
|
// actually 'not merchant' is pointless since merchant units are ignored by default
|
|
|
|
find_not_merchant = true;
|
|
|
|
invert_filter=false;
|
|
|
|
}
|
|
|
|
else if(p == "milkable" && !invert_filter)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
find_milkable = true;
|
|
|
|
}
|
2012-04-15 11:49:50 -06:00
|
|
|
else if(p == "milkable" && invert_filter)
|
|
|
|
{
|
|
|
|
find_not_milkable = true;
|
|
|
|
invert_filter=false;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
else if(p == "set")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-10 01:15:38 -06:00
|
|
|
building_set = true;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
2012-04-16 02:15:37 -06:00
|
|
|
else if(p == "nick")
|
|
|
|
{
|
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
if(i == parameters.size()-1)
|
|
|
|
{
|
|
|
|
out.printerr("No nickname specified! Use 'remnick' to remove nicknames!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
nick_set = true;
|
|
|
|
target_nick = parameters[i+1];
|
|
|
|
i++;
|
|
|
|
out << "Set nickname to: " << target_nick << endl;
|
|
|
|
}
|
|
|
|
else if(p == "remnick")
|
|
|
|
{
|
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
nick_set = true;
|
|
|
|
target_nick = "";
|
|
|
|
i++;
|
|
|
|
out << "Remove nickname." << endl;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
else if(p == "all")
|
|
|
|
{
|
2012-04-15 11:49:50 -06:00
|
|
|
if(invert_filter)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-04 08:48:22 -06:00
|
|
|
out << "Filter: all" << endl;
|
2012-04-02 08:07:23 -06:00
|
|
|
all = true;
|
|
|
|
}
|
|
|
|
else
|
2012-04-05 03:40:27 -06:00
|
|
|
{
|
|
|
|
out << "Unknown command: " << p << endl;
|
2012-04-02 08:07:23 -06:00
|
|
|
return CR_WRONG_USAGE;
|
2012-04-05 03:40:27 -06:00
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
2012-04-05 12:32:44 -06:00
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
|
|
|
out.printerr("Map is not available!\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
if((zone_info && !all) || building_set)
|
2012-04-02 08:07:23 -06:00
|
|
|
need_cursor = true;
|
|
|
|
|
|
|
|
if(need_cursor && cursor->x == -30000)
|
|
|
|
{
|
|
|
|
out.printerr("No cursor; place cursor over activity zone.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-04-15 11:49:50 -06:00
|
|
|
// search for male and not male is exclusive, so drop the flags if both are specified
|
|
|
|
if(find_male && find_not_male)
|
|
|
|
{
|
|
|
|
find_male=false;
|
|
|
|
find_not_male=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// search for female and not female is exclusive, so drop the flags if both are specified
|
|
|
|
if(find_female && find_not_female)
|
|
|
|
{
|
|
|
|
find_female=false;
|
|
|
|
find_not_female=false;
|
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
// search for male and female is exclusive, so drop the flags if both are specified
|
|
|
|
if(find_male && find_female)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-04 06:58:53 -06:00
|
|
|
find_male=false;
|
|
|
|
find_female=false;
|
|
|
|
}
|
|
|
|
|
2012-04-09 20:10:07 -06:00
|
|
|
// search for trained and untrained is exclusive, so drop the flags if both are specified
|
2012-04-15 15:21:36 -06:00
|
|
|
if(find_trained && find_not_trained)
|
|
|
|
{
|
|
|
|
find_trained=false;
|
|
|
|
find_not_trained=false;
|
|
|
|
}
|
2012-04-09 20:10:07 -06:00
|
|
|
|
|
|
|
// search for grazer and nograzer is exclusive, so drop the flags if both are specified
|
2012-04-15 11:49:50 -06:00
|
|
|
if(find_grazer && find_not_grazer)
|
2012-04-09 20:10:07 -06:00
|
|
|
{
|
|
|
|
find_grazer=false;
|
2012-04-15 11:49:50 -06:00
|
|
|
find_not_grazer=false;
|
2012-04-09 20:10:07 -06:00
|
|
|
}
|
|
|
|
|
2012-04-15 15:21:36 -06:00
|
|
|
// todo: maybe add this type of sanity check for all remaining bools, maybe not (lots of code just to avoid parsing dumb input)
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
// try to cope with user dumbness
|
2012-04-05 12:32:44 -06:00
|
|
|
if(target_agemin > target_agemax)
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
out << "Invalid values for minage/maxage specified! I'll swap them." << endl;
|
|
|
|
int oldmin = target_agemin;
|
|
|
|
target_agemin = target_agemax;
|
|
|
|
target_agemax = oldmin;
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:07:23 -06:00
|
|
|
// give info on zone(s), chain or cage under cursor
|
|
|
|
// (doesn't use the findXyzAtCursor() methods because zones might overlap and contain a cage or chain)
|
|
|
|
if(zone_info) // || chain_info || cage_info)
|
|
|
|
{
|
|
|
|
for (size_t b = 0; b < world->buildings.all.size(); b++)
|
|
|
|
{
|
|
|
|
df::building * building = world->buildings.all[b];
|
|
|
|
|
|
|
|
// find building under cursor
|
|
|
|
if (!all &&
|
|
|
|
!(building->x1 <= cursor->x && cursor->x <= building->x2 &&
|
2012-04-17 08:57:41 -06:00
|
|
|
building->y1 <= cursor->y && cursor->y <= building->y2 &&
|
|
|
|
building->z == cursor->z))
|
2012-04-02 08:07:23 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
zoneInfo(out, building, verbose);
|
|
|
|
chainInfo(out, building, verbose);
|
|
|
|
cageInfo(out, building, verbose);
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-10 01:15:38 -06:00
|
|
|
// set building at cursor position to be new target building
|
|
|
|
if(building_set)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-16 08:31:12 -06:00
|
|
|
// cagezone wants a pen/pit as starting point
|
|
|
|
if(!cagezone_assign)
|
|
|
|
target_building = findCageAtCursor();
|
2012-04-10 01:15:38 -06:00
|
|
|
if(target_building != -1)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
out << "Target building type: cage." << endl;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
2012-04-10 01:15:38 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
target_building = findPenPitAtCursor();
|
|
|
|
if(target_building == -1)
|
|
|
|
{
|
|
|
|
out << "No pen/pasture or pit under cursor!" << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "Target building type: pen/pasture or pit." << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out << "Current building set to #" << target_building << endl;
|
2012-04-02 08:07:23 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-16 08:31:12 -06:00
|
|
|
if(building_assign || cagezone_assign || unit_info || unit_slaughter || nick_set)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-04 06:58:53 -06:00
|
|
|
df::building * building;
|
2012-04-16 08:31:12 -06:00
|
|
|
if(building_assign || cagezone_assign || (nick_set && !all && !find_count))
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
2012-04-05 03:40:27 -06:00
|
|
|
// try to get building index from the id
|
2012-04-10 01:15:38 -06:00
|
|
|
int32_t index = findBuildingIndexById(target_building);
|
2012-04-04 06:58:53 -06:00
|
|
|
if(index == -1)
|
|
|
|
{
|
|
|
|
out << "Invalid building id." << endl;
|
2012-04-10 01:15:38 -06:00
|
|
|
target_building = -1;
|
2012-04-04 06:58:53 -06:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
building = world->buildings.all.at(index);
|
2012-04-16 02:15:37 -06:00
|
|
|
|
|
|
|
if(nick_set && !building_assign)
|
|
|
|
{
|
|
|
|
out << "Renaming all units in target building." << endl;
|
|
|
|
return nickUnitsInBuilding(out, building, target_nick);
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
if(all || find_count)
|
|
|
|
{
|
2012-04-16 08:31:12 -06:00
|
|
|
vector <df::unit*> units_for_cagezone;
|
2012-04-04 06:58:53 -06:00
|
|
|
size_t count = 0;
|
|
|
|
for(size_t c = 0; c < world->units.all.size(); c++)
|
|
|
|
{
|
|
|
|
df::unit *unit = world->units.all[c];
|
2012-04-07 19:36:29 -06:00
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
// ignore dead and undead units
|
|
|
|
if (isDead(unit) || isUndead(unit))
|
2012-04-08 04:51:03 -06:00
|
|
|
continue;
|
2012-04-07 19:36:29 -06:00
|
|
|
|
2012-04-08 04:51:03 -06:00
|
|
|
// ignore merchant units by default
|
|
|
|
if (!find_merchant && (isMerchant(unit) || isForest(unit)))
|
|
|
|
continue;
|
|
|
|
// but allow pitting them and stealing from them if specified :)
|
|
|
|
if (find_merchant && !isMerchant(unit) && !isForest(unit))
|
|
|
|
continue;
|
2012-04-08 00:07:29 -06:00
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
if(find_race && getRaceName(unit) != target_race)
|
|
|
|
continue;
|
2012-04-15 11:49:50 -06:00
|
|
|
if(find_not_race && getRaceName(unit) == target_race)
|
|
|
|
continue;
|
2012-04-04 06:58:53 -06:00
|
|
|
// ignore own dwarves by default
|
|
|
|
if(isOwnCiv(unit) && isOwnRace(unit))
|
|
|
|
{
|
|
|
|
if(!find_race)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (find_unassigned && isAssigned(unit))
|
2012-04-10 01:15:38 -06:00
|
|
|
// avoid tampering with creatures who are currently being hauled to a built cage
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (isContainedInItem(unit) && (find_not_caged || isInBuiltCage(unit)))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (isChained(unit))
|
|
|
|
|| (find_caged && !isContainedInItem(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_caged && isContainedInItem(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (find_own && !isOwnCiv(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_own && isOwnCiv(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (find_tame && !isTame(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_tame && isTame(unit))
|
|
|
|
|| (find_trained && !isTrained(unit))
|
|
|
|
|| (find_not_trained && isTrained(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (find_war && !isWar(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_war && isWar(unit))
|
|
|
|
|| (find_hunter && !isHunter(unit))
|
|
|
|
|| (find_not_hunter && isHunter(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (find_agemin && getUnitAge(unit)<target_agemin)
|
|
|
|
|| (find_agemax && getUnitAge(unit)>target_agemax)
|
|
|
|
|| (find_grazer && !isGrazer(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_grazer && isGrazer(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (find_egglayer && !isEggLayer(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_egglayer && isEggLayer(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (find_milkable && !isMilkable(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_milkable && isMilkable(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (find_male && !isMale(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_male && isMale(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
|| (find_female && !isFemale(unit))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_female && isFemale(unit))
|
2012-04-05 12:32:44 -06:00
|
|
|
|| (find_named && !unit->name.has_name)
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_named && unit->name.has_name)
|
2012-04-20 13:22:20 -06:00
|
|
|
|| (find_naked && !isNaked(unit))
|
|
|
|
|| (find_not_naked && isNaked(unit))
|
2012-04-20 13:38:50 -06:00
|
|
|
|| (find_tamable && !isTamable(unit))
|
|
|
|
|| (find_not_tamable && isTamable(unit))
|
2012-04-15 09:40:39 -06:00
|
|
|
|| (find_trainable_war && (isWar(unit) || isHunter(unit) || !isTrainableWar(unit)))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_trainable_war && isTrainableWar(unit)) // hm, is this check enough?
|
2012-04-15 09:40:39 -06:00
|
|
|
|| (find_trainable_hunting && (isWar(unit) || isHunter(unit) || !isTrainableHunting(unit)))
|
2012-04-15 11:49:50 -06:00
|
|
|
|| (find_not_trainable_hunting && isTrainableHunting(unit)) // hm, is this check enough?
|
2012-04-04 06:58:53 -06:00
|
|
|
)
|
|
|
|
continue;
|
|
|
|
|
2012-04-06 22:47:32 -06:00
|
|
|
// animals bought in cages have an invalid map pos until they are freed for the first time
|
|
|
|
// but if they are not in a cage and have an invalid pos it's better not to touch them
|
|
|
|
if(!isContainedInItem(unit) && !hasValidMapPos(unit))
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-06 22:47:32 -06:00
|
|
|
if(verbose)
|
|
|
|
{
|
|
|
|
out << "----------"<<endl;
|
|
|
|
out << "invalid unit pos but not in cage either. will skip this unit." << endl;
|
|
|
|
unitInfo(out, unit, verbose);
|
|
|
|
out << "----------"<<endl;
|
|
|
|
}
|
2012-04-06 18:31:10 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
if(unit_info)
|
|
|
|
{
|
|
|
|
unitInfo(out, unit, verbose);
|
2012-04-16 02:15:37 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nick_set)
|
|
|
|
{
|
|
|
|
Units::setNickname(unit, target_nick);
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
2012-04-16 08:31:12 -06:00
|
|
|
|
|
|
|
if(cagezone_assign)
|
|
|
|
{
|
|
|
|
units_for_cagezone.push_back(unit);
|
|
|
|
}
|
|
|
|
else if(building_assign)
|
2012-04-15 15:21:36 -06:00
|
|
|
{
|
2012-04-04 06:58:53 -06:00
|
|
|
command_result result = assignUnitToBuilding(out, unit, building, verbose);
|
|
|
|
if(result != CR_OK)
|
|
|
|
return result;
|
|
|
|
}
|
2012-04-16 02:15:37 -06:00
|
|
|
|
|
|
|
if(unit_slaughter)
|
2012-04-05 03:40:27 -06:00
|
|
|
{
|
2012-04-05 12:32:44 -06:00
|
|
|
// don't slaughter named creatures unless told to do so
|
2012-04-16 08:31:12 -06:00
|
|
|
if(!unit->name.has_name || find_named)
|
|
|
|
doMarkForSlaughter(unit);
|
2012-04-05 03:40:27 -06:00
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
count++;
|
|
|
|
if(find_count && count >= target_count)
|
|
|
|
break;
|
|
|
|
}
|
2012-04-16 08:31:12 -06:00
|
|
|
if(cagezone_assign)
|
|
|
|
{
|
|
|
|
command_result result = assignUnitsToCagezone(out, units_for_cagezone, building, verbose);
|
|
|
|
if(result != CR_OK)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
out << "Processed creatures: " << count << endl;
|
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
else
|
2012-04-04 06:58:53 -06:00
|
|
|
{
|
|
|
|
// must have unit selected
|
2012-04-17 08:57:41 -06:00
|
|
|
df::unit *unit = getSelectedUnit(out, true);
|
2012-04-04 06:58:53 -06:00
|
|
|
if (!unit)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
if(unit_info)
|
|
|
|
{
|
|
|
|
unitInfo(out, unit, verbose);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-04-10 01:15:38 -06:00
|
|
|
else if(building_assign)
|
2012-04-05 03:40:27 -06:00
|
|
|
{
|
|
|
|
return assignUnitToBuilding(out, unit, building, verbose);
|
|
|
|
}
|
|
|
|
else if(unit_slaughter)
|
|
|
|
{
|
2012-04-16 13:37:48 -06:00
|
|
|
// by default behave like the game? only allow slaughtering of named war/hunting pets
|
2012-04-05 12:32:44 -06:00
|
|
|
//if(unit->name.has_name && !find_named && !(isWar(unit)||isHunter(unit)))
|
|
|
|
//{
|
|
|
|
// out << "Slaughter of named unit denied. Use the filter 'named' to override this check." << endl;
|
|
|
|
// return CR_OK;
|
|
|
|
//}
|
|
|
|
|
2012-04-05 03:40:27 -06:00
|
|
|
doMarkForSlaughter(unit);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-04-04 06:58:53 -06:00
|
|
|
}
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
// de-assign from pen or pit
|
|
|
|
// using the zone tool to free creatures from cages or chains
|
|
|
|
// is pointless imo since that is already quite easy using the ingame UI.
|
|
|
|
// but it's easy to implement so I might as well add it later
|
2012-04-10 01:15:38 -06:00
|
|
|
if(building_unassign)
|
2012-04-02 08:07:23 -06:00
|
|
|
{
|
|
|
|
// must have unit selected
|
2012-04-17 08:57:41 -06:00
|
|
|
df::unit *unit = getSelectedUnit(out, true);
|
2012-04-02 08:07:23 -06:00
|
|
|
if (!unit)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
// remove assignment reference from unit and old zone
|
2012-04-10 01:15:38 -06:00
|
|
|
if(unassignUnitFromBuilding(unit))
|
2012-04-04 06:58:53 -06:00
|
|
|
out << "Unit unassigned." << endl;
|
|
|
|
else
|
|
|
|
out << "Unit is not assigned to an activity zone!" << endl;
|
2012-04-17 08:57:41 -06:00
|
|
|
|
2012-04-04 06:58:53 -06:00
|
|
|
return CR_OK;
|
2012-04-02 08:07:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-04-05 12:32:44 -06:00
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
////////////////////
|
|
|
|
// autonestbox stuff
|
|
|
|
|
2012-04-05 12:32:44 -06:00
|
|
|
command_result df_autonestbox(color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
|
|
|
|
|
|
|
bool verbose = false;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < parameters.size(); i++)
|
|
|
|
{
|
|
|
|
string & p = parameters[i];
|
|
|
|
|
|
|
|
if (p == "help" || p == "?")
|
|
|
|
{
|
|
|
|
out << autonestbox_help << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
if (p == "start")
|
|
|
|
{
|
|
|
|
autonestbox_did_complain = false;
|
2012-04-09 07:03:26 -06:00
|
|
|
start_autonestbox(out);
|
2012-04-05 12:32:44 -06:00
|
|
|
return autoNestbox(out, verbose);
|
|
|
|
}
|
|
|
|
if (p == "stop")
|
|
|
|
{
|
|
|
|
enable_autonestbox = false;
|
2012-04-09 07:03:26 -06:00
|
|
|
if(config_autonestbox.isValid())
|
|
|
|
config_autonestbox.ival(0) = 0;
|
|
|
|
out << "Autonestbox stopped." << endl;
|
2012-04-05 12:32:44 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else if(p == "verbose")
|
|
|
|
{
|
|
|
|
verbose = true;
|
|
|
|
}
|
|
|
|
else if(p == "sleep")
|
|
|
|
{
|
|
|
|
if(i == parameters.size()-1)
|
|
|
|
{
|
|
|
|
out.printerr("No duration specified!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t ticks = 0;
|
|
|
|
stringstream ss(parameters[i+1]);
|
|
|
|
i++;
|
|
|
|
ss >> ticks;
|
|
|
|
if(ticks <= 0)
|
|
|
|
{
|
|
|
|
out.printerr("Invalid duration specified (must be > 0)!");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
sleep_autonestbox = ticks;
|
2012-04-09 07:03:26 -06:00
|
|
|
if(config_autonestbox.isValid())
|
|
|
|
config_autonestbox.ival(1) = sleep_autonestbox;
|
2012-04-05 12:32:44 -06:00
|
|
|
out << "New sleep timer for autonestbox: " << ticks << " ticks." << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "Unknown command: " << p << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return autoNestbox(out, verbose);
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result autoNestbox( color_ostream &out, bool verbose = false )
|
|
|
|
{
|
|
|
|
bool stop = false;
|
|
|
|
size_t processed = 0;
|
|
|
|
|
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
|
|
|
out.printerr("Map is not available!\n");
|
|
|
|
enable_autonestbox = false;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
df::building * free_building = findFreeNestboxZone();
|
|
|
|
df::unit * free_unit = findFreeEgglayer();
|
|
|
|
if(free_building && free_unit)
|
|
|
|
{
|
|
|
|
command_result result = assignUnitToBuilding(out, free_unit, free_building, verbose);
|
|
|
|
if(result != CR_OK)
|
|
|
|
return result;
|
|
|
|
processed ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stop = true;
|
|
|
|
if(free_unit && !free_building)
|
|
|
|
{
|
|
|
|
static size_t old_count = 0;
|
|
|
|
size_t freeEgglayers = countFreeEgglayers();
|
|
|
|
// avoid spamming the same message
|
|
|
|
if(old_count != freeEgglayers)
|
|
|
|
autonestbox_did_complain = false;
|
|
|
|
old_count = freeEgglayers;
|
|
|
|
if(!autonestbox_did_complain)
|
|
|
|
{
|
|
|
|
stringstream ss;
|
|
|
|
ss << freeEgglayers;
|
|
|
|
string announce = "Not enough free nestbox zones found! You need " + ss.str() + " more.";
|
|
|
|
Gui::showAnnouncement(announce, 6, true);
|
|
|
|
out << announce << endl;
|
|
|
|
autonestbox_did_complain = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!stop);
|
|
|
|
if(processed > 0)
|
|
|
|
{
|
|
|
|
stringstream ss;
|
|
|
|
ss << processed;
|
|
|
|
string announce;
|
|
|
|
announce = ss.str() + " nestboxes were assigned.";
|
|
|
|
Gui::showAnnouncement(announce, 2, false);
|
|
|
|
out << announce << endl;
|
|
|
|
// can complain again
|
|
|
|
// (might lead to spamming the same message twice, but catches the case
|
|
|
|
// where for example 2 new egglayers hatched right after 2 zones were created and assigned)
|
|
|
|
autonestbox_did_complain = false;
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
////////////////////
|
|
|
|
// autobutcher stuff
|
2012-04-06 18:31:10 -06:00
|
|
|
|
|
|
|
// getUnitAge() returns 0 if born in current year, therefore the look at birth_time in that case
|
|
|
|
// (assuming that the value from there indicates in which tick of the current year the unit was born)
|
|
|
|
bool compareUnitAgesYounger(df::unit* i, df::unit* j)
|
|
|
|
{
|
|
|
|
int32_t age_i = getUnitAge(i);
|
|
|
|
int32_t age_j = getUnitAge(j);
|
|
|
|
if(age_i == 0 && age_j == 0)
|
|
|
|
{
|
|
|
|
age_i = i->relations.birth_time;
|
|
|
|
age_j = j->relations.birth_time;
|
|
|
|
}
|
|
|
|
return (age_i < age_j);
|
|
|
|
}
|
|
|
|
bool compareUnitAgesOlder(df::unit* i, df::unit* j)
|
|
|
|
{
|
|
|
|
int32_t age_i = getUnitAge(i);
|
|
|
|
int32_t age_j = getUnitAge(j);
|
|
|
|
if(age_i == 0 && age_j == 0)
|
|
|
|
{
|
|
|
|
age_i = i->relations.birth_time;
|
|
|
|
age_j = j->relations.birth_time;
|
|
|
|
}
|
|
|
|
return (age_i > age_j);
|
|
|
|
}
|
|
|
|
|
|
|
|
//enum WatchedRaceSubtypes
|
|
|
|
//{
|
|
|
|
// femaleKid=0,
|
|
|
|
// maleKid,
|
|
|
|
// femaleAdult,
|
|
|
|
// maleAdult
|
|
|
|
//};
|
|
|
|
|
|
|
|
struct WatchedRace
|
|
|
|
{
|
|
|
|
public:
|
2012-04-09 07:03:26 -06:00
|
|
|
PersistentDataItem rconfig;
|
2012-04-06 18:31:10 -06:00
|
|
|
|
|
|
|
bool isWatched; // if true, autobutcher will process this race
|
|
|
|
int raceId;
|
|
|
|
int fk; // max female kids
|
|
|
|
int mk; // max male kids
|
|
|
|
int fa; // max female adults
|
|
|
|
int ma; // max male adults
|
|
|
|
|
|
|
|
// bah, this should better be an array of 4 vectors
|
|
|
|
// that way there's no need for the 4 ugly process methods
|
|
|
|
vector <df::unit*> fk_ptr;
|
|
|
|
vector <df::unit*> mk_ptr;
|
|
|
|
vector <df::unit*> fa_ptr;
|
|
|
|
vector <df::unit*> ma_ptr;
|
|
|
|
|
|
|
|
WatchedRace(bool watch, int id, int _fk, int _mk, int _fa, int _ma)
|
|
|
|
{
|
|
|
|
isWatched = watch;
|
|
|
|
raceId = id;
|
|
|
|
fk = _fk;
|
|
|
|
mk = _mk;
|
|
|
|
fa = _fa;
|
|
|
|
ma = _ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
~WatchedRace()
|
|
|
|
{
|
|
|
|
ClearUnits();
|
|
|
|
}
|
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
void UpdateConfig(color_ostream & out)
|
|
|
|
{
|
|
|
|
if(!rconfig.isValid())
|
|
|
|
{
|
|
|
|
string keyname = "autobutcher/watchlist/" + getRaceName(raceId);
|
|
|
|
auto pworld = Core::getInstance().getWorld();
|
|
|
|
rconfig = pworld->GetPersistentData(keyname);
|
|
|
|
if(!rconfig.isValid())
|
|
|
|
rconfig = pworld->AddPersistentData(keyname);
|
|
|
|
}
|
|
|
|
if(rconfig.isValid())
|
|
|
|
{
|
|
|
|
rconfig.ival(0) = raceId;
|
|
|
|
rconfig.ival(1) = isWatched;
|
|
|
|
rconfig.ival(2) = fk;
|
|
|
|
rconfig.ival(3) = mk;
|
|
|
|
rconfig.ival(4) = fa;
|
|
|
|
rconfig.ival(5) = ma;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// this should never happen
|
|
|
|
string keyname = "autobutcher/watchlist/" + getRaceName(raceId);
|
|
|
|
out << "Something failed, could not find/create config key " << keyname << "!" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveConfig(color_ostream & out)
|
|
|
|
{
|
|
|
|
if(!rconfig.isValid())
|
|
|
|
return;
|
|
|
|
Core::getInstance().getWorld()->DeletePersistentData(rconfig);
|
|
|
|
}
|
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
void SortUnitsByAge()
|
|
|
|
{
|
|
|
|
sort(fk_ptr.begin(), fk_ptr.end(), compareUnitAgesOlder);
|
|
|
|
sort(mk_ptr.begin(), mk_ptr.end(), compareUnitAgesOlder);
|
|
|
|
sort(fa_ptr.begin(), fa_ptr.end(), compareUnitAgesYounger);
|
|
|
|
sort(ma_ptr.begin(), ma_ptr.end(), compareUnitAgesYounger);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PushUnit(df::unit * unit)
|
|
|
|
{
|
|
|
|
if(isFemale(unit))
|
|
|
|
{
|
|
|
|
if(isBaby(unit) || isChild(unit))
|
|
|
|
fk_ptr.push_back(unit);
|
|
|
|
else
|
|
|
|
fa_ptr.push_back(unit);
|
|
|
|
}
|
|
|
|
else //treat sex n/a like it was male
|
|
|
|
{
|
|
|
|
if(isBaby(unit) || isChild(unit))
|
|
|
|
mk_ptr.push_back(unit);
|
|
|
|
else
|
|
|
|
ma_ptr.push_back(unit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearUnits()
|
|
|
|
{
|
|
|
|
fk_ptr.clear();
|
|
|
|
mk_ptr.clear();
|
|
|
|
fa_ptr.clear();
|
|
|
|
ma_ptr.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProcessUnits_fk()
|
|
|
|
{
|
|
|
|
int subcount = 0;
|
|
|
|
while(fk_ptr.size() > fk)
|
|
|
|
{
|
|
|
|
df::unit* unit = fk_ptr.back();
|
|
|
|
doMarkForSlaughter(unit);
|
|
|
|
fk_ptr.pop_back();
|
|
|
|
subcount++;
|
|
|
|
}
|
|
|
|
return subcount;
|
|
|
|
}
|
2012-04-08 04:51:03 -06:00
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
int ProcessUnits_mk()
|
|
|
|
{
|
|
|
|
int subcount = 0;
|
|
|
|
while(mk_ptr.size() > mk)
|
|
|
|
{
|
|
|
|
df::unit* unit = mk_ptr.back();
|
|
|
|
doMarkForSlaughter(unit);
|
|
|
|
mk_ptr.pop_back();
|
|
|
|
subcount++;
|
|
|
|
}
|
|
|
|
return subcount;
|
|
|
|
}
|
2012-04-08 04:51:03 -06:00
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
int ProcessUnits_fa()
|
|
|
|
{
|
|
|
|
int subcount = 0;
|
|
|
|
while(fa_ptr.size() > fa)
|
|
|
|
{
|
|
|
|
df::unit* unit = fa_ptr.back();
|
|
|
|
doMarkForSlaughter(unit);
|
|
|
|
fa_ptr.pop_back();
|
|
|
|
subcount++;
|
|
|
|
}
|
|
|
|
return subcount;
|
|
|
|
}
|
2012-04-08 04:51:03 -06:00
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
int ProcessUnits_ma()
|
|
|
|
{
|
|
|
|
int subcount = 0;
|
|
|
|
while(ma_ptr.size() > ma)
|
|
|
|
{
|
|
|
|
df::unit* unit = ma_ptr.back();
|
|
|
|
doMarkForSlaughter(unit);
|
|
|
|
ma_ptr.pop_back();
|
|
|
|
subcount++;
|
|
|
|
}
|
|
|
|
return subcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProcessUnits()
|
|
|
|
{
|
|
|
|
SortUnitsByAge();
|
|
|
|
int slaughter_count = 0;
|
|
|
|
slaughter_count += ProcessUnits_fk();
|
|
|
|
slaughter_count += ProcessUnits_mk();
|
|
|
|
slaughter_count += ProcessUnits_fa();
|
|
|
|
slaughter_count += ProcessUnits_ma();
|
|
|
|
ClearUnits();
|
|
|
|
return slaughter_count;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// vector of races handled by autobutcher
|
|
|
|
// the name is a bit misleading since entries can be set to 'unwatched'
|
|
|
|
// to ignore them for a while but still keep the target count settings
|
|
|
|
std::vector<WatchedRace*> watched_races;
|
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
// default target values for autobutcher
|
2012-04-07 03:15:49 -06:00
|
|
|
static int default_fk = 5;
|
|
|
|
static int default_mk = 1;
|
|
|
|
static int default_fa = 5;
|
|
|
|
static int default_ma = 1;
|
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
|
|
|
|
|
|
|
bool verbose = false;
|
|
|
|
bool watch_race = false;
|
|
|
|
bool unwatch_race = false;
|
|
|
|
bool forget_race = false;
|
|
|
|
bool list_watched = false;
|
2012-04-09 07:03:26 -06:00
|
|
|
bool list_export = false;
|
2012-04-06 18:31:10 -06:00
|
|
|
bool change_target = false;
|
2012-04-06 21:05:42 -06:00
|
|
|
vector <string> target_racenames;
|
|
|
|
vector <int> target_raceids;
|
|
|
|
|
2012-04-06 18:31:10 -06:00
|
|
|
int target_fk = default_fk;
|
|
|
|
int target_mk = default_mk;
|
|
|
|
int target_fa = default_fa;
|
|
|
|
int target_ma = default_ma;
|
|
|
|
|
|
|
|
int32_t target_raceid = -1;
|
|
|
|
|
2012-04-06 21:05:42 -06:00
|
|
|
if(!parameters.size())
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-06 21:05:42 -06:00
|
|
|
out << "You must specify a command!" << endl;
|
|
|
|
out << autobutcher_help << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse main command
|
|
|
|
string & p = parameters[0];
|
|
|
|
if (p == "help" || p == "?")
|
|
|
|
{
|
|
|
|
out << autobutcher_help << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
if (p == "example")
|
|
|
|
{
|
|
|
|
out << autobutcher_help_example << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else if (p == "start")
|
|
|
|
{
|
|
|
|
enable_autobutcher = true;
|
2012-04-09 07:03:26 -06:00
|
|
|
start_autobutcher(out);
|
2012-04-06 21:05:42 -06:00
|
|
|
return autoButcher(out, verbose);
|
|
|
|
}
|
|
|
|
else if (p == "stop")
|
|
|
|
{
|
|
|
|
enable_autobutcher = false;
|
2012-04-09 07:03:26 -06:00
|
|
|
if(config_autobutcher.isValid())
|
|
|
|
config_autobutcher.ival(0) = enable_autobutcher;
|
2012-04-08 04:51:03 -06:00
|
|
|
out << "Autobutcher stopped." << endl;
|
2012-04-06 21:05:42 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else if(p == "sleep")
|
|
|
|
{
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
if(!parameters.size())
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-08 04:51:03 -06:00
|
|
|
out.printerr("No duration specified!\n");
|
2012-04-06 21:05:42 -06:00
|
|
|
return CR_WRONG_USAGE;
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-06 21:05:42 -06:00
|
|
|
else
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-06 21:05:42 -06:00
|
|
|
size_t ticks = 0;
|
|
|
|
stringstream ss(parameters.back());
|
|
|
|
ss >> ticks;
|
|
|
|
if(ticks <= 0)
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-08 04:51:03 -06:00
|
|
|
out.printerr("Invalid duration specified (must be > 0)!\n");
|
2012-04-06 18:31:10 -06:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
2012-04-06 21:05:42 -06:00
|
|
|
sleep_autobutcher = ticks;
|
2012-04-09 07:03:26 -06:00
|
|
|
if(config_autobutcher.isValid())
|
|
|
|
config_autobutcher.ival(1) = sleep_autobutcher;
|
2012-04-06 21:05:42 -06:00
|
|
|
out << "New sleep timer for autobutcher: " << ticks << " ticks." << endl;
|
2012-04-06 18:31:10 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-04-06 21:05:42 -06:00
|
|
|
}
|
|
|
|
else if(p == "watch")
|
|
|
|
{
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
watch_race = true;
|
2012-04-09 10:36:01 -06:00
|
|
|
out << "Start watching race(s): "; // << endl;
|
2012-04-06 21:05:42 -06:00
|
|
|
}
|
|
|
|
else if(p == "unwatch")
|
|
|
|
{
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
unwatch_race = true;
|
2012-04-09 10:36:01 -06:00
|
|
|
out << "Stop watching race(s): "; // << endl;
|
2012-04-06 21:05:42 -06:00
|
|
|
}
|
|
|
|
else if(p == "forget")
|
|
|
|
{
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
forget_race = true;
|
2012-04-09 10:36:01 -06:00
|
|
|
out << "Removing race(s) from watchlist: "; // << endl;
|
2012-04-06 21:05:42 -06:00
|
|
|
}
|
|
|
|
else if(p == "target")
|
|
|
|
{
|
|
|
|
// needs at least 5 more parameters:
|
|
|
|
// fk mk fa ma R (can have more than 1 R)
|
|
|
|
if(parameters.size() < 6)
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-08 04:51:03 -06:00
|
|
|
out.printerr("Not enough parameters!\n");
|
2012-04-06 21:05:42 -06:00
|
|
|
return CR_WRONG_USAGE;
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-06 21:05:42 -06:00
|
|
|
stringstream fk(parameters[1]);
|
|
|
|
stringstream mk(parameters[2]);
|
|
|
|
stringstream fa(parameters[3]);
|
|
|
|
stringstream ma(parameters[4]);
|
|
|
|
fk >> target_fk;
|
|
|
|
mk >> target_mk;
|
|
|
|
fa >> target_fa;
|
|
|
|
ma >> target_ma;
|
|
|
|
parameters.erase(parameters.begin(), parameters.begin()+5);
|
|
|
|
change_target = true;
|
2012-04-09 10:36:01 -06:00
|
|
|
out << "Setting new target count for race(s): "; // << endl;
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-06 21:05:42 -06:00
|
|
|
else if(p == "autowatch")
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-07 03:15:49 -06:00
|
|
|
out << "Auto-adding to watchlist started." << endl;
|
|
|
|
enable_autobutcher_autowatch = true;
|
2012-04-09 07:03:26 -06:00
|
|
|
if(config_autobutcher.isValid())
|
|
|
|
config_autobutcher.ival(2) = enable_autobutcher_autowatch;
|
2012-04-06 18:31:10 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-04-06 21:05:42 -06:00
|
|
|
else if(p == "noautowatch")
|
|
|
|
{
|
2012-04-07 03:15:49 -06:00
|
|
|
out << "Auto-adding to watchlist stopped." << endl;
|
|
|
|
enable_autobutcher_autowatch = false;
|
2012-04-09 07:03:26 -06:00
|
|
|
if(config_autobutcher.isValid())
|
|
|
|
config_autobutcher.ival(2) = enable_autobutcher_autowatch;
|
2012-04-06 21:05:42 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else if(p == "list")
|
|
|
|
{
|
|
|
|
list_watched = true;
|
|
|
|
}
|
2012-04-09 07:03:26 -06:00
|
|
|
else if(p == "list_export")
|
|
|
|
{
|
|
|
|
list_export = true;
|
|
|
|
}
|
2012-04-06 21:05:42 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "Unknown command: " << p << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
2012-04-06 18:31:10 -06:00
|
|
|
|
|
|
|
if(list_watched)
|
|
|
|
{
|
2012-04-09 07:03:26 -06:00
|
|
|
out << "Autobutcher status: ";
|
|
|
|
|
|
|
|
if(enable_autobutcher)
|
|
|
|
out << "enabled,";
|
|
|
|
else
|
|
|
|
out << "not enabled,";
|
|
|
|
|
|
|
|
if (enable_autobutcher_autowatch)
|
|
|
|
out << " autowatch,";
|
|
|
|
else
|
|
|
|
out << " noautowatch,";
|
|
|
|
|
|
|
|
out << " sleep: " << sleep_autobutcher << endl;
|
|
|
|
|
|
|
|
out << "Default setting for new races:"
|
|
|
|
<< " fk=" << default_fk
|
|
|
|
<< " mk=" << default_mk
|
|
|
|
<< " fa=" << default_fa
|
|
|
|
<< " ma=" << default_ma
|
|
|
|
<< endl;
|
|
|
|
|
2012-04-08 04:51:03 -06:00
|
|
|
if(!watched_races.size())
|
|
|
|
{
|
|
|
|
out << "The autobutcher race list is empty." << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
out << "Races on autobutcher list: " << endl;
|
2012-04-06 18:31:10 -06:00
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
{
|
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
df::creature_raw * raw = df::global::world->raws.creatures.all[w->raceId];
|
|
|
|
string name = raw->creature_id;
|
|
|
|
if(w->isWatched)
|
|
|
|
out << "watched: ";
|
|
|
|
else
|
|
|
|
out << "not watched: ";
|
|
|
|
out << name
|
|
|
|
<< " fk=" << w->fk
|
|
|
|
<< " mk=" << w->mk
|
|
|
|
<< " fa=" << w->fa
|
|
|
|
<< " ma=" << w->ma
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-09 07:03:26 -06:00
|
|
|
if(list_export)
|
|
|
|
{
|
|
|
|
string run = "dfhack-run autobutcher ";
|
|
|
|
#ifdef LINUX_BUILD
|
2012-04-09 07:35:25 -06:00
|
|
|
run = "./dfhack-run autobutcher ";
|
2012-04-09 07:03:26 -06:00
|
|
|
#endif
|
|
|
|
// force creation of config
|
|
|
|
out << run << "start" << endl;
|
|
|
|
|
|
|
|
if(!enable_autobutcher)
|
|
|
|
out << run << "stop" << endl;
|
|
|
|
|
|
|
|
if (enable_autobutcher_autowatch)
|
|
|
|
out << run << "autowatch" << endl;
|
|
|
|
|
|
|
|
out << run << "sleep " << sleep_autobutcher << endl;
|
|
|
|
out << run << "target"
|
|
|
|
<< " " << default_fk
|
|
|
|
<< " " << default_mk
|
|
|
|
<< " " << default_fa
|
|
|
|
<< " " << default_ma
|
|
|
|
<< " new" << endl;
|
|
|
|
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
{
|
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
df::creature_raw * raw = df::global::world->raws.creatures.all[w->raceId];
|
|
|
|
string name = raw->creature_id;
|
|
|
|
|
|
|
|
out << run << "target"
|
|
|
|
<< " " << w->fk
|
|
|
|
<< " " << w->mk
|
|
|
|
<< " " << w->fa
|
|
|
|
<< " " << w->ma
|
|
|
|
<< " " << name << endl;
|
|
|
|
|
|
|
|
if(w->isWatched)
|
|
|
|
out << run << "watch " << name << endl;
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-06 21:05:42 -06:00
|
|
|
// parse rest of parameters for commands followed by a list of races
|
|
|
|
if( watch_race
|
|
|
|
|| unwatch_race
|
|
|
|
|| forget_race
|
|
|
|
|| change_target )
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-06 21:05:42 -06:00
|
|
|
if(!parameters.size())
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-08 04:51:03 -06:00
|
|
|
out.printerr("No race(s) specified!\n");
|
2012-04-06 21:05:42 -06:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
while(parameters.size())
|
|
|
|
{
|
|
|
|
string tr = parameters.back();
|
|
|
|
target_racenames.push_back(tr);
|
|
|
|
parameters.pop_back();
|
2012-04-08 04:51:03 -06:00
|
|
|
out << tr << " ";
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-08 04:51:03 -06:00
|
|
|
out << endl;
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-06 21:05:42 -06:00
|
|
|
|
2012-04-09 10:36:01 -06:00
|
|
|
if(change_target && target_racenames.size() && target_racenames[0] == "all")
|
2012-04-07 03:15:49 -06:00
|
|
|
{
|
|
|
|
out << "Setting target count for all races on watchlist." << endl;
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
{
|
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
w->fk = target_fk;
|
|
|
|
w->mk = target_mk;
|
|
|
|
w->fa = target_fa;
|
|
|
|
w->ma = target_ma;
|
2012-04-09 07:03:26 -06:00
|
|
|
w->UpdateConfig(out);
|
2012-04-07 03:15:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(target_racenames.size() && (target_racenames[0] == "all" || target_racenames[0] == "new"))
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-09 10:36:01 -06:00
|
|
|
if(change_target)
|
2012-04-09 07:03:26 -06:00
|
|
|
{
|
2012-04-09 10:36:01 -06:00
|
|
|
out << "Setting target count for the future." << endl;
|
|
|
|
default_fk = target_fk;
|
|
|
|
default_mk = target_mk;
|
|
|
|
default_fa = target_fa;
|
|
|
|
default_ma = target_ma;
|
|
|
|
if(config_autobutcher.isValid())
|
|
|
|
{
|
|
|
|
config_autobutcher.ival(3) = default_fk;
|
|
|
|
config_autobutcher.ival(4) = default_mk;
|
|
|
|
config_autobutcher.ival(5) = default_fa;
|
|
|
|
config_autobutcher.ival(6) = default_ma;
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else if(target_racenames[0] == "new")
|
|
|
|
{
|
|
|
|
out << "The only valid usage of 'new' is in combination when setting a target count!" << endl;
|
|
|
|
|
|
|
|
// hm, maybe instead of complaining start/stop autowatch instead? and get rid of the autowatch option?
|
|
|
|
if(unwatch_race)
|
|
|
|
out << "'unwatch new' makes no sense! Use 'noautowatch' instead." << endl;
|
|
|
|
else if(forget_race)
|
|
|
|
out << "'forget new' makes no sense, 'forget' is only for existing watchlist entries! Use 'noautowatch' instead." << endl;
|
|
|
|
else if(watch_race)
|
|
|
|
out << "'watch new' makes no sense! Use 'autowatch' instead." << endl;
|
|
|
|
return CR_WRONG_USAGE;
|
2012-04-09 07:03:26 -06:00
|
|
|
}
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
|
|
|
|
2012-04-09 10:36:01 -06:00
|
|
|
if(target_racenames.size() && target_racenames[0] == "all")
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-09 10:36:01 -06:00
|
|
|
// fill with race ids from watchlist
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-09 10:36:01 -06:00
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
target_raceids.push_back(w->raceId);
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-09 10:36:01 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// map race names from parameter list to ids
|
|
|
|
size_t num_races = df::global::world->raws.creatures.all.size();
|
|
|
|
while(target_racenames.size())
|
2012-04-06 21:05:42 -06:00
|
|
|
{
|
2012-04-09 10:36:01 -06:00
|
|
|
bool found_race = false;
|
|
|
|
for(size_t i=0; i<num_races; i++)
|
|
|
|
{
|
|
|
|
if(getRaceName(i) == target_racenames.back())
|
|
|
|
{
|
|
|
|
target_raceids.push_back(i);
|
|
|
|
target_racenames.pop_back();
|
|
|
|
found_race = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found_race)
|
|
|
|
{
|
|
|
|
out << "Race not found: " << target_racenames.back() << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-04-06 21:05:42 -06:00
|
|
|
}
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
|
|
|
|
2012-04-07 03:15:49 -06:00
|
|
|
while(target_raceids.size())
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-07 03:15:49 -06:00
|
|
|
bool entry_found = false;
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-07 03:15:49 -06:00
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
if(w->raceId == target_raceids.back())
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-07 03:15:49 -06:00
|
|
|
if(unwatch_race)
|
2012-04-09 07:03:26 -06:00
|
|
|
{
|
2012-04-06 21:05:42 -06:00
|
|
|
w->isWatched=false;
|
2012-04-09 07:03:26 -06:00
|
|
|
w->UpdateConfig(out);
|
|
|
|
}
|
2012-04-07 03:15:49 -06:00
|
|
|
else if(forget_race)
|
2012-04-09 07:03:26 -06:00
|
|
|
{
|
|
|
|
w->RemoveConfig(out);
|
2012-04-07 03:15:49 -06:00
|
|
|
watched_races.erase(watched_races.begin()+i);
|
2012-04-09 07:03:26 -06:00
|
|
|
}
|
2012-04-07 03:15:49 -06:00
|
|
|
else if(watch_race)
|
2012-04-09 07:03:26 -06:00
|
|
|
{
|
2012-04-07 03:15:49 -06:00
|
|
|
w->isWatched = true;
|
2012-04-09 07:03:26 -06:00
|
|
|
w->UpdateConfig(out);
|
|
|
|
}
|
2012-04-07 03:15:49 -06:00
|
|
|
else if(change_target)
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-07 03:15:49 -06:00
|
|
|
w->fk = target_fk;
|
|
|
|
w->mk = target_mk;
|
|
|
|
w->fa = target_fa;
|
|
|
|
w->ma = target_ma;
|
2012-04-09 07:03:26 -06:00
|
|
|
w->UpdateConfig(out);
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-07 03:15:49 -06:00
|
|
|
entry_found = true;
|
|
|
|
break;
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-07 03:15:49 -06:00
|
|
|
if(!entry_found && (watch_race||change_target))
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-07 03:15:49 -06:00
|
|
|
WatchedRace * w = new WatchedRace(watch_race, target_raceids.back(), target_fk, target_mk, target_fa, target_ma);
|
2012-04-09 07:03:26 -06:00
|
|
|
w->UpdateConfig(out);
|
2012-04-07 03:15:49 -06:00
|
|
|
watched_races.push_back(w);
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-07 03:15:49 -06:00
|
|
|
target_raceids.pop_back();
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-08 04:51:03 -06:00
|
|
|
// check watched_races vector for a race id, return -1 if nothing found
|
|
|
|
// calling method needs to check itself if the race is currently being watched or ignored
|
2012-04-06 18:31:10 -06:00
|
|
|
int getWatchedIndex(int id)
|
2012-04-05 12:32:44 -06:00
|
|
|
{
|
2012-04-06 18:31:10 -06:00
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
{
|
|
|
|
WatchedRace * w = watched_races[i];
|
2012-04-08 04:51:03 -06:00
|
|
|
if(w->raceId == id) // && w->isWatched)
|
2012-04-06 18:31:10 -06:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result autoButcher( color_ostream &out, bool verbose = false )
|
|
|
|
{
|
|
|
|
// don't run if not supposed to
|
|
|
|
if(!Maps::IsValid())
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
// check if there is anything to watch before walking through units vector
|
2012-04-16 08:31:12 -06:00
|
|
|
if(!enable_autobutcher_autowatch)
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-16 08:31:12 -06:00
|
|
|
bool watching = false;
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
2012-04-06 18:31:10 -06:00
|
|
|
{
|
2012-04-16 08:31:12 -06:00
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
if(w->isWatched)
|
|
|
|
{
|
|
|
|
watching = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-16 08:31:12 -06:00
|
|
|
if(!watching)
|
|
|
|
return CR_OK;
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i=0; i<world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit * unit = world->units.all[i];
|
|
|
|
if( isDead(unit)
|
2012-04-09 07:03:26 -06:00
|
|
|
|| isUndead(unit)
|
2012-04-06 18:31:10 -06:00
|
|
|
|| isMarkedForSlaughter(unit)
|
2012-04-08 04:51:03 -06:00
|
|
|
|| isMerchant(unit) // ignore merchants' draught animals
|
|
|
|
|| isForest(unit) // ignore merchants' caged animals
|
2012-04-06 18:31:10 -06:00
|
|
|
|| !isOwnCiv(unit)
|
|
|
|
|| !isTame(unit)
|
2012-04-08 04:51:03 -06:00
|
|
|
|| isWar(unit) // ignore war dogs etc
|
|
|
|
|| isHunter(unit) // ignore hunting dogs etc
|
2012-04-16 02:15:37 -06:00
|
|
|
// ignore creatures in built cages which are defined as rooms to leave zoos alone
|
|
|
|
// (TODO: better solution would be to allow some kind of slaughter cages which you can place near the butcher)
|
2012-04-16 08:31:12 -06:00
|
|
|
|| (isContainedInItem(unit) && isInBuiltCageRoom(unit)) // !!! see comments in isBuiltCageRoom()
|
2012-04-06 18:31:10 -06:00
|
|
|
|| unit->name.has_name
|
|
|
|
)
|
|
|
|
continue;
|
|
|
|
|
2012-04-06 22:47:32 -06:00
|
|
|
// found a bugged unit which had invalid coordinates but was not in a cage.
|
2012-04-06 18:31:10 -06:00
|
|
|
// marking it for slaughter didn't seem to have negative effects, but you never know...
|
2012-04-06 22:47:32 -06:00
|
|
|
if(!isContainedInItem(unit) && !hasValidMapPos(unit))
|
2012-04-06 18:31:10 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
int watched_index = getWatchedIndex(unit->race);
|
|
|
|
if(watched_index != -1)
|
|
|
|
{
|
|
|
|
WatchedRace * w = watched_races[watched_index];
|
2012-04-08 04:51:03 -06:00
|
|
|
if(w->isWatched)
|
|
|
|
w->PushUnit(unit);
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-07 03:15:49 -06:00
|
|
|
else if(enable_autobutcher_autowatch)
|
|
|
|
{
|
|
|
|
WatchedRace * w = new WatchedRace(true, unit->race, default_fk, default_mk, default_fa, default_ma);
|
2012-04-09 07:03:26 -06:00
|
|
|
w->UpdateConfig(out);
|
2012-04-07 03:15:49 -06:00
|
|
|
watched_races.push_back(w);
|
|
|
|
w->PushUnit(unit);
|
2012-04-09 07:03:26 -06:00
|
|
|
|
|
|
|
string announce;
|
|
|
|
announce = "New race added to autobutcher watchlist: " + getRaceName(w->raceId);
|
|
|
|
Gui::showAnnouncement(announce, 2, false);
|
|
|
|
//out << announce << endl;
|
2012-04-07 03:15:49 -06:00
|
|
|
}
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int slaughter_count = 0;
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
{
|
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
int slaughter_subcount = w->ProcessUnits();
|
|
|
|
slaughter_count += slaughter_subcount;
|
2012-04-08 04:51:03 -06:00
|
|
|
if(slaughter_subcount)
|
2012-04-09 07:03:26 -06:00
|
|
|
{
|
|
|
|
stringstream ss;
|
|
|
|
ss << slaughter_subcount;
|
|
|
|
string announce;
|
|
|
|
announce = getRaceName(w->raceId) + " marked for slaughter: " + ss.str();
|
|
|
|
Gui::showAnnouncement(announce, 2, false);
|
|
|
|
//out << announce << endl;
|
|
|
|
}
|
2012-04-06 18:31:10 -06:00
|
|
|
}
|
2012-04-08 04:51:03 -06:00
|
|
|
//out << slaughter_count << " units total marked for slaughter." << endl;
|
2012-04-06 18:31:10 -06:00
|
|
|
|
2012-04-05 12:32:44 -06:00
|
|
|
return CR_OK;
|
2012-04-09 07:03:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
// autobutcher and autonestbox start/init/cleanup
|
|
|
|
|
|
|
|
command_result start_autobutcher(color_ostream &out)
|
|
|
|
{
|
|
|
|
auto pworld = Core::getInstance().getWorld();
|
|
|
|
|
|
|
|
enable_autobutcher = true;
|
|
|
|
if (!config_autobutcher.isValid())
|
|
|
|
{
|
|
|
|
config_autobutcher = pworld->AddPersistentData("autobutcher/config");
|
|
|
|
config_autobutcher.ival(0) = enable_autobutcher;
|
|
|
|
config_autobutcher.ival(1) = sleep_autobutcher;
|
|
|
|
config_autobutcher.ival(2) = enable_autobutcher_autowatch;
|
|
|
|
config_autobutcher.ival(3) = default_fk;
|
|
|
|
config_autobutcher.ival(4) = default_mk;
|
|
|
|
config_autobutcher.ival(5) = default_fa;
|
|
|
|
config_autobutcher.ival(6) = default_ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
out << "Starting autobutcher." << endl;
|
|
|
|
init_autobutcher(out);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result init_autobutcher(color_ostream &out)
|
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
cleanup_autobutcher(out);
|
2012-04-09 07:03:26 -06:00
|
|
|
auto pworld = Core::getInstance().getWorld();
|
|
|
|
if(!pworld)
|
|
|
|
{
|
|
|
|
out << "Autobutcher has no world to read from!" << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_autobutcher = pworld->GetPersistentData("autobutcher/config");
|
|
|
|
if(config_autobutcher.isValid())
|
|
|
|
{
|
|
|
|
if (config_autobutcher.ival(0) == -1)
|
|
|
|
{
|
|
|
|
config_autobutcher.ival(0) = enable_autobutcher;
|
|
|
|
config_autobutcher.ival(1) = sleep_autobutcher;
|
|
|
|
config_autobutcher.ival(2) = enable_autobutcher_autowatch;
|
|
|
|
config_autobutcher.ival(3) = default_fk;
|
|
|
|
config_autobutcher.ival(4) = default_mk;
|
|
|
|
config_autobutcher.ival(5) = default_fa;
|
|
|
|
config_autobutcher.ival(6) = default_ma;
|
|
|
|
out << "Autobutcher's persistent config object was invalid!" << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
enable_autobutcher = config_autobutcher.ival(0);
|
|
|
|
sleep_autobutcher = config_autobutcher.ival(1);
|
|
|
|
enable_autobutcher_autowatch = config_autobutcher.ival(2);
|
|
|
|
default_fk = config_autobutcher.ival(3);
|
|
|
|
default_mk = config_autobutcher.ival(4);
|
|
|
|
default_fa = config_autobutcher.ival(5);
|
|
|
|
default_ma = config_autobutcher.ival(6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!enable_autobutcher)
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
// read watchlist from save
|
|
|
|
|
|
|
|
std::vector<PersistentDataItem> items;
|
|
|
|
pworld->GetPersistentData(&items, "autobutcher/watchlist/", true);
|
|
|
|
for (auto p = items.begin(); p != items.end(); p++)
|
|
|
|
{
|
|
|
|
string key = p->key();
|
|
|
|
out << "Reading from save: " << key << endl;
|
|
|
|
//out << " raceid: " << p->ival(0) << endl;
|
|
|
|
//out << " watched: " << p->ival(1) << endl;
|
|
|
|
//out << " fk: " << p->ival(2) << endl;
|
|
|
|
//out << " mk: " << p->ival(3) << endl;
|
|
|
|
//out << " fa: " << p->ival(4) << endl;
|
|
|
|
//out << " ma: " << p->ival(5) << endl;
|
|
|
|
|
|
|
|
WatchedRace * w = new WatchedRace(p->ival(1), p->ival(0), p->ival(2), p->ival(3),p->ival(4),p->ival(5));
|
|
|
|
w->rconfig = *p;
|
|
|
|
watched_races.push_back(w);
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result cleanup_autobutcher(color_ostream &out)
|
|
|
|
{
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
{
|
|
|
|
delete watched_races[i];
|
|
|
|
}
|
|
|
|
watched_races.clear();
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result start_autonestbox(color_ostream &out)
|
|
|
|
{
|
|
|
|
auto pworld = Core::getInstance().getWorld();
|
|
|
|
enable_autonestbox = true;
|
|
|
|
if (!config_autobutcher.isValid())
|
|
|
|
{
|
|
|
|
config_autonestbox = pworld->AddPersistentData("autonestbox/config");
|
|
|
|
config_autonestbox.ival(0) = enable_autonestbox;
|
|
|
|
config_autonestbox.ival(1) = sleep_autonestbox;
|
|
|
|
}
|
|
|
|
out << "Starting autonestbox." << endl;
|
|
|
|
init_autonestbox(out);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result init_autonestbox(color_ostream &out)
|
|
|
|
{
|
2012-04-10 01:15:38 -06:00
|
|
|
cleanup_autonestbox(out);
|
2012-04-09 07:03:26 -06:00
|
|
|
auto pworld = Core::getInstance().getWorld();
|
|
|
|
if(!pworld)
|
|
|
|
{
|
|
|
|
out << "Autonestbox has no world to read from!" << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_autonestbox = pworld->GetPersistentData("autonestbox/config");
|
|
|
|
if(config_autonestbox.isValid())
|
|
|
|
{
|
|
|
|
if (config_autonestbox.ival(0) == -1)
|
|
|
|
{
|
|
|
|
config_autonestbox.ival(0) = enable_autonestbox;
|
|
|
|
config_autonestbox.ival(1) = sleep_autonestbox;
|
|
|
|
out << "Autonestbox's persistent config object was invalid!" << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
enable_autonestbox = config_autonestbox.ival(0);
|
|
|
|
sleep_autonestbox = config_autonestbox.ival(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result cleanup_autonestbox(color_ostream &out)
|
|
|
|
{
|
|
|
|
// nothing to cleanup currently
|
|
|
|
// (future version of autonestbox could store info about cages for useless male kids)
|
|
|
|
return CR_OK;
|
|
|
|
}
|