Minecolonies & Barbarrrrrian Rework

in #utopian-io6 years ago

Hey everyone, lately I had noticed how weak our barbarians against colony defense systems are, based on that I decided that they urgently require a small rework.

The results of this can be seen in our new video:

Based on that several changes had to be made:

  • Pathfinding
  • Ladder placing
  • Wall breaking
  • Bridge building

Preparation:

First of all, I added a configuration value to the game which allows people to toggle this manually.

Then I moved the constants in the barbarians to their own constant class and the other constants in matching constant classes to clean up the code a bit.

Then, on the way, I noticed we were using reflection for a variable which became protected in the last year and we didn't notice it.
That's nice since I was able to remove a bit ugly chunk of code from the citizen and barbarian class.

The barbarian himself then became a stuck and ladder counter.

With the respective getters and setters as well as persisting the values in case of chunks unloading.

Additionally, I moved the navigator code to the barbarian class to be able to handle it from all classes which need it and not only from the one we're going to use a bit further down the line.

Now, I also noticed that our pathfinding had some issues when trying to run away from an entity or position because one possibility of running away included running through it. And if running through it wasn't possible it would run away way too far.

Therefore, I had to adapt the metric with which we detect if we were successful in running away. So, to return true already if a certain distance was reached independenty of the direction.

final double nodeResult = getNodeResultScore(n);
final int avoidSq = (avoidDistance * avoidDistance);
return nodeResult >= avoidSq && (EnumFacing.getFacingFromVector(vector.getX(), 0, vector.getZ()).equals(direction) || nodeResult > avoidSq * avoidDistance);

I also had noticed that our ladder climbing was slightly bugged since BlockPos and Vec3d are immutable and have to be replaced to adapt actually.

Now, within the barbarian AI job I added a bunch of new fields:

As in the barbarian which has the job, a set of all directions and the world.

A random generator and the target block to go to.

And finally, the last position he was at and the time he is stuck there.

The AI:

Based on that, first I added a code which checks if the entity is still around lastPos and will if so increment the counter.

After that, we would reset the current path, reset the counter and tell the barbarian that we got stuck now.
After that, we calculate in which direction we're facing and check if there is an empty space there. If so, we will let the barbarian place cobble there since this probably means that there is a hole which we can't path over.

Following that we check if the stuck counter is bigger than 1 and that we turned on barbarian griefing.

If one of these is not the case we will try to re-path by moving away for a few blocks.

If that is the case we shuffle the directions, reset the stuck counter and recognize we will try to place a ladder.

Following that, we calculate possible existing ladder positions in front of us.

If there is a ladder in front of us we attempt placing on under it. If there is one under it we try to place it over it. We do this to make sure we try to place ladders over each other and not scattered over the wall.

If that is not successful, we go through the direction list and try to place a ladder on a solid block. Since barbarians sometimes are not correctly directed to the wall and stand sideways.

If the barbarians are done with ladder placing, meaning they placed equal or more to the configuration parameter, they will start breaking blocks.

Again they will go through the position vector and randomly destroy blocks over or next to them.

Which resulted in the behavior of the video I posted above.
The response to this was quite mixed, a lot of players were afraid of this new functionality which made us consider to add a configuration variable to make this triggerable depending on the preference.

I hope you liked the new update and I'll keep you posted!

Repository:

https://github.com/ldtteam/minecolonies

Pull Request:

https://github.com/ldtteam/minecolonies/pull/2856

Sort:  
  • Great bonus to have a video demonstration of the code in action.
  • Perhaps there was a little less comments in the code this time. Also try to add comments that are more than just a repeat of the function name.
  • The param line above in the yellow box does not seem to be a complete sentence. Did I miss something?

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Yeah, setters and getters are my weakness in terms of documentation.
It's quite straightforward what they do.
It would probably be better to have it: ladderCounter the counter to set.

Thank you for your review, @helo!

So far this week you've reviewed 1 contributions. Keep up the good work!

Hi @raycoms!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!

Hey, @raycoms!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Perfexms Solutions,
Calidad, entregado a tiempo y por debajo del presupuesto.

Consigue tu presupuesto para tu empresa y lo que ofrecemos en nuestros servicios.

Ricardo Guadalupe,
CEO - Director Ejecutivo.

https://www.perfexms.solutions
https://www.perfexms.com

Coin Marketplace

STEEM 0.19
TRX 0.14
JST 0.030
BTC 59479.71
ETH 3174.48
USDT 1.00
SBD 2.44