Forum Archive

Go Back   3D Realms Forums > 3D Realms Topics > Duke Nukem > Duke Nukem 3D Modifications
Blogs FAQ Members List Social Groups Calendar Mark Forums Read

Notices

 
 
Thread Tools
Old 05-25-2008, 03:10 AM   #1
Jblade

Jblade's Avatar
Best way to do friendly AIs?
I know there's already a coding topic, but I thought this topic is one that's on a lot of people's minds so a thread dedicated to it might help more in the future.

I've got a few TCs that could really use something like this, but of course the huge problem is how to do it effectively. There's quite a few commands that can be used to help but I myself have no idea where to start when it comes to getting enemies to advance towards each other and shoot properly rather than the player, as well as actually finding a target in the first place.

Any advice would be greatly appreciated.
Jblade is offline  
Old 05-25-2008, 10:14 AM   #2
DeeperThought

DeeperThought's Avatar
Re: Best way to do friendly AIs?
For targetting you could use findnearactor directed at the target tile number, but there are two problems with that: 1) It will find dead bodies, which you don't want to be shooting at, 2) it only finds a specific tile number, which is bad if there are several different units on each side. So what you do is you make everyone spawn a special invisible target sprite. The special sprite sticks to the actor which spawned it like glue, and it dies when its owner dies. Then other actors look for the target sprite to set a target (and they can get its owner if they need to know about who spawned it). You can make different picnums of target sprites for the different sides in the war, so depending on which side an actor is on it only looks for a certain type of target sprite.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 05-25-2008, 11:05 AM   #3
Jblade

Jblade's Avatar
Re: Best way to do friendly AIs?
That makes sense, but the only problem with that is findnearactor always returns the first one it finds, and if that first one is hidden behind a wall it'll get 'stuck' on that one and not notice any of the others unless they get closer. At least that's the trouble I had with that approach when I tried it before.
Jblade is offline  
Old 05-25-2008, 11:13 AM   #4
DeeperThought

DeeperThought's Avatar
Re: Best way to do friendly AIs?
Quote:
Originally Posted by Jblade View Post
That makes sense, but the only problem with that is findnearactor always returns the first one it finds, and if that first one is hidden behind a wall it'll get 'stuck' on that one and not notice any of the others unless they get closer. At least that's the trouble I had with that approach when I tried it before.
Code:
state botfindtarget
setvar target -1
findnearspritez SHOOTME 4096 32768 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget
ifvarn target -1 break
findnearspritez SHOOTME 8192 65536 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget
ifvarn target -1 break
findnearspritez SHOOTME 12288 98304 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget
ifvarn target -1 break
findnearspritez SHOOTME 18432 147456 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget
findnearspritez SHOOTME 32768 262144 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget
ends
This is what my bots do (SHOOTME is the target sprite of course). There's important stuff going on in validatetarget that you can't see, but basically it makes sure that the bot is actually able to shoot at the target, and if not it resets target to -1. Note that my bots only do this every once in a while, because the findnear commands take a lot of cpu.

An alternative to this approach is to keep all the potential targets in an array, and then periodically check the array for the best target.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
DeeperThought is offline  
Old 05-25-2008, 02:24 PM   #5
Jblade

Jblade's Avatar
Re: Best way to do friendly AIs?
Well that definitly helps, thanks I'll get it working first before concerning myself with things like height differences and wherether things are blocking it (although really the AI would mostly be used in sparse maps so this won't be too much of a problem)
Jblade is offline  
Old 05-25-2008, 02:53 PM   #6
DeeperThought

DeeperThought's Avatar
Re: Best way to do friendly AIs?
Quote:
Originally Posted by Jblade View Post
Well that definitly helps, thanks I'll get it working first before concerning myself with things like height differences and wherether things are blocking it (although really the AI would mostly be used in sparse maps so this won't be too much of a problem)
That code that I posted doesn't really help with the wall problem very much, because if it finds an enemy behind a wall the first time, it's just going to keep finding it. The main use of that routine is that it makes targets close by higher priority than targets further away, because closer targets are found first. That feature does help with the wall problem somewhat, because typically a monster behind a wall is a bit further away than other monsters in the area.

Another thing that I do which does tend to help is, when a bot gets shot, it checks out who shot him and makes it his target if it is an enemy and he can see it. So if he is obsessing about a monster behind a wall, getting shot by another monster will snap him out of it.
__________________
DUKE PLUS
New map effects and various optional extras for Duke 3D.

DUKE NUKEM: ATTRITION
XP based weapon upgrades, progressive difficulty, and more.
Last edited by DeeperThought; 05-25-2008 at 02:56 PM.
DeeperThought is offline  
Old 05-25-2008, 03:05 PM   #7
Jblade

Jblade's Avatar
Re: Best way to do friendly AIs?
The bot getting shot is a good idea actually - It would be nice to have this all just built in but I think that's asking for a bit much heh. Still it's a lot of work for something that Doom seems to have, but that stuff was built into the original game due to the infighting and things so it's probably the same case of "they don't work anything like each other" that a few other things are.

EDIT: Saying all that, it just makes it a million more times satisfying to see your bots massacre a horde of enemies:

It was kinda one-sided, what with them having no ability to die or even be targetted yet, but still
Last edited by Jblade; 05-25-2008 at 04:03 PM.
Jblade is offline  
Old 05-25-2008, 06:38 PM   #8
Reaper_Man

Reaper_Man's Avatar
Re: Best way to do friendly AIs?
Of all of the additions to EDuke32, I really wish improved / added AI functions would be really kick ass but I don't think it is going to work.

Putting all of the available actors into an array works wonders and I would suggest doing considering that if you haven't already. It has some amazing benefits - such as being able to go through the array to determine who is closest, how many of them you can see, if any of them are dead, and so on.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 05-26-2008, 12:12 PM   #9
Jblade

Jblade's Avatar
Re: Best way to do friendly AIs?
I have no real idea how to work with arrays; I imagine if I knew C it'd be alot easier but I don't - it's something I'll have to tackle since I want to add waypoints for NPCs and stuff eventually
Jblade is offline  
Old 05-26-2008, 01:20 PM   #10
Reaper_Man

Reaper_Man's Avatar
Re: Best way to do friendly AIs?
You don't necessarily need to know about C to understand arrays, arrays are a fairly integral part of most programming languages. They allow you to keep track of information in an organized way.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 05-26-2008, 05:49 PM   #11
Dr. Kylstien
Re: Best way to do friendly AIs?
EDuke arrays and C arrays are both arrays. The similarities pretty much end there. Also, the wiki has some information on them.
Dr. Kylstien is offline  
Old 05-26-2008, 05:56 PM   #12
Reaper_Man

Reaper_Man's Avatar
Re: Best way to do friendly AIs?
Quote:
Originally Posted by Dr. Kylstien View Post
Also, the wiki has some information on them.
I plan on expanding the info there greatly once I get a handle on them myself. It's a little lacking to say the least.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
Old 05-26-2008, 06:09 PM   #13
Dr. Kylstien
Re: Best way to do friendly AIs?
Quote:
Originally Posted by Reaper_Man View Post
I plan on expanding the info there greatly once I get a handle on them myself. It's a little lacking to say the least.
When I originally wrote those articles I just wanted something to refer to for syntax if I forgot it. I've just expanded the entry for gamearray to provide a slightly more detailed explanation. I think it would benefit greatly from some example code right now.
Dr. Kylstien is offline  
Old 05-26-2008, 06:13 PM   #14
Reaper_Man

Reaper_Man's Avatar
Re: Best way to do friendly AIs?
Thanks for filling in the "size" parameter, I was pretty sure that it was the maximum number of values it could hold but I just wanted to be sure!

Any idea if per-player and per-actor arrays is going to happen? Global arrays are useful to an extent, but per-actor arrays would kick my ass up and down Main Street.
__________________
The Once and Future King
msleeper.com :: Digital Entertainment Design
The AWOL Project :: The Best Damned TC Never
Super AI Project / Duke RTS :: Coming Soon to an Actor near you!
Artificial Intelligence 101 :: Ask AI questions, get AI answers
Reaper_Man is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 01:44 PM.

Page generated in 0.16253591 seconds (100.00% PHP - 0% MySQL) with 18 queries

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.

Website is 1987-2014 Apogee Software, Ltd.
Ideas and messages posted here become property of Apogee Software Ltd.