1
0
forked from 0ad/0ad

Move out of world promoted, packed and upgraded entity as they are not destroyed immediately. So they don't interact with the 'physical' world. Refs #4595.

Differential Revision: https://code.wildfiregames.com/D590
Reviewed By: wraitii
This was SVN commit r20393.
This commit is contained in:
fatherbushido 2017-11-01 14:55:18 +00:00
parent 502ebdbe42
commit de1bb8a766
4 changed files with 12 additions and 7 deletions

View File

@ -76,9 +76,9 @@ Promotion.prototype.Promote = function(promotedTemplateName)
var cmpCurrentUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI);
var cmpPromotedUnitAI = Engine.QueryInterface(promotedUnitEntity, IID_UnitAI);
var pos = cmpCurrentUnitAI.GetHeldPosition();
if (pos)
cmpPromotedUnitAI.SetHeldPosition(pos.x, pos.z);
var heldPos = cmpCurrentUnitAI.GetHeldPosition();
if (heldPos)
cmpPromotedUnitAI.SetHeldPosition(heldPos.x, heldPos.z);
if (cmpCurrentUnitAI.GetStanceName())
cmpPromotedUnitAI.SwitchToStance(cmpCurrentUnitAI.GetStanceName());
@ -123,6 +123,8 @@ Promotion.prototype.Promote = function(promotedTemplateName)
Engine.PostMessage(this.entity, MT_EntityRenamed, { "entity": this.entity, "newentity": promotedUnitEntity });
// Destroy current entity
if (cmpCurrentUnitPosition && cmpCurrentUnitPosition.IsInWorld())
cmpCurrentUnitPosition.MoveOutOfWorld();
Engine.DestroyEntity(this.entity);
// save the entity id
this.promotedUnitEntity = promotedUnitEntity;

View File

@ -180,15 +180,15 @@ AddMock(SYSTEM_ENTITY, IID_TemplateManager, {
}
});
cmpEntityLimits.ChangeCount( "Champion", 1)
cmpEntityLimits.ChangeCount("Champion", 1)
TS_ASSERT(cmpEntityLimits.AllowedToReplace(100, "templateA"))
TS_ASSERT(!cmpEntityLimits.AllowedToReplace(101, "templateA"))
cmpEntityLimits.ChangeCount( "Champion", -1)
cmpEntityLimits.ChangeCount("Champion", -1)
cmpEntityLimits.ChangeCount( "Tower", 5)
cmpEntityLimits.ChangeCount("Tower", 5)
TS_ASSERT(!cmpEntityLimits.AllowedToReplace(102, "templateD"))
TS_ASSERT(cmpEntityLimits.AllowedToReplace(103, "templateD"))
cmpEntityLimits.ChangeCount( "Tower", -5)
cmpEntityLimits.ChangeCount("Tower", -5)
TS_ASSERT_UNEVAL_EQUALS(cmpEntityLimits.GetCounts(), { "Tower": 0, "Wonder": 0, "Hero": 0, "Champion": 0 });

View File

@ -24,6 +24,7 @@ AddMock(60, IID_Position, {
"GetRotation": () => new Vector3D(3, 4, 5),
"GetHeightOffset": () => {},
"IsInWorld": () => true,
"MoveOutOfWorld": () => {}
});
AddMock(60, IID_Ownership, {

View File

@ -97,6 +97,8 @@ function ChangeEntityTemplate(oldEnt, newTemplate)
Engine.PostMessage(oldEnt, MT_EntityRenamed, { "entity": oldEnt, "newentity": newEnt });
if (cmpPosition && cmpPosition.IsInWorld())
cmpPosition.MoveOutOfWorld();
Engine.DestroyEntity(oldEnt);
return newEnt;