Home   Help Search Login Register  

Author Topic: Automatically joining infantry groups  (Read 2495 times)

0 Members and 1 Guest are viewing this topic.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Automatically joining infantry groups
« on: 25 Mar 2005, 07:55:40 »
Is this likely to be of any interest?   I use this sort of thing a lot.

As groups take casualties during a mission you can often end up with many small groups of soldiers.  These groups will not behave in a coordinated way and are more prone to fleeing than larger groups.

This script will combine small infantry groups to make larger ones.  There are many ways this can be done.  The method used here is to:
- join groups that are further from a specified object to groups that are closer to that object
- ignor units that are inside vehicles

This can be used for example where a base is being attacked and you want any 'spare' infantry to join groups that are close to the centre of the base.


The script is dynamic in that it will automatically pick up any new infantry groups.  For example if the crew of a vehicle disembark then this script will detect them and inculde them in future consolidations.  So all those survivors from destroyed tanks will be picked up by the script and will join up with other infantry groups.  This creates a high level of realism and randomness.

called by:  [object,minOkaySize,maxOkaySize,AllUnits] exec "JoinUpUnits.sqs"

  Object is an object that is used to determine which groups join together.  
  A group will join to other groups that are closer to the object than they are.

  minOkaySize is the size of the smallest group that will not try to join another group

  maxOkaySize is the largest size that joining groups will form.

  AllUnits is an array of all the units that are to be considered for joining up.
  This can be created by having a trigger that covers the map, and then using: list triggername


The script counts the number of units in each group to determine whether or not to join the group to another.  This is better than counting the number that are alive in the group because count reflects the current perception of the leader of the group of how many in his group are still alive.

Sample Mission:
This does not look very spectacular, but it does show how effective the script can be.  

You start as the commander of a tank with a lone West soldier, a lone Resistance soldier and a lone civilian in front of you.  You can start the script using your radio, and a short time later the other west soldiers, resistance soldiers and civilians will join up with the units in front of you.  If you get out of the tank you will then also be caught by the script and will join the west group.  That is assuming you don't move into the centre of Chapoi.  If you do you may find that all the west soldiers join you.  The reason for this is that I have chosen object 50041 as the point around which units will join.  Units and groups that at are close to this point will have other units and groups join them.  Object 50041 is the water fountain at Ef72.  Obviously the user can specify any object in the game.
« Last Edit: 26 Mar 2005, 06:30:18 by THobson »

Offline Blanco

  • Former Staff
  • ****
Re:Automatically joining infantry groups
« Reply #1 on: 25 Mar 2005, 09:22:10 »
Tested. Very nice script.

Also very usefull for tankcrews who lost their tank and survive, they don't just flee or hide anymore.

btw, I saw a note in the script :

Quote
;If instead of joining up groups depending on their location you prefer to join small groups to large ones then replace the above line with:

Does this mean that small groups automatically join to a larger group regardless their position?

I've wrote a regroup script a few weeks ago, but this one is waaaaay better...






« Last Edit: 25 Mar 2005, 09:35:53 by Blanco »
Search or search or search before you ask.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Automatically joining infantry groups
« Reply #2 on: 25 Mar 2005, 10:17:16 »
First of all thanks for the comments.

There are three lines relevant to your question:

Code: [Select]
if (((leader _grpi) distance _obj)  > ((leader _grpj) distance _obj)) then {units _grpi join _grpj} else {units _grpj join _grpi}

;If instead of joining up groups depending on their location you prefer to join small groups to large ones then replace the above line with:
; if ((count units _grpi) < (count units _grpj)) then {units _grpi join _grpj} else {units _grpj join _grpi}

The first line is active and causes the groups to join up depending on how close they are to the specified object.  If instead of that you want then to join up so the smallest joins the largest then that line should be commented out and the last line should have the ; removed from it so that it becomes active.
« Last Edit: 25 Mar 2005, 20:51:56 by THobson »

Offline Blanco

  • Former Staff
  • ****
Re:Automatically joining infantry groups
« Reply #3 on: 28 Mar 2005, 04:56:09 »
THobson, does this script catch created units?

Because I 've used your script with a simple spawnscript and the new created units doesn't join other groups.
I add a "killed" eventhandler that runs a spawnscript to create a second line so they can support other groups in the field but the new units doesn't seem to be catched by the joinup script.
Can you try the test and tell me what I'm doing wrong?
Just stay at the flagpole and wait for hints when the units are created or... when you got bored hit 0-0 to start camera.sqs and watch the fight. You can switch back to the player when you hit the v-key  :P

**edit**

It seems to work when I move the #mainloop label on top of the script, just below _obj = _this select 0  :D
 


« Last Edit: 28 Mar 2005, 06:04:33 by Blanco »
Search or search or search before you ask.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Automatically joining infantry groups
« Reply #4 on: 28 Mar 2005, 10:34:03 »
A couple of points (edit: well it turned out to be more than 2):

The first script I put here was taken from my current mission so it was tailored to that.  I have significantly improved the generality of the script.  See:
http://www.ofpec.com/editors/resource_view.php?id=788
The new script does not need to make any assumption about what triggers are available etc.  I submitted it in view of not getting many comments on it here.

You are correct.  The scripts will not catch spawned units - I didn't think of that because I never spawn them.

It also will not catch units that move into the trigger area.  I did consider having it do that.  The reason I didn't was that mostly the script will be used with triggers that cover the map, and as soon as I have used them and got their list I like to do a deleteVehicle on them to cut down on lag.

You are absolutely correct.  Moving
#mainloop
to just below
_obj = _this select 0
will enable it to catch all spawned units and all units that later wander into the trigger area.  The downside of that is you have to keep the triggers active.

As I said there are many ways this can be implemented.  I used a much cruder piece of code in my mission Defensive Strike  - don't look at it is ugly - but one nice feature about it was that it worked on a global array of loons, so the mission maker could add new groups during the mission.

What do you think - should I change it to pick up spawned units?  It is easy to do.  In my new script I would move the start of the loop as discussed and change the script to allow the input of a trigger name rather than a list of loons.

Nice mission.  I didn't press 0-0 quickly enough the first time and was joined to a group and so lost the radio.  There is a line inthe script
:====================
that should be
;====================

EDIT:

I had a bit of spare time today so did modify the script so that it will capture newly created and respawned units.
« Last Edit: 28 Mar 2005, 15:52:35 by THobson »

Offline Blanco

  • Former Staff
  • ****
Re:Automatically joining infantry groups
« Reply #5 on: 28 Mar 2005, 17:23:12 »
Perfect  :cheers:

Quote
I didn't press 0-0 quickly enough the first time and was joined to a group and so lost the radio.

You can, when you show the map and use the radio :)

Quote
:====================
that should be
;====================

Oops  :P
*edit*
For the record...
you forgot a ; in front of the line

Quote
TriggerName is the trigger that detects the units to be joined up.


...which causes an error  :)

« Last Edit: 28 Mar 2005, 18:04:31 by Blanco »
Search or search or search before you ask.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Automatically joining infantry groups
« Reply #6 on: 28 Mar 2005, 21:25:23 »
Quote
...which causes an error  
It would cause an error on the script on this thread.  This is still version one here.  It should not cause an error with the script here:
http://www.ofpec.com/editors/resource_view.php?id=788
In fact that script comes with a test mission that uses it.

Quote
You can, when you show the map and use the radio
I learn something everyday
« Last Edit: 28 Mar 2005, 21:27:13 by THobson »