autonestbox: don't assign to nestboxes which are already claimed or contain eggs.

bprobe: look a bit closer at nestboxes
develop
Robert Heinrich 2012-04-15 21:45:15 +02:00
parent 6197c4e739
commit 7aefae17d1
2 changed files with 31 additions and 1 deletions

@ -16,6 +16,7 @@ using namespace std;
#include "PluginManager.h" #include "PluginManager.h"
#include "modules/Units.h" #include "modules/Units.h"
#include "df/unit_inventory_item.h" #include "df/unit_inventory_item.h"
#include "df/building_nest_boxst.h"
#include "modules/Maps.h" #include "modules/Maps.h"
#include "modules/Gui.h" #include "modules/Gui.h"
#include "modules/Materials.h" #include "modules/Materials.h"
@ -370,6 +371,12 @@ command_result df_bprobe (color_ostream &out, vector <string> & parameters)
ENUM_KEY_STR(trap_type, building.trap_type).c_str(), ENUM_KEY_STR(trap_type, building.trap_type).c_str(),
building.trap_type); building.trap_type);
break; break;
case building_type::NestBox:
{
df::building_nest_boxst* nestbox = (df::building_nest_boxst*) building.origin;
out.print(", claimed:(%i), items:%i", nestbox->claimed_by, nestbox->contained_items.size());
break;
}
default: default:
if (building.subtype != -1) if (building.subtype != -1)
out.print(", subtype %i", building.subtype); out.print(", subtype %i", building.subtype);

@ -56,6 +56,7 @@ using namespace std;
#include "df/building_civzonest.h" #include "df/building_civzonest.h"
#include "df/building_cagest.h" #include "df/building_cagest.h"
#include "df/building_chainst.h" #include "df/building_chainst.h"
#include "df/building_nest_boxst.h"
#include "df/general_ref_building_civzone_assignedst.h" #include "df/general_ref_building_civzone_assignedst.h"
#include <df/creature_raw.h> #include <df/creature_raw.h>
#include <df/caste_raw.h> #include <df/caste_raw.h>
@ -1063,6 +1064,28 @@ bool isNestboxAtPos(int32_t x, int32_t y, int32_t z)
return found; return found;
} }
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;
}
bool isEmptyPasture(df::building* building) bool isEmptyPasture(df::building* building)
{ {
if(!isPenPasture(building)) if(!isPenPasture(building))
@ -1083,7 +1106,7 @@ df::building* findFreeNestboxZone()
df::building* building = world->buildings.all[b]; df::building* building = world->buildings.all[b];
if( isEmptyPasture(building) && if( isEmptyPasture(building) &&
isActive(building) && isActive(building) &&
isNestboxAtPos(building->x1, building->y1, building->z)) isFreeNestboxAtPos(building->x1, building->y1, building->z))
{ {
free_building = building; free_building = building;
break; break;