Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#3154 closed defect (fixed)

Formations - Attack order fails by targeting the formation and not the individual unit

Reported by: elexis Owned by: Itms
Priority: Must Have Milestone: Alpha 19
Component: UI & Simulation Keywords:
Cc: Patch:

Description

In a game that started as 4v4, people disconnected without resigning, resigned & quit and changed displomacy multiple times. Also the private chat ("/msg <nickname> <text>") was used.

At turn 3120 player 1 and 3 issued non-queued attack commands:

turn 3120 500
cmd 1 {"type":"attack","entities":[164,4127,4128,4132,4133,4134,4135,4136,4403,4573,4633,4642,4672,4715,4727,4740,4806,4807,4808,4809,4810,5147,5148,5149,5150,5151,5152,5153,5154,5155,5156,5366,5367,5368,5369,5370,5371,5372,5373,5374,5375,5589,5590,5591,5592,5593,5594,5595,5596,5597,5598],"target":4793,"queued":false}
cmd 3 {"type":"attack","entities":[3720,4159,4161,4214,4216,4218,4789,4790,4791,4792,4793],"target":5593,"queued":false}
end

This is when the following error message appeares:

WARNING: JavaScript warning: simulation/components/Player.js line 557
reference to undefined property this.diplomacy[id]
WARNING: JavaScript warning: simulation/components/Player.js line 570
reference to undefined property this.diplomacy[id]

Which means that the error occurs in the return part of the following functions in Player.js:

/**
 * Check if given player is our enemy
 */
Player.prototype.IsEnemy = function(id)
{
	return this.diplomacy[id] < 0;
};

/**
 * Check if given player is neutral
 */
Player.prototype.IsNeutral = function(id)
{
	return this.diplomacy[id] == 0;
};

The error is reproducable by replaying the attached commands.txt file.

Additional Information: Player 1 = me was defeated after I deleted all units at turn 4175 (therefore no resign command in the logfile) Player 2 = left without resign shortly after turn 28 (looked like network timeout) Player 3+4 = remaining players alive as the game ended Player 5-8 resigned (turn 538, 956, 1435 and 2571)

Attachments (4)

commands.txt.7z (145.7 KB) - added by elexis 5 years ago.
commands.txt and replay-log
t3154_commands.txt_replaylog_alternative.7z (107.0 KB) - added by elexis 5 years ago.
I experienced this error on some more matches. This one also has it on turn 1084.
t3154_commands.txt_replaylog_alternative2.7z (222.3 KB) - added by elexis 5 years ago.
This one also has the error on turn 1155 and #3239 on turn 5591.
t3154_commands.txt_replaylog_alternative3.7z (216.8 KB) - added by elexis 5 years ago.
Same error, only on turn 4433.

Download all attachments as: .zip

Change History (15)

Changed 5 years ago by elexis

Attachment: commands.txt.7z added

commands.txt and replay-log

comment:1 Changed 5 years ago by elexis

When the error occurs, the id argument is -1. By adding the following code to Player.js...

if (id == -1) {
   var err = new Error();
   error(err.stack);
}

I could dump the following stack trace:

Player.prototype.IsNeutral@simulation/components/Player.js:571:10
IsOwnedByNeutralOfPlayer@simulation/helpers/Player.js:349:1
UnitAI.prototype.CanAttack@simulation/components/UnitAI.js:5571:1
UnitAI.prototype.Attack@simulation/components/UnitAI.js:4931:6
UnitAI.prototype.CallMemberFunction@simulation/components/UnitAI.js:5842:3
UnitAI.prototype.UnitFsmSpec.FORMATIONCONTROLLER["Order.Attack"]@simulation/components/UnitAI.js:844:47
FSM.prototype.ProcessMessage@simulation/helpers/FSM.js:274:29
UnitAI.prototype.PushOrder@simulation/components/UnitAI.js:3527:39
UnitAI.prototype.ReplaceOrder@simulation/components/UnitAI.js:3635:3
UnitAI.prototype.AddOrder@simulation/components/UnitAI.js:4769:3
UnitAI.prototype.Attack@simulation/components/UnitAI.js:4942:46
commands.attack/<@simulation/helpers/Commands.js:149:4
commands.attack@simulation/helpers/Commands.js:148:3
ProcessCommand@simulation/helpers/Commands.js:37:3


Also ignore the other error in the replay log:

Turn 3210 (500)... WARNING: JavaScript warning: simulation/components/Fogging.js line 160
reference to undefined property this.miraged[player]

Since that one is #3149.

comment:2 Changed 5 years ago by elexis

Summary: undefined property this.diplomacy[id][Formations] Attack order causes "undefined property this.diplomacy[id]" error

comment:3 Changed 5 years ago by historic_bruno

Milestone: Alpha 19Backlog

Changed 5 years ago by elexis

I experienced this error on some more matches. This one also has it on turn 1084.

comment:4 Changed 5 years ago by elexis

Priority: Nice to HaveShould Have

Changed 5 years ago by elexis

This one also has the error on turn 1155 and #3239 on turn 5591.

Changed 5 years ago by elexis

Same error, only on turn 4433.

comment:5 Changed 5 years ago by elexis

Milestone: BacklogAlpha 19
Priority: Should HaveMust Have

comment:6 Changed 5 years ago by elexis

This bug happens frequently. Moved to alpha19, hoping that someone wise will find the ticket and fix it.

comment:7 Changed 5 years ago by elexis

Component: Core engineUI & Simulation
Summary: [Formations] Attack order causes "undefined property this.diplomacy[id]" errorFormations - Attack order fails by targeting the formation and not the individual unit

The target that was supposed to be attacked is owned by INVALID_PLAYER. I've added debug output to show the template and owner of all targets to be attacked:

UnitAI.prototype.CanAttack = function(target, forceResponse)
{
         ...
	
	// DEBUG START
	var cmpOwnership_target = Engine.QueryInterface(target, IID_Ownership);
	if (!cmpOwnership_target)
		return false;
	var target_owner = cmpOwnership_target.GetOwner();

	var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
	var template = cmpTemplateManager.GetCurrentTemplateName(target);
	error("TEMPLATE OF " + target + " IS " + template);
	error("OWNER OF " + target + " IS " + target_owner);
	// DEBUG END
	
	// Verify that the target is an attackable resource supply like a domestic animal
	// or that it isn't owned by an ally of this entity's player or is responding to
	// an attack.
	var owner = cmpOwnership.GetOwner();
	if (!this.MustKillGatherTarget(target)
	    && !(IsOwnedByEnemyOfPlayer(owner, target)
	         || IsOwnedByNeutralOfPlayer(owner, target)
	         || (forceResponse && !IsOwnedByPlayer(owner, target))))
		return false;

	return true;
};

which reveals that somehow the attack order targets the formation and not the individual unit.

Attack orders that don't cause issues have the following output:

ERROR: TEMPLATE OF 2896 IS units/maur_infantry_archer_b
ERROR: OWNER OF 2896 IS 2

while that bugged attack order produces that output:

ERROR: TEMPLATE OF 2982 IS formations/line_closed
ERROR: OWNER OF 2982 IS -1

This is a very critical bug, since enemy units won't be attacked.

comment:8 Changed 5 years ago by sanderd17

Ah, that makes it a very trivial bug too. It's probably just a matter of setting the ownership when creating a formatio. So in http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/components/Formation.js#L1005

comment:9 Changed 5 years ago by elexis

This bug can be reproduced in a18 and svn by doing the following steps:

  1. Start a game with 2 players, either singleplayer or networked.
  1. Select some units of the first player. Make them passive, so that they won't auto-attack. Disable formation for them and put them back to line-closed. Move to the middle of the map.
  1. Select the other player with the change-perspective tool. Repeat 2. for that player. Attack the other player.

That error doesn't appear in every case but often. It also works when you don't change the unit stance, but its easier to reproduce with passive units.

Sometimes the error doesn't appear, but the units don't attack while being in range and told to attack.

comment:10 Changed 4 years ago by Itms

Owner: set to Itms
Resolution: fixed
Status: newclosed

In 16847:

Keep ownership when changing formation. Fixes #3154, fix proposed by sanderd17.

comment:11 Changed 4 years ago by Itms

Formations are disabled right now but they are fairly easy to reenable, so I fixed this because it was trivial and mods based on A19 might want to use formations (especially Delenda Est and Ancient Empires).

Note: See TracTickets for help on using tickets.