Jump to content
Sign in to follow this  
Angen

Formation rework

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
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
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

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.

Sign in to follow this  

×
×
  • Create New...