Jump to content

Recommended Posts

Compatible with SVN, so Alpha 23 as well. You probably did not find any other behaviour because there is none :P.

Its not really a full-fledged mod(atleast not for now), just an experiment to know more about GUI.

  • Like 1

Share this post


Link to post
Share on other sites

@(-_-) I used this in updateGUIobjects, maybe your approach is better, I did not see it whole yet:

function updateFormationSelection()
{
	let selected  = g_Selection.toList();
	let entsAdd = [];
	let used = [];
	for (let sel in selected)
	{
		let state = GetEntityState(selected[sel]);
		if (!state.unitAI)
			continue;
		let formation = state.unitAI.formationController;
		if (!formation)
			continue;
		if (used.indexOf(formation) != -1)
			continue;
		used.push(formation);
		let fState = GetEntityState(formation);
		if(!fState){
			warn("fState does not exist");
			continue;
		}
		if(!fState.formation){
			warn("cmpFormation does not exist");
			continue;
		}

		let ents = fState.formation.members;
		for (let ent of ents)
		{
			if(selected.indexOf(ent) == -1 && entsAdd.indexOf(ent) == -1)
				entsAdd.push(ent);
		}
	}
	g_Selection.addList(entsAdd);
}

 

Share this post


Link to post
Share on other sites
18 hours ago, gaius said:

Thanks @(-_-). will definetly look at your code. Not even thought about that cool idea. But i tried it and i didn't discover any other behavior. Maybe only a22 combatible?

I can show you code if you want to prevent merging of formations when multiple of them are selected. 

Share this post


Link to post
Share on other sites

@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);
}

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

there is a turnrate element  but I'm pretty sure it makes no difference, prob. not implemented

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×