Home   Help Search Login Register  

Author Topic: Ambient civilian traffic  (Read 6001 times)

0 Members and 1 Guest are viewing this topic.

Offline Trexian

  • Members
  • *
Ambient civilian traffic
« on: 24 Sep 2009, 14:45:34 »
I have a rough proof of concept working for ambient civilian traffic.  I've attached my super-generic test mission.  Basically, just start it and wait for the traffic to start. :)

The framework starts with the ambient civilian module.  Each civilian is initiated with a  40% chance of spawning a civilian vehicle (from a local array).  That vehicle is then assigned a move waypoint (either within the town where it spawned or a neighbor) and a cycle waypoint.  For now, the civs basically just leave the city, but it won't be difficult to spawn them outside and have them enter the city.

I still need assistance in a few areas.

Ambient Civilian Module:
From the Biki (and experience in a mission I'm also making) I know the syntax to set an init line for a civ is
Code: [Select]
[**location**,"ALICE_civilianinit",[{**code**}]] call bis_fnc_variablespaceadd;

but, I don't want to specify a particular location.  I want ALL civs to have the init, regardless where they are.  I've worked around it by having the init.sqf create a list of all the city centers (BIS location function) and a forEach that runs through every one.  That's rather inelegant.

I've tried syntax such as
Code: [Select]
[bis_alice_mainscope, "ALICE_civilianinit",[{if ((random 1) < .4) then {[_this] execVM "JTD_ambientCivTraffic.sqf"};}]] call bis_fnc_variablespaceadd;
and the civs just don't spawn.  I know (from mistakes... err "experience") that the first element in the array passed to variablespaceadd should be an object, location, etc.  I also tried a setVariable for ALICE_civilianinit and it didn't like it.  Like I said, I just want something to put that init on every spawned civ.  Ideally, either in the initialization of the ALICE module, or in a GL.

MP Players:
For now, this is SP only, because I need to delete the vehicles based on proximity to the player.  As it stands in the proof of concept, when the civ that triggered the vehicle-spawn is removed based on the ALICE logic, the vehicle should be deleted.  I would prefer to have the cycle waypoint contain code or execVM a script to check if the vehicle is near any players.  If not, then delete.  If it is, then wait for it to come back to the cycle waypoint.  The only way I can come up with is to use an inelegant check of allGroups to see if a player is in any group.  What is the best way to see if an MP player is near a location?

ALICE FSM:
I originally wanted to put the originally spawned civs behind the wheel.  However, a moveInDriver didn't work, and an assignAsDriver followed by moveInDriver did work - the civ got in the vehicle, and even started the engine - but then they promptly got out and started moving onto their other wps apparently.  Any suggestions on how to disable the ALICE-based logic?  Oh, one thing I didn't try (dammit, why do these ideas only come to me when I'm posting?) is to delete all current waypoints, then generate the new ones....

Thanks in advance, as usual. :)

Edit:
Also, in going through kju's AllInOneConfig from d-h, I found this interesting tidbit.
Code: [Select]
class drive
  {
  condition = "_twnthreat <= 1 && _twnthreat >= 0 && !isnil 'bis_silvie_mainscope' && {_x getvariable 'ALICE_threat' <= 1} count _nearbyTowns > 0 && getnumber(configfile >> 'cfgvehicles' >> typeof (_this select 0) >> 'woman') == 0;";
  fsm = "ca\modules\alice\data\actions\safe_drive.fsm";
  rarity = 0.01;
  locked = 1;
  canRepeat = 0;
It looks like the ambient civs already have a 1% chance to drive, as long as the ambient vehicles are there, also.  Now, that has a couple problems.  One is that because of the algorithm it uses to decide how many civs to spawn, the only chance of getting that many is in the big cities like Chernogorsk.  Also, it looks like it is influenced by some threat calculation.

Is there some way to change the condition/probability via script?  Or, I guess an addon-type thing that changes the config?  (That rapidly fades into stuff way beyond my ken....)

Edit:
Updated to a version I did on 29 Sept.  Too much traffic, but am working on it.
« Last Edit: 14 Oct 2009, 02:22:10 by Trexian »
Sic semper tyrannosauro.

Offline Trexian

  • Members
  • *
Re: Ambient civilian traffic
« Reply #1 on: 31 Oct 2009, 04:42:58 »
Ok.  I think I got it mostly working. :)

I introduce what may be my first substantive contribution to ArmA-kind. :)

JTD_ACTON - Ambient Civilian Traffic On Nodes (ok, that may not be the final name).  It requires the placement on the map of the ambient civilian module (ALICE), and then the JTD Ambient Civilian Traffic module.  After that, any city you go to should have some traffic.

Attached is the addon JTD_ACTON pbo (place in @JTD\addons - which you should already have because you have JTD_FireAndSmoke) ;) and a simple test mission.

The mission consists of you in a city.  Give it a few minutes, and you should start to see some traffic.  Get in the nearby red 4x4 and you can drive to other cities, where you should also see some traffic.

I consider this alpha testing.  Once I have it tweaked and such, we can either move this to betatesting, or I can start a new thread there.

Thanks go to DMarkwick, OFPEC, and dude SNKMAN at BI forums - he made a couple posts that set up the basic config I used to make my scripts into a module. :)
Sic semper tyrannosauro.

Offline tcp

  • Members
  • *
    • Violator Gaming
Re: Ambient civilian traffic
« Reply #2 on: 31 Oct 2009, 07:46:59 »
 Where do I apply it? :P
« Last Edit: 31 Oct 2009, 07:59:34 by tcp »

Offline Rommel92

  • Members
  • *
Re: Ambient civilian traffic
« Reply #3 on: 31 Oct 2009, 11:38:14 »
OR for an all in one system, shame its unusable because my core components are missing, but you would get the jist.

Code: [Select]
#define CAR_MAX 8
#define CIV_MAX 24
#define CIV_FLEEING 0.93
#define CIV_RADIUS 50
#define CIV_CAR_RANGE 500
#define CIV_CAR_CHANCE 0.66
#define CIV_CAR_CARGOCHANCE 0.93

if !(RMM_Server) exitwith {};

private ["_classes", "_count"];
_classes = [];
_count = count (configfile >> "cfgVehicles");
for [{_i = 0}, {_i < _count}, {_i = _i + 1}] do {
_actual = (configfile >> "cfgVehicles") select _i;
if (isclass _actual) then {
private ["_class","_scope","_side", "_vehicle"];
_class = configname _actual;
_vehicle = gettext (configfile >> "cfgvehicles" >> _class >> "vehicleClass");
if !(_vehicle in ["Sounds","Mines"]) then {
_scope = getnumber (_actual >> "scope");
_side = getnumber (_actual >> "side");
if (_class iskindof "LandVehicle" && _scope == 2 && _side == 3) then {
_rarity = getnumber (_actual >> "rarityUrban");
if (_rarity > 0) then {
_classes = _classes + [[_class, _rarity]];
};
};
};
};
};
{
private ["_i", "_array"];
_i = 0;
_position = position _x;
_importance = importance _x;
_m = CAR_MAX * _importance;
while {_i < _m} do {
_array = _classes select (random (count _classes - 1));
if (random 1 > _array select 1) then {
_i = _i + 1;
private ["_veh", "_pos"];
_veh = createvehicle [_array select 0, _position, [], 50 * _i, "FORM"];
_pos = position (nearestBuilding _veh);
_pos set [0, (_pos select 0) + random 10];
_pos set [1, (_pos select 1) + random 10];
_veh setpos _pos;
_veh setvelocity [0,0, -1];
_veh setdir ((random 1) * 360);
};
};
private ["_count", "_code"];
_count = CIV_MAX * _importance;
_code = {
_position = (_this select 0);
_group = (_this select 5);
_group allowFleeing CIV_FLEEING;
_array = [_position, CIV_CAR_RANGE, "Car"] call RMM_f_nearVehicles;
_units = (units _group) - [leader _group];
{
_veh = _x;
if (count _units == 0) exitwith {};
if (side _x == civilian) then {
if (locked _x) exitwith {};
if (random 1 > CIV_CAR_CHANCE) then {
private ["_driver","_crew"];
_driver = _units select 0;
_driver assignAsDriver _veh;
_driver moveInDriver _veh;
_crew = [];
_seats = _veh emptyPositions "cargo";
_units set [0, "^*&"];
for "_i" from 1 to (_count - 1) do {
if (random 1 > CIV_CAR_CARGOCHANCE) then {
if (_seats > 0) then {
_crew set [count _crew, _units select _i];
_units set [_i, "^*&"];
_seats = _seats - 1;
};
};
};
_units = _units - ["^*&"];
{
_x assignAsCargo _veh;
_x moveInCargo _veh;
} foreach _crew;
_veh setfuel 1; _veh setdamage 0;
_destination = (position (RMM_MAP_Towns select round(random count RMM_MAP_Towns)));
_veh commandMove _destination;
};
};
} forEach _array;
[_group, _position, CIV_RADIUS, "SAD"] call RMM_f_taskWaypoint;
[_group, _position, CIV_RADIUS, "CYCLE"] call RMM_f_taskWaypoint;
};
[_position,"CIV",_count,_code, true, grpNull] call RMM_f_ASM;
} foreach RMM_MAP_Towns;
« Last Edit: 22 Jun 2013, 05:58:44 by Rommel92 »

Offline Trexian

  • Members
  • *
Re: Ambient civilian traffic
« Reply #4 on: 31 Oct 2009, 14:18:46 »
@tju - just create a mission, then place the BIS ambient civilian module, then place the JTD Ambient Civilian Traffic module. :)  Wherever the BIS civs spawn, there will be some traffic. Or, there is supposed to be....

@Rommel - will study that!  One of the longer-term action items was to derive the car types from the config.

I wanted something that would be easy to use, and integrate with the BIS modules. :)
Sic semper tyrannosauro.

Offline Trexian

  • Members
  • *
Re: Ambient civilian traffic
« Reply #5 on: 05 Nov 2009, 21:12:02 »
Shyte!  If I'd only waited a few hours, I would've been able to post here instead of BI forums! :D

http://forums.bistudio.com/showthread.php?t=89775

Will post in beta board a new thread, though.  :thumbs:
Sic semper tyrannosauro.

Offline Trexian

  • Members
  • *
Re: Ambient civilian traffic
« Reply #6 on: 17 Nov 2009, 16:02:17 »
Update for 17 Nov:

Link to more or less release candidate version. :)

http://www.mediafire.com/file/czntmhojy5z/JTD_ACTON_01d.7z

Includes a readme, signature/key files, and should work.  I haven't put together this kind of package before, so probably messed something up. :)

Once I get some feedback that this works, it'll probably be a real release. :)
Sic semper tyrannosauro.

Offline Trexian

  • Members
  • *
Re: Ambient civilian traffic
« Reply #7 on: 16 May 2010, 04:28:32 »
Ok ladies, alpha version (really more like beta, but close enough) of version 2 is here:
http://www.mediafire.com/file/nuzr2d1zozg/JTD_ACTON_2a.zip

I'm reluctant to have the wonderful community mirrors host it yet, only because it has only been tested by me, and it isn't signed.  If you guys decide you want to, no problem, but if this goes well, I'll probably have a signed version within a week or so.

(Famous last words, those.) ;)

Anyway, there is a readme, but it could probably stand to have a fuller pdf to really detail how it works.  There is quite a bit changed in the mechanics of it, but here is the portion of the readme that covers the major changes:
Quote
ADDITIONAL FUNCTIONALITY IN VERSION 2

Implementation:
ALICE -
This is the same implementation as in version 1.  Place an ALICE module, and the traffic will spawn any time an ALICE civ spawns.


Config cities/towns -
By default, civs will spawn in all cities/towns identified in the config for the island.  However, this is time-consuming at the start of a mission if there are many such cities/towns.  Plus, on a map with many cities/towns, it is possible to quickly run out of available groups to spawn civs in.  Something is different from ArmA1, and the trigger formulation I used before now results in civs being spawned immediately.  So, the first ~100 groups of civs will be assigned to the first cities/towns in the config.

Markers -
By placing markers in areas where you want civs, they will only spawn in those locations.  To accomplish this, you MUST set the JTD_civMarkerArray variable.

JTD_civMarkerArray - array - default = nil;
** This is required to designate which markers will spawn civs.  In the init line of the module, write:
this setVariable ["JTD_civMarkerArray", ["nameofmarker1", "nameofmarker2"]];

In that example, you have named the markers nameofmarker1, nameofmarker2.  You can have as many markers as you need.  Also, you can overlap or "nest" markers in various areas.  Have a big marker over an entire city, then smaller markers in neighborhoods where you want more dense concentrations of civs.

Feedback is not only requested, but required. :)

I've tested all 3 implementations in Utes, Pantera and Chernarus (and elsewhere).  The marker way is really best from a designer perspective, and while the city function method is easiest, it really isn't workable for maps like Chernarus, and even Pantera, where there are many defined cities in the config.  (I'm going to have to build in some error-catching or limit the city functionality somehow.)  ALICE is the best balance between easy and effective in that instance.

Anyway, apologies for mistakes that are sure to be in there.  I am (again) pushing the edge of my scriptological skeels with this.  You all are just along for the bumpy ride!  And thanks for the support.
Sic semper tyrannosauro.