Home   Help Search Login Register  

Author Topic: Dynamically spawning civilian AI (alpha)  (Read 3483 times)

0 Members and 2 Guests are viewing this topic.

Offline Trexian

  • Members
  • *
Dynamically spawning civilian AI (alpha)
« on: 09 Oct 2008, 16:56:01 »
Ok.

I'm *really* not sure this stuff is ready for semi-release like this.  Consider this alpha status proof of concept.  But, i0n0s (in the JTD City Functions thread) made it sound like there'd be some interest in this.

One reason for the city functions was to establish a framework for spawning civilians.

These are the initial tests of this idea.

The zip has 2 pbos.  When you enter any city on the map (should be red ellipses showing the general area of the trigger), the civs will spawn.  The number of civs is random, but related to the radius of the city.  Larger the city, the more potential civs.  This is in JTD_CivSpawnInit.sqf.

The actual spawning in JTD_CivSpawn.sqf needs some work.  Each civ is his own group, which means you can quickly hit the max number of groups.  I need to change it to spawn small groups 1-3 AI, but still have them spread out.  Also, this is NOT MP FRIENDLY.  I think I can make it that way, though, using Spooner's tips on arrays (idea is that each civ goes into global array, and is then removed when it is deleted; along with an array of what cities have spawned AI so as not to spawn more in that city).  But for now, this is SP only.

The 01c version in the zip has the civs spawn all around the city.  Unfortunately, this might be within the player's field of view.  Ver. 01c2 has the civs spawn randomly in a 120 degree arc on the opposite side of the town from where the player is.  Or at least, it is supposed to.

When the civs are spawned, they are given random waypoints, so they move around, and should, on occasion, enter buildings.  Also, there is a chance some of the AI will sorta follow the player for awhile.  Unfortunately, the only way I could figure out how to delete them is to have a constantly running script with a distance check that deletes them when they are 500m from the player.  Haven't tested enough to know if this is too much of a CPU drain.

Feedback is welcome.   :good:
---------------------------------
Edit: updated the download to CivTest2b

There is one error (a hint that shows regardless of DEBUG flag).
« Last Edit: 06 Jan 2009, 14:32:26 by Trexian »
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Dynamically spawning civilian AI (alpha)
« Reply #1 on: 09 Oct 2008, 17:27:40 »
For this sort of script, which deals only with server-side AI without any need for interaction with the client machines, it is easy to make it MP-compatible. All you need to do is ensure that JTD_cityInit.sqf has this at the top of the file, so your scripts don't run on clients as well as on the server:
Code: [Select]
if (not isServer) exitWith {};
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline i0n0s

  • Moderator
  • *****
Re: Dynamically spawning civilian AI (alpha)
« Reply #2 on: 09 Oct 2008, 17:34:56 »
Ok, took a look at it and went into Chantico:
First: They have to spawn earlier. Currently at least the city hint came when I'm was nearly in the centre of the down.
Then: Spawn them in buildings or other point of interest. Currently it look like a random spawn. I only got two civilians in the town, the rest runs outside at the border of the town.
Then: Please set their waypoints to slow or normal. Currently they running around which looks strange.
Do you know the waypoint "Dismiss"? When using that waypoint all member of that group start wandering around. May be useful for your purpose and also takes care of the group limit.

And to Spooner:
No. He should use
Code: [Select]
if (isServer) then {yourCodehere}; since exitWith ain't designed to determinate scripts.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Dynamically spawning civilian AI (alpha)
« Reply #3 on: 09 Oct 2008, 17:41:20 »
exitWith does terminate the function, returning the value in the {} to the calling script, but only if it is in the outer scope (if just {}, then it will return nil, of course). Which you use though (if-then or if-exitWith) is really a question of style. Pure structured programming says use the former, but use of a so-called "guard condition" is less cumbersome in my view.
« Last Edit: 09 Oct 2008, 17:43:57 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: Dynamically spawning civilian AI (alpha)
« Reply #4 on: 09 Oct 2008, 18:16:54 »
@ Spooner - sorry for the misplacement.   :good:  But, to be truly MP compatible, I'm afraid that multiple "players" entering the same city will each individually start spawning civilians?  Or, am I completely misunderstanding how the server-side spawning works?  If more than one player enters the city, I only want the civs to do the spawn routine 1 time.  Also, in terms of deleting the civs, I'm not sure how the distance check to player will go if there are more than one player....  I may need to make the check relative to the center of the city being used.

@ i0n0s - thanks for the feedback!  Did you run the 01c or 01c2?  Either way, you are right, the civs start spawning at approximately the same time as that hint that tells you what city you are entering.  Some tweaking is necessary for the size of the trigger to start spawning the civs.  I suspect it will be something like a percentage 30-50% of the size of the radius calc I use now.  I've experimented a little with spawning them in buildings.  The problem there is that in areas with a small number of buildings, if it spawns alot of civs, it looks like they're all leaving some kind of meeting or something. :D  Part of the routine does find if there are any occupiable buildings within 50m of the spawn point, and if so, spawn in a building.  However, I also noticed that there were ALOT of civs spawning outside buildings.  I may need to revisit this.  And NO! :D  I hadn't seen the "DISMISS" waypoint.  That would be PERFECT. :good:
Sic semper tyrannosauro.

Offline i0n0s

  • Moderator
  • *****
Re: Dynamically spawning civilian AI (alpha)
« Reply #5 on: 09 Oct 2008, 20:48:22 »
exitWith does terminate the function, returning the value in the {} to the calling script, but only if it is in the outer scope (if just {}, then it will return nil, of course).
It terminates the function, but it is not require to do it:
Quote
When you use exitWith not inside a loops, the behaviour is undefined - sometimes it may exit the script, sometimes some other scope, but this is not intended and designed behaviour of this command, and it is not guaranteed to work reliably.
exitWith (BIKI), see "description" (added by suma, so should be correct). Therefor we should avoid exitWith to terminate a script.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Dynamically spawning civilian AI (alpha)
« Reply #6 on: 10 Oct 2008, 02:50:44 »
@Trexian: Ah, yes, you are quite right, there are several other issues I didn't consider. Sorry, I didn't actually read your scripts, except as far as to realise they needed to be run only on the server. For the sort of system you are talking about, you'd need to count the number of people within a zone using isPlayer, since of course, there is no player object on the server. So, as you say, more complex changes would be needed than I suggested :whistle:

@i0n0s: Well, you certainly have a point there, and if anyone except Suma had written that I would happily ignore it, since I take everything in the BIKI with a pinch of salt (It has worked consistently for me and a lot of people to break out of the current scope, regardless of type, for some time). Also, since it both runs and returns the value inside the {} to the outer scope, this doesn't really make sense for loops, but does for most of the other possible types of scopes.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: Dynamically spawning civilian AI (alpha)
« Reply #7 on: 10 Oct 2008, 05:37:23 »
@Trexian: Ah, yes, you are quite right, there are several other issues I didn't consider. Sorry, I didn't actually read your scripts, except as far as to realise they needed to be run only on the server. For the sort of system you are talking about, you'd need to count the number of people within a zone using isPlayer, since of course, there is no player object on the server. So, as you say, more complex changes would be needed than I suggested :whistle:

Let me bounce this idea off of you. :)  What if it stayed local-side.  If there was an array that prevented civs from spawning more than once per a player visit, then what would be the downside?  A lag between when they were created on the one machine and when they were seen on the other machines, would be one thing, I think.  But this is more for ambiance anyway.  Except for those Geneva Convention be-damned moments, :) these AI are really just going to be part of the scenery.  And, there's the risk that if the MPers were too spread out, one might see the spawning of the civs - popping up from nowhere.  But, to me, those seem like negligible issues, although I'm open to being corrected. :D

I admit I don't do much MP, so that side is even more of a mystery than the regular stuff to me.
Sic semper tyrannosauro.

Offline Trexian

  • Members
  • *
Re: Dynamically spawning civilian AI (alpha)
« Reply #8 on: 06 Jan 2009, 14:43:43 »
Ok, still Alpha status, as I realized after zipping it all up that there's an error in one of the hints (it shows regardless whether there "DEBUG" flag is set).

Here is the idea.  The mission has an init.sqf with a single line:
Code: [Select]
["", "", 1, 1] execVM "JTD_CityInit.sqf";

The first param can either be empty "" or "DEBUG" or "MARKERS."  (You can put anything else, but it will end up being the same as "".) :)  Debug shows a bunch of hints that I use to show me where I'm messing up.  Markers shows the markers on the map, but not the hints.  Empty doesn't show anything.

The second field is either empty or "PLAYERONLY" for the triggers.  Empty, and any unit will trigger the triggers - which in this case will spawn civilians.  "PLAYERONLY" will make it so only the player will trigger the triggers.

The third field modifies the size of the radii for the markers/triggers.  Default is 1.  The scripts will multiply the size times the modifier.  So, if you want the triggers half as big, the value should be .5.  Twice as big should be 2.

Same idea for the fourth field, which is the number of civs to spawn.  It will generate a random number based in part on the size of the trigger radii.  That number is mulitplied by the modifier.  Want fewer civs generated, put in a small number like .5.  Want more, then put 2 to double it.

This script relies on somewhat updated versions of these scripts:
http://www.ofpec.com/forum/index.php?topic=32328.0

The mission just puts you in a spot with a motorcycle or a helo to travel with.  There are (dynamically created) triggers in the cities/towns that spawn the civilians when a unit activates it.  Problem with the helo is that if you go too fast over/through a city, you're not likely to see civilians.

My preference was to imitate an urban area in a war zone - civilians are still there, just not many, and they don't likely want to be around bullet-magnet soldiers.  Of course, in the ArmA world, the only civilians are able-bodied, military age young men.  :doh:  And, there are still some AI issues: loiterers (guys just standing around, although I've alleviated alot of this behavior by just trial and error), guys walking off of the tops of buildings, and some walking-through-walls things when viewed from a distance.

But, I think overall this can add to immersion.

(I've attached the test mission to this post, as well as editing the original.)  I can post the scripts, too, if someone is interested.

Edit: Oh, and this MIGHT even be multi-player friendly.  Maybe.  I haven't tested it, but I've included some things that I think will help make it that way.  Maybe.  Keep in mind I'm an utter n00b.

Edit2: Oh, and I think the mission included in this has the following init, which activates the debugging hints.
Code: [Select]
["DEBUG", "", 1, 1] execVM "JTD_CityInit.sqf";
« Last Edit: 06 Jan 2009, 15:11:11 by Trexian »
Sic semper tyrannosauro.