AngleWyrm / Colonies

Minecraft mod MineColony Reboot
7 stars 8 forks source link

Citizen AI to pick up dropped items from ground #99

Closed boycat97 closed 11 years ago

boycat97 commented 11 years ago

This is the AI module that will allow for items that are in a certain vicinity to be picked up off the ground and stored in the entity's inventory.

boycat97 commented 11 years ago

Should the AI set the user on an active hunt for the items or just pick them up if they are in a reachable vicinity? I will set it up for scanning the vicinity around the entity and then if the decision is made to have them actively look for them further that can be modified.

AngleWyrm commented 11 years ago

To make this decision, let's examine what it means to be "in a reachable vicinity." If we define that radius as something like 3-5m, then whenever this module gets executed, a search zone of about 8m diameter is covered, centered on the citizen. No movement is performed, and appropriate objects within that radius disappear from the world and are re-created in the citizen's inventory.

The alternative is to have the citizen move towards a destination first. The citizen would search a larger radius, and then Navigate close to a target destination before transferring the found item into their inventory.

If we make this module do it's thing WITHOUT movement, then it will be possible to execute this task simultaneously with other tasks that require movement (Mutextbit 1). The lumberjack could continue to chop a tree and gather up wood and saplings at the same time. The miner could continue to dig while simultaneously gathering up dropped blocks.

So this module is a good candidate for not using a navigator, so that it can be executed simultaneously with other modules.that need to do navigation.

boycat97 commented 11 years ago

TODO: Have a method that looks for explicitly defined items interested in, instead of picking up everything.

AngleWyrm commented 11 years ago

This can be done by changing the constructor from EntityAIGatherDroppedItems(EntityCitizen _citizen) to EntityAIGatherDroppedItems(EntityCitizen _citizen, ItemStack[ ] thingsToPickUp).

If the citizen in question is expected to pick everything up, then pass a null pointer for the second parameter, when creating the task in that citizen's constructor.

If the citizen is expected to pick up only a specific subset of all possible items, then they can be passed as an array of ItemStack objects to be checked against.

A final possibility that isn't covered by this solution is a list of exclusions to not pick up. Haven't thought of a reason to create such an arrangement, but if needed, it could be done with a third parameter on the constructor.

AngleWyrm commented 11 years ago

This is feature complete, we can move it to colonies/src/citizens