Tuesday, September 26, 2017

Update 51: Emerging AI

Next on the list was AI. I had a plan for this. Since most interactions are over in 2-3 turns, I don't think I have to worry about a higher AI (where the AI is trying to think long term). I think, (at least initially), I just want to encourage the AI to move towards the player and be fairly aggressive, staying in cover and shooting if the chance to hit is high. These ten rules are definitely just a starting point.

  1. Find all possible tiles the character can move to, initializing them with a score of 0.
  2. Assign points to any tiles that are in cover (+10). If the character is currently not in cover, give all of those positions an extra boost to encourage the character to move into cover. (+10)
  3. Add points for tiles that are in range for the character to shoot at the opponent. (+10)
  4. Add points for tiles that close the gap between the AI and opponent. (+5)
  5. Add points for positions in cover that flank the opponent (+20)
  6. Add points if the opponent is within range and has more than a 50% chance to hit. (+10)
  7. Add even more points if the chance to hit is 80% or more. (+20)
  8. Add even more points if the chance to hit is 95% or higher. (+30)
  9. Order the list by total score, descending order (highest first)
  10. Pick the top score from the list. 

When I add difficulty levels later, I will randomize the top 3-5 scores and pick one. This will help to give the AI some unpredictability and ensure that it's not always brutally taking the best position. Everyone makes mistakes, and it's important the AI does too (except on maybe the highest difficulty level). I may do this sooner than later to keep things interesting.

This AI is currently working, but I have some timing issues, where the AI moves into cover, but fires his weapon for his second action before he has completed his first action. 

Here is a series of screenshots showing the AI's at the beginning of a turn (standing out of cover), and then moving to cover and shooting at the (flanked) player. 

This one is showing the timing issues I have, where the AI fired (action 2) before completing his walk to the new cover (action 1), in the process destroying the cover.




Next I'm going to tweak the timings so the actions are one at a time and add side steps to the characters so that when behind cover they don't shoot out their own cover, but step to the side and shoot around the cover.

Thursday, September 14, 2017

Update 50: Combat and 50!!

5 years and 50 posts later, here we are, still working through the combat mechanics. Amazingly, I'm still making regular progress. I think the keyword here is regular, there have definitely been some large gaps in progress.

However, the combat is proceeding along nicely. I've added projectiles and the destructive terrain back. I've added back the shoulder cam when you are aiming and choosing your target. The enemy and player are now dealing (and receiving) damage. I almost have a quasi game here. 

Here you can see the setup of the level, with the second (shoulder) camera ready



The view from the shoulder cam. The models really look low res here!

Boom!


 Before the shot...

"Missed", that is the end of that wall!


Here you can see the ray-cast passing through the enemy, it was a hit!


Next on the list is basic AI, it's time for the enemy to respond to your actions and try to defeat you. 

Thursday, August 31, 2017

Update 49: Added weapons to the characters

I have now added weapons to the characters. The Simple Military pack has a variety of weapons, but at this stage, I've assigned a 'modern assault rifle' for the 'good guys', and a AK47 for the 'bad guys'.




I also added a muzzle flash when the gun shoots (it shows for just a fraction of a second).




Next I will add projectiles and add back in the destructive environment that I started with, all those years ago.

Sunday, August 27, 2017

Update 48: Implementing the turn state diagrams

Next I've been working on implementing more of the game, which is a big departure of most of my posts, where I've been working on game mechanics, usually in isolation. I'm calling this the "player state diagram". You can see this represented in a state diagram below. Also encased in the diagram is a road map of the features I've implemented and what I plan to implement next.




When a player has finished all of their moves, it switches to the enemy turn, where the (overly simplified AI) decides to just pass ("Patrol"), and switch back to the player. Since the player still can't attack, I think this is fair. 

Next we need to add AI to the player to move into cover and shooting between the two teams...

Tuesday, August 22, 2017

Update 47: Cover and Flanking

In my last update I showed a screenshot with a soldier in cover. In this latest update, I've added an enemy and added the code that marks the players as in cover or being flanked/out of cover.

Here my player is in cover (the enemy has a lower chance of hitting the player and dealing damage):




Here my player is flanked and not in cover (the enemy has a much higher chance of hitting the player and dealing critical damage):


There was actually quite a lot of rework involved in the code and corresponding systems to get the enemy soldier to (re-)appear and have everything work. The next update will be even more involved as I refactor the code into more systems and add more players and enemies - adding turns that switch back and forth after movement.

Monday, August 14, 2017

Update 46: OpenTile

Two years can really fly by. Growing families, big work projects, small home projects, and as many distractions as you can throw at a sticky wall, here I am. I haven't been doing nothing, I just haven't been writing about it. I'm trying to change the not writing about things problem today.

One of those mini projects I've been working on is very relevant for this project. About a year and a half ago, I started a GitHub project I've called OpenTile. OpenTile is an opensource solution to create the building blocks and data structures for a tile based game. There is no UI, apart from the ASCII files, but it's being built in C#, with a branch for Unity3d. There is currently functionality for basic path finding, possible available tiles (for movement), cover, as well as a number of utility functions. 

I've found this framework really helpful for building a game. I'm able to focus on fundamental functionality such as path finding or cover in a simple ASCII UI, and then it's much easier to integrate the changes into a full 3d engine - with the confidence that it works.

In the screenshots below you can see two simple examples that show the output of path finding on a large map with varied obstacles.





In Unity3D, this is what the result looks like on a small test map: