Jump to content

(solved) changed coordinates problem


Recommended Posts

I was trying to implement the feature of seperate entities for horse riders but I got a problem and didn't knew what the thing that keeps changing coordinates.

the logs gave me:

the horse 7079 got the order from 7085, x = 608.2567138671875 z = 852.1669311523438

7079 ordered to Walk to x = 841.0175601990993, z = 100

the function is:

UnitAI.prototype.Walk = function(x, z, queued, pushFront)
{
	let mov = 1;
	log(this.entity + " ordered to  Walk to x = " + x + ", z = " + z);
	let cmpTurretable = Engine.QueryInterface(this.entity, IID_Turretable);
	if (cmpTurretable)
	{
		mov = 0;
		log(this.entity + " Turretable");
		let tur = cmpTurretable.HolderID();
		log(tur + " is Turret");
		if (tur)
		{
			let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
			if (cmpTimer)
			{
				log("the horse " + tur + " got the order from " + this.entity + ", x = " + x + " z = " + z);
				cmpTimer.SetTimeout(tur, IID_UnitAI, "Walk", 100, x, z, queued, pushFront);
			}
		}
		else
			mov = 1;
	}
	if (mov)
	{
		if (!pushFront && this.expectedRoute && queued)
			this.expectedRoute.push({ "x": x, "z": z });
		else
			this.AddOrder("Walk", { "x": x, "z": z, "force": true }, queued, pushFront);
	}
};

any ideas?

Edited by man_s_our
Link to comment
Share on other sites

  • man_s_our changed the title to (solved) changed coordinates problem

I fond the problem was in the need to turn the args into dictionary first.

this code solves the problem:

UnitAI.prototype.Walk = function(x, z, queued, pushFront)
{
	let mov = 1;
	let cmpTurretable = Engine.QueryInterface(this.entity, IID_Turretable);
	if (cmpTurretable)
	{
		mov = 0;
		let tur = cmpTurretable.HolderID();
		if (tur)
		{
			let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
			if (cmpTimer)
			{
				var data = { "x": x, "z": z, "queued": queued, "pushFront": pushFront };
				cmpTimer.SetTimeout(tur, IID_UnitAI, "Walkt", 100, data);
			}
		}
		else
			mov = 1;
	}
	if (mov)
	{
		if (!pushFront && this.expectedRoute && queued)
			this.expectedRoute.push({ "x": x, "z": z });
		else
			this.AddOrder("Walk", { "x": x, "z": z, "force": true }, queued, pushFront);
	}
};
UnitAI.prototype.Walkt = function(data, lateness)
{
	let x = data.x;
	let z = data.z;
	let queued = data.queued;
	let pushFront = data.pushFront;
	if (!pushFront && this.expectedRoute && queued)
		this.expectedRoute.push({ "x": x, "z": z });
	else
		this.AddOrder("Walk", { "x": x, "z": z, "force": true }, queued, pushFront);
};

 

Link to comment
Share on other sites

11 hours ago, Freagarach said:

Glad you got it working. :) I've bitten my teeth on this turret-order problem before, so I'm very interested in any results, so please do keep us (me) updated. :)

till now the problems I got is:

when order the unit to gather while it's riding a horse (propably will be solved after editing more UnitAI functions)

if I order a melee unit to ride a horse and send it to fight it doesn't attack the enemies.

I don't know which function that will return the current movement speed (instead of max speed) to use it for archer's spread. (solved)

Edited by man_s_our
Link to comment
Share on other sites

  • 2 weeks later...

@Freagarach

changelog:

riders' orientation is now the same with the horse most the time when the horse is walking (turretable.js)

the horse will automatically go to the targeted unit so that the rider attack it instead of having to make 2 seperate orders.

the cavalry units are automatically using hit-run tactics (can be disabled by replacing "range.max / 2" in the line 5087 by range.min)

TODO:

fix the bugs related to gathering (when gather order issued you can't stop it)

UnitAI.js Turretable.js

Edited by man_s_our
Link to comment
Share on other sites

Very cool! It seems you are coming close to something we may be able include in the main game (feature wise), could you upload a patch on our Phabricator, please? (https://trac.wildfiregames.com/wiki/SubmittingPatches) It will allow us to give direct comments on your code and speed up the inclusion. :) (I see quite some hardcoding in some functions, but it might be unavoidable.)

Link to comment
Share on other sites

10 hours ago, Freagarach said:

Very cool! It seems you are coming close to something we may be able include in the main game (feature wise), could you upload a patch on our Phabricator, please? (https://trac.wildfiregames.com/wiki/SubmittingPatches) It will allow us to give direct comments on your code and speed up the inclusion. :) (I see quite some hardcoding in some functions, but it might be unavoidable.)

I already planned to do it when I complete the TODO list. the same with the hunger script when finishing the last bug.

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