diff options
author | Persson-dev <66266021+Persson-dev@users.noreply.github.com> | 2021-12-29 20:28:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-29 20:28:41 +0100 |
commit | fec64bb91c03c5e872a8f6fbc1a253f341373072 (patch) | |
tree | 74eca1320f61b93cae672a0d9def7abea2ab80ef /src/Mobs/Villager.h | |
parent | Update solid and transparent blocks (#5353) (diff) | |
download | cuberite-fec64bb91c03c5e872a8f6fbc1a253f341373072.tar cuberite-fec64bb91c03c5e872a8f6fbc1a253f341373072.tar.gz cuberite-fec64bb91c03c5e872a8f6fbc1a253f341373072.tar.bz2 cuberite-fec64bb91c03c5e872a8f6fbc1a253f341373072.tar.lz cuberite-fec64bb91c03c5e872a8f6fbc1a253f341373072.tar.xz cuberite-fec64bb91c03c5e872a8f6fbc1a253f341373072.tar.zst cuberite-fec64bb91c03c5e872a8f6fbc1a253f341373072.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Mobs/Villager.h | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index 4ac06765c..ef1c9e70f 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -3,6 +3,7 @@ #include "PassiveMonster.h" #include "../Blocks/ChunkInterface.h" +#include "../Inventory.h" @@ -38,30 +39,68 @@ public: virtual void KilledBy (TakeDamageInfo & a_TDI) override; // cVillager functions - /** return true if the given blocktype are: crops, potatoes or carrots. */ - bool IsBlockFarmable(BLOCKTYPE a_BlockType); + /** Returns the villager hidden inventory (8 slots). */ + cItemGrid & GetInventory(void) { return m_Inventory; } + const cItemGrid & GetInventory(void) const { return m_Inventory; } + + /** Returns true if the given blocktype are: crops, potatoes or carrots and they have full grown up. */ + bool IsBlockFarmable(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + + /** Returns true if the block at the given location is a fully grown up crop. */ + bool IsHarvestable(Vector3i a_CropsPos); + + /** Returns true if seeds can be planted at a given location. */ + bool IsPlantable(Vector3i a_CropsPos); // Farmer functions - /** Searches in a 11x7x11 area for crops. If it found some it will navigate to them. */ - void HandleFarmerPrepareFarmCrops(); + enum eFarmerAction + { + faIdling, + faPlanting, + faHarvesting, + } ; + + static const int FARMER_RANDOM_TICK_SPEED = 5; + /** With 10% chance, it takes about 20 seconds to find a spot. */ + static constexpr double FARMER_SPECIAL_ACTION_CHANCE = 0.1; + /** This distance from the Villager makes for a 31x3x31 area. */ + static constexpr Vector3i FARMER_SCAN_CROPS_DIST {15, 1, 15}; - /** Looks if the farmer has reached it's destination, and if it's still crops and the destination is closer then 2 blocks it will harvest them. */ + /** Tick function for farmers. */ + void TickFarmer(); + + /** Searches in a 31x3x31 area to harvest crops or spaces to plant crops. If it found some it will navigate to them. */ + void ScanAreaForWork(); + + /** Looks if the farmer has reached it's destination, and if it's still crops and the destination is closer then 1 block it will harvest them. */ void HandleFarmerTryHarvestCrops(); - /** Replaces the crops he harvested. */ - void HandleFarmerPlaceCrops(); + /** Looks if the farmer has reached it's destination, and if it's still non obstructed farmland and the destination is closer then 1 block it will plant crops. */ + void HandleFarmerTryPlaceCrops(); + + /** Checking for harvesting or planting nearby crops */ + void CheckForNearbyCrops(); + + /** Returns whether the farmer has crops in his inventory to plant. */ + bool CanPlantCrops(); + + /** Returns whether the farmer is not working. */ + bool IsIdling() + { + return m_FarmerAction == faIdling; + } // Get and set functions. - int GetVilType(void) const { return m_Type; } - Vector3i GetCropsPos(void) const { return m_CropsPos; } - bool DoesHaveActionActivated(void) const { return m_VillagerAction; } + int GetVilType(void) const { return m_Type; } + eFarmerAction GetFarmerAction(void) const { return m_FarmerAction; } private: int m_ActionCountDown; int m_Type; - bool m_VillagerAction; + eFarmerAction m_FarmerAction; Vector3i m_CropsPos; + cItemGrid m_Inventory; } ; |