Jump to content

Formation rework


Recommended Posts

@gaius , I will not send you whole file because I have there another changes and you probably do not want them so:

file: /helpers/Commands.js

find function GetFormationUnitAIs and rename it to something like this e.g. GetMergedFormationUnitAIs.

Now find "formation": function(player, cmd, data) should be around line 612 and use renamed function instead old (you need it to form new formation, reform or merge more formations on command)

For rest of not renamed callings, create this function, which is not merging selected units into one formation but keeping existing:

function GetFormationUnitAIs(ents, player)
{
	// Separate out the units that don't support the chosen formation
	let formedEnts = [];
	let nonformedUnitAIs = [];
	for (let ent of ents)
	{
		// Skip units with no UnitAI or no position
		let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
		let cmpPosition = Engine.QueryInterface(ent, IID_Position);
		if (!cmpUnitAI || !cmpPosition || !cmpPosition.IsInWorld())
			continue;

		let cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
		let nullFormation = cmpUnitAI.GetFormationTemplate() == "special/formations/null";
		if (nullFormation) {
			RemoveFromFormation([ent]);
			nonformedUnitAIs.push(cmpUnitAI);
		} else {
			formedEnts.push(ent);
		}
	}
	// No units support the formation - return all the others
	if (formedEnts.length == 0)
		return nonformedUnitAIs;

	let formationUnitAIs = [];
	let formations = ExtractFormations(formedEnts);

	for (let i = 0; i < formations.ids.length; ++i) {
		let fId = formations.ids[i];
		let cmpUnitAI = Engine.QueryInterface(+fId, IID_UnitAI);
		if(cmpUnitAI)
			formationUnitAIs.push(cmpUnitAI);
	}
	return nonformedUnitAIs.concat(formationUnitAIs);
}

 

Link to comment
Share on other sites

2 hours ago, gaius said:

Very nice, Angen. And i guess you will decrease turning rate of formation so its possible to flank a formation. 

Isn’t that already supported?

IIRC, there was a <turn rate> element in the formation xml files.

Link to comment
Share on other sites

1 hour ago, (-_-) said:

Isn’t that already supported?

IIRC, there was a <turn rate> element in the formation xml files.

Yes, there is turn rate, but I am not using it now. I am just turning +/- 12 on button click, but I ll probably turn down movement speed for this action so they will get to turned position slower.

Quote
3 hours ago, gaius said:

Very nice, Angen. And i guess you will decrease turning rate of formation so its possible to flank a formation. 

Currently there is no difference based on side you are attacking formation from.

Edited by Angen
Link to comment
Share on other sites

I inserted your code in my newest version. Works great and is really useful, thanks @Angen. Also my Infantry can now fight better in pure Formation when put on StandGround. I solved it that way, that they heal each other a bit when idle. It is not a perfect solution, but an interesting one and also nice as a tactical move. 

https://0ad.mod.io/formation-fighting-mod

Edited by gaius
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...