Coding

Code related posts !

When it’s time to give life to creatures and create AI, there are several options : you can code it by writting scripts, or use tools such as Finites State Machine or Behaviors Tree.

Creating the whole Artificial Intelligence by scripts is great for a developer wich is also the one integrating the AI, wich is my case. However it’s not the ideal  solution for complex behaviors , especially if you need flexibility and can also be tricky to maintain / debug.

Second option, use common tools to write AI, like FSM and BT. Nice tools, and both BT and FSM can be mixed. I have the bad habit to reinvent the wheel (wich in my opinion is not that bad if you really want to understand the coding way 🙂 ) , but this time i decided to gave  try to some public tools instead of coding my system. Unfortunately, after some tries, i end-up with that conclusion: it can works great (BT can be wonderfull !), but not suitable for my needs. I need the creatures of The Dungeon Kingdom to be smart, very smart. Not just simple “if see player, reach and attack” style behaviors. I also need the creatures’s Artificial Intelligence to be smart, tweakable, and easy add variety to a base one. With those requirements in mind, it can be tricky to handle such an AI with common tools.  I then decided to revisit an 8 years ago AI design i have written in c++ for a AAA class game. Of course, i have rewritten all from scratch in c#, and improving it greatly !

So what’s this AI system like ? Basically, it’s a “virtual” brain, and like any real creatures, it is made of elements/features such as sensors (vision, hear noise…probe environment…), memory (in my design, i call them cells. Add to this macro behaviors and controllers and you get the AI system. I won’t enter too much in details here, but the system has been created with flexibility in mind, and fast complexe behaviors creation. Sensors automatically create Cells, wich have automatic values history tracking and others cool features, behaviors and controllers ( a controller is permanent / parallel behavior in this system)  has weight, randomness, priority, cooldown and all you can dream to help the brain decide wich behavior to execute. Let’s see how does it look into the editor (here in play mode) :

Brain Tool showing behaviors

Brain Tool showing behaviors

Cells, Sensors, Controllers...

Cells, Sensors, Controllers…

You can also notice in the 3D viewport some lines and differents shapes wich are sensors debug informations, like creature’s field of view etc. etc.

This brain setup is basic, but already good enough to create unpredictable behaviour  (by the player) .

That’s all for this post, next time i’ll talk a bit about the creature navigation !

The Dungeon kings interface was in place for some weeks now. However i was far to be satisfied with it. Note that it’s about the TOUCH interface for mobile/tablets. The heroes panel was located at bottom of the screen. Nice for a panoramic view. However, there are two problems :

-DK has mainly indoors, so panoramic view is not so well suited. And also, panoramic/large view allow to see more things around, but the field of view’s “height” is reduced : you see smaller portion of the floor/ceil. Not so great as there are items or traps on the floor !

-Secondly, the game run on different devices and screen sizes. iPad has a screen ratio of 1.33 , iPhone 4/4S 1.5, iPhone 5/S/C, Nexus 7, LG G2 have a 1.7 ratio ! It brings problems when designing an interface based on screen width !

After struggling with the ergonomy, i decided to created a new playfield interface: portraits are now located on the right. Let’s see the new UI:

New The Dungeon Kings Interface

New The Dungeon Kings Interface

The red squares are actually replacing the green bars on the old interface, they are Magic and tireness indicators wich are glowing more or less according the value. Note that you can’t see on the screenshot, but items part is automatically scrolling out of screen when opening the inventory, leaving more room for 3d view and allowing drag and drop from 3d view to inventory slots. Also note that on desktop computers using mouse, you can both take item as cursor, or use drag’n drop like on touch devices ! And at last, the FOV and 3d viewport are being adjusted dynamically when the heroes panel and inventory panel are scrolling to keep a wider 3d view area when screen is partially filled by theses interfaces panels. The Arrow panel will disappear if using swip touch control mode for moving, and will be much more transparent in cursor keys mode.

After playing a while, i am now really satisfied with the current UI  (user interface) layout. On small screens, i am planning to add button to automatically attack/switch heroes, making it easier to quickly attack on the small screens : hit the button, to launch an attack with curently selected hero, then after the attack is launched, the game will automatically switch to next hero, waiting for you to press again the button and repeating the process. Of course the game will decide wich hands / attack to launch for you. Keep in minds this is purely optional and targeted to small screens only.

I am finally glad i spent time to change the ui, and feel so motivated to go on creature fighting !!!

Compare the ui to old layout :

Old ui layout

Old ui layout

 

The new interface features much less lost in 3d viewport height, and more convenient to use for mobile device !

Now back to creature fighting !!