Refactored NPC AI Project

#1
Hello everyone!

I've been a huge fan of SCP:CB since I first laid eyes on it back in Halloween, and just last night I started delving into the source code with this grand idea that I should find something to try to improve, then release here to see if it's worth any salt. So anyway, I decided to look into improving the AI of the MTF and guards, and in doing so learned that it'll be hard to make any headway with the way all the NPC logic is stuffed into NPCs.bb, and how the entire logic for each character is a series of flow controls called on every tick of the game engine inside a massive foreach.

So, I'd like to take on a bigger task, and rebuild each of the SCPs so that they can target each other (and the player), as well as switch targets at any time if it becomes more opportune to chase one entity rather than another. In doing so, it would also be possible to implement some complex, fuzzy logic in order to determine under what conditions an NPC will switch targets, which brings us full circle to improving the AI of the MFT and guards.

Anyway, I'm posting here to gather warnings or thoughts from anyone who might have any experience implementing more conventional AI in Blitz3D? Does anyone forsee any pitfalls in doing what I hope to do, or are there any big reasons why this method was avoided in the design of current NPCs? This is also my first time using Basic, though I'm not unfamiliar to programming (suffice to say, the language looks really simple).

To sum up, my goals are as follows:
  • Make each NPC aware of every other NPC.
  • Allow NPCs to focus on a single hostile target, or no hostile target at any time.
  • Allow NPCs to switch targets according to some sort of fuzzy logic, so that they don't immediately focus on the most opportune target 100% of the time, and so they don't switch immediately.
  • Put an end to having everything face the player all the time and lay the foundation for populating the game world with other characters, and have them get hunted down in adjacent rooms to the player in the early stages of the game.
  • Refactor the code so that each NPC gets it's own .bb file, or else NPCs.bb will just continue to get redonculously big as more content gets added to the game.
  • Add more stats to modify abstract things like how quickly NPCs can become aware of others.
  • Possibly add a system for scheduling events on a per-creature basis, rather than "calculating a number each tick between 0 and 500 and checking to see if it = 1 to see if I should make a sound" -sort of design
  • Implement different behaviours for attacking and reading targets depending on whether they are a player or another NPC (dragging an NPC into the pocket dimension should just kill things that aren't the player)
  • [**Edit**] Removing camera zoom behaviour from individual NPCs, and making it a universal behaviour of all NPCs (using data stored in .ini to determine strength and style of effect for each)
On another note, my girlfriend saw me playing, and figured that this game could be a great way to add to her animation portfolio... (though she may have become busy as of recent).
Last edited by OmiSC on Sat Feb 02, 2013 2:50 pm, edited 2 times in total.

Re: Refactored NPC AI Project

#3
This is great, Improved AI has been one of my biggest wants in-game for SCP:CB. You have full permission easily of course and if it's good Regalis could implement it in a future update for the game.

Something I've always really wanted is the MTF to be able to shoot actual bullets in a cone generated from they're gun, with raytraces to detect if they hit the player or not, or hit the walls and leave bullet decals, etc.

Edit:

As well, I had the idea of there being other survivors in-game as the facility grows bigger in future updates. At the start of the game in the distance Dynamic NPC AI actually plays out: Guards spawn at Keter + Euclid + Safe SCP's cells, fight those escaped SCP's or try to run away based on random AI (the guards will almost totally fail all the time); scientists, janitors and Class-D's randomly spawn in areas and attempt to flee and hide in spaces -- only for some of them to be discovered by hunting Euclids + Keter SCP's and most likely horrifically terminated. It would make the game so much more dynamic, random and re-playable along with it's current randomly generated modular room system.

Re: Refactored NPC AI Project

#4
[ Update ]

I've split up the game code into a lot of small files, and dealt with a weird duplicate naming bug where the compiler parses the code in a way doesn't match the way includes work 1:1 (thinking that variables in parallel scopes are being declared on top of each other). I'm working on implementing some universal behaviour for all NPCs so that I can remove some common code from each of the individual NPC cases, hopefully reducing the code some, and offloading some configuration to the NPCs.ini file. For example, many NPCs cause the player's camera to zoom in when looked at, but each NPC rewrites the code that makes this happen in it's entirety.

Also, the states numbering system does not seem intuitive to me. I'm having a really hard time figuring out what states control what behaviour without analyzing the code closely. I think I'm going to try gutting it.

Re: Refactored NPC AI Project

#5
OmiSC wrote:[ Update ]

I've split up the game code into a lot of small files, and dealt with a weird duplicate naming bug where the compiler parses the code in a way doesn't match the way includes work 1:1 (thinking that variables in parallel scopes are being declared on top of each other). I'm working on implementing some universal behaviour for all NPCs so that I can remove some common code from each of the individual NPC cases, hopefully reducing the code some, and offloading some configuration to the NPCs.ini file. For example, many NPCs cause the player's camera to zoom in when looked at, but each NPC rewrites the code that makes this happen in it's entirety.

Also, the states numbering system does not seem intuitive to me. I'm having a really hard time figuring out what states control what behaviour without analyzing the code closely. I think I'm going to try gutting it.
You are awesome, there's so many talented people on this forum now, hehe. I think what you're doing is really benificial to the game. Perhaps you could stop the MTFs from doing that thing where they open a door, go into the nearest corner, and walk into it, it's funny to observe their behaviour in noclip.
Image
I WANT TO [REDACTED] INSIDE TWILIGHT SPARKLE
DRIVER_IRQL_NOT_LESS_OR_EQUAL
Atheros drivers SUCK!

Re: Refactored NPC AI Project

#6
This looks great. For my mod, I'm doing something similar. I'd like to see how this is executed, could create a much nicer experience.

My advice is to split up thought processes. I'd done an AI before, and it was *okay*. But it wasn't in Basic.
Just think basic commands like "If player is aiming/shooting, go to cover", "Player is reloading/vulnerable, fire weapon.", "Player movement is low, lob a grenade", ETC.
Good luck, but for things like my mod, the AI is one of the main focuses.
Image

Re: Refactored NPC AI Project

#7
mrpeanut188 wrote:This looks great. For my mod, I'm doing something similar. I'd like to see how this is executed, could create a much nicer experience.

My advice is to split up thought processes. I'd done an AI before, and it was *okay*. But it wasn't in Basic.
Just think basic commands like "If player is aiming/shooting, go to cover", "Player is reloading/vulnerable, fire weapon.", "Player movement is low, lob a grenade", ETC.
Good luck, but for things like my mod, the AI is one of the main focuses.
I read your post, but I couldn't take it seriously with your avatar. Seriously, what is it, it scares me :cry:
SCP - Box of Horrors v0.8.0b
Twitter
Github Profile

Re: Refactored NPC AI Project

#8
InnocentSam wrote:
mrpeanut188 wrote:This looks great. For my mod, I'm doing something similar. I'd like to see how this is executed, could create a much nicer experience.

My advice is to split up thought processes. I'd done an AI before, and it was *okay*. But it wasn't in Basic.
Just think basic commands like "If player is aiming/shooting, go to cover", "Player is reloading/vulnerable, fire weapon.", "Player movement is low, lob a grenade", ETC.
Good luck, but for things like my mod, the AI is one of the main focuses.
I read your post, but I couldn't take it seriously with your avatar. Seriously, what is it, it scares me :cry:
Can you take my posts seriously?
Image
I WANT TO [REDACTED] INSIDE TWILIGHT SPARKLE
DRIVER_IRQL_NOT_LESS_OR_EQUAL
Atheros drivers SUCK!

Re: Refactored NPC AI Project

#9
Destructoid wrote:
InnocentSam wrote:
mrpeanut188 wrote:This looks great. For my mod, I'm doing something similar. I'd like to see how this is executed, could create a much nicer experience.

My advice is to split up thought processes. I'd done an AI before, and it was *okay*. But it wasn't in Basic.
Just think basic commands like "If player is aiming/shooting, go to cover", "Player is reloading/vulnerable, fire weapon.", "Player movement is low, lob a grenade", ETC.
Good luck, but for things like my mod, the AI is one of the main focuses.
I read your post, but I couldn't take it seriously with your avatar. Seriously, what is it, it scares me :cry:
Can you take my posts seriously?
I used to but...
Image
SCP - Box of Horrors v0.8.0b
Twitter
Github Profile
cron