Jump to content

Running, charging, stamina and stances (with a bit of formations)


Karamel
 Share

Recommended Posts

15 hours ago, asterix said:

Look at the section formations https://trac.wildfiregames.com/wiki/Alpha23

Is says that the speed bonus is removed, is that what you are referring to? Because I tried to let units actually run in the formations (visualise an awesome cavalry charge) but, strangely, they only slow down when I try to use the run speed.

4 hours ago, (-_-) said:

What kind of information do you need from the hyrule code? (I talked to exo and while he did adapt it, the core concept remains the same)

Well, I don't *need* anything, but I'm just curious :) I wanted to see what code they used for the different steps, but if it is basically the same it is okay.

Link to comment
Share on other sites

Formation.prototype.Run = function()
{
	let maxSpeed = 0;

	for (let ent of this.members)
	{
		let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
		if (cmpUnitMotion) {
			if (maxSpeed == 0)
				maxSpeed = cmpUnitMotion.GetRunMultiplier();
			else
				maxSpeed = Math.min(maxSpeed, cmpUnitMotion.GetRunMultiplier());
		}
	}
	maxSpeed *= this.GetSpeedMultiplier(); <- apply formation speed multiplier

	this.speed = maxSpeed * this.minSpeed; <- this.minSpeed is minimal walking speed of formation
	this.running = true;

	let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
	cmpUnitMotion.SetSpeedMultiplier(this.speed);
}

I use something like this

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

45 minutes ago, Angen said:

I use something like this

I changed the "ComputeMotionParameters" function to include a check whether "run" is called, to remove duplication ;) But that is not on SVN, so I probably need to use your code in the future :)

Link to comment
Share on other sites

  • 2 months later...
On 5/20/2019 at 1:10 PM, Freagarach said:

I changed the "ComputeMotionParameters" function to include a check whether "run" is called, to remove duplication ;) But that is not on SVN, so I probably need to use your code in the future :)

Now is possible ? Or we need more pathfinder changes?

Link to comment
Share on other sites

5 hours ago, Lion.Kanzen said:

Now is possible ? Or we need more pathfinder changes?

Well, my solution was neither regarding the pathfinder nor UnitMotion, it was regarding a function in Formation.js.

Spoiler

For reference this was my (currently hopelessly outdated) solution:


/**
 * Set formation controller's speed based on its current members.
 * @param {boolean} - whether the run-speed is wanted
 */
Formation.prototype.ComputeMotionParameters = function(run = false)
{
	let minSpeed = Infinity;

	for (let ent of this.members)
	{
		let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
		if (cmpUnitMotion)
			minSpeed = run ? Math.min(minSpeed, cmpUnitMotion.GetRunSpeed()) : Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed());
	}
	minSpeed *= this.GetSpeedMultiplier();

	let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
	if (cmpUnitMotion)
		cmpUnitMotion.SetSpeed(minSpeed);
};

 

 

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...
On 7/23/2019 at 12:36 AM, Freagarach said:

Well, my solution was neither regarding the pathfinder nor UnitMotion, it was regarding a function in Formation.js.

  Reveal hidden contents

For reference this was my (currently hopelessly outdated) solution:



/**
 * Set formation controller's speed based on its current members.
 * @param {boolean} - whether the run-speed is wanted
 */
Formation.prototype.ComputeMotionParameters = function(run = false)
{
	let minSpeed = Infinity;

	for (let ent of this.members)
	{
		let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
		if (cmpUnitMotion)
			minSpeed = run ? Math.min(minSpeed, cmpUnitMotion.GetRunSpeed()) : Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed());
	}
	minSpeed *= this.GetSpeedMultiplier();

	let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
	if (cmpUnitMotion)
		cmpUnitMotion.SetSpeed(minSpeed);
};

 

 

But how will work for the user, a hotkeys or mouse command?

Link to comment
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
 Share

×
×
  • Create New...