Minecolonies & A new Worker in Town - The Smelter

in #utopian-io7 years ago (edited)

Hey everyone, besides refactoring our code extensively (as in here) I was also working at a new worker in the past weeks.

This worker is "The Smelter".

Before I talk more about his code some basic specs:

The Smelter is a worker quite similar to the cook. He basically requests ore and fuel to the colony (warehouse, or the player),
and when he receives this he will smelt the ore using the fuel.
Besides that, he's also able to deconstruct tools, weapons or armor the player doesn't need anymore.

In order to create a new Worker in Minecolonies you need the following classes:

Job - The job of the worker which tells you about his model, about his AI and store job-related information even to disk.
Block - The block the worker is connected with and which he uses to execute his job.
Building - The building which contains the block and stores information about the worker to disk as well (Which stays even after worker death).
AI - The actual AI of the worker which defines exactly what he does.

On the basis of that, I created the following classes.

And since we don't have a Model and texture yet, as you can see in the code we defined the current style to be the miner style until we have something more fitting.

Besides that, I had to request certain Building-styles to our community so the worker has a roof over his head and enough furnaces to actually work.

In the next step, I added a functionality to our request-system which allows each worker to request just "ore" and the warehouse will give him the first "ore" he can find.

Our coders did a really great job with the request system, which allows us to add quite generic classes of deliverable items and block which can be fulfilled by the deliveryman.

Then as a first step before implementing the AI, I had to define exactly what the AI has to do and I broke it down into the following basic tasks:

Which can be shortly described as:

  • Getting fuel
  • Smelting ore
  • Gathering things from the chests
  • Retrieving smelted things from the furnace
  • Breaking down tools etc in raw materials

I was then, finally able to start with the AI itself.

First of all, I connected the different AI states and how they'll be called in the constructor of the AI class:

Besides that, I defined that the worker is allowed to pick up items and what his best working skills are (used for leveling).

The most interesting part here is probably "Start-Working" since that is basically the task which starts off most of the other tasks.

When he starts working he first always checks if there is anything he can get from the furnace (if any ore is ready) if that is not necessary he will check if he has ore to smelt and if necessary request it.

After that he will check the furnaces he has and will decide if he a) Will go to retrieve ore since it's ready now or b) start smelting ore since there is ore in a furnace but its missing fuel.
If there is no furnace with anything to do he will try to deconstruct tools, weapons or armor he finds around his inventory.

I hope you liked our new worker, we're pretty happy to have one more great addition to our colonies, see you the next time!



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

@raggaemuffin
minnowbooster you are managing didnt upvote my 5sbd order i did going to 2hrs now and as a first timer, i am most dissapointed as i needed my post to appear on hot. very sad for this. however, great work you guys are doing

WARNING: RPC Node lag. Currently behind: 9 hours and 32 minutes

And please don't hijack random comments, go to our discord…

Hey @raycoms I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • You are generating more rewards than average for this category. Super!;)
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Buen post de Gaming Technology Education Programming

It's look rly nice keep going ill keep an eye on the project

thank you friend

Thank you for your valuable and useful information

Thank you for the contribution. It has been approved.

Hi Ray, found this a couple of days ago. This will be my reference.

Yeah this will definitely help you to start developing it.

Coin Marketplace

STEEM 0.31
TRX 0.34
JST 0.056
BTC 97306.42
ETH 3848.10
SBD 4.17