Ticket #4334: TransformFix2.patch
File TransformFix2.patch, 9.3 KB (added by , 7 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Gate.js
diff --git a/binaries/data/mods/public/simulation/components/Gate.js b/binaries/data/mods/public/simulation/components/Gate.js index faa5c11..bce5fbe 100644
a b Gate.prototype.IsLocked = function() 137 137 /** 138 138 * Lock the gate, with sound. It will close at the next opportunity. 139 139 */ 140 Gate.prototype.LockGate = function( )140 Gate.prototype.LockGate = function(quiet) 141 141 { 142 142 this.locked = true; 143 143 // If the door is closed, enable 'block pathfinding' … … Gate.prototype.LockGate = function() 153 153 this.OperateGate(); 154 154 155 155 // TODO: Possibly move the lock/unlock sounds to UI? Needs testing 156 PlaySound("gate_locked", this.entity); 156 if (!quiet) 157 PlaySound("gate_locked", this.entity); 157 158 }; 158 159 159 160 /** -
binaries/data/mods/public/simulation/components/Promotion.js
diff --git a/binaries/data/mods/public/simulation/components/Promotion.js b/binaries/data/mods/public/simulation/components/Promotion.js index 9ad78c8..4760cd5 100644
a b Promotion.prototype.GetPromotedTemplateName = function() 30 30 31 31 Promotion.prototype.Promote = function(promotedTemplateName) 32 32 { 33 // If the unit is dead, don't promote it 34 var cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health); 33 let cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health); 35 34 if (cmpCurrentUnitHealth.GetHitpoints() == 0) 36 35 return; 37 36 38 // Create promoted unit entity 39 var promotedUnitEntity = Engine.AddEntity(promotedTemplateName); 40 41 // Copy parameters from current entity to promoted one 42 var cmpCurrentUnitPosition = Engine.QueryInterface(this.entity, IID_Position); 43 var cmpPromotedUnitPosition = Engine.QueryInterface(promotedUnitEntity, IID_Position); 44 if (cmpCurrentUnitPosition.IsInWorld()) 45 { 46 var pos = cmpCurrentUnitPosition.GetPosition2D(); 47 cmpPromotedUnitPosition.JumpTo(pos.x, pos.y); 48 } 49 var rot = cmpCurrentUnitPosition.GetRotation(); 50 cmpPromotedUnitPosition.SetYRotation(rot.y); 51 cmpPromotedUnitPosition.SetXZRotation(rot.x, rot.z); 52 var heightOffset = cmpCurrentUnitPosition.GetHeightOffset(); 53 cmpPromotedUnitPosition.SetHeightOffset(heightOffset); 37 if (!CanGarrisonedChangeTemplate(this.entity,promotedTemplateName)) 38 return; 54 39 55 var cmpCurrentUnitOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 56 var cmpPromotedUnitOwnership = Engine.QueryInterface(promotedUnitEntity, IID_Ownership); 57 cmpPromotedUnitOwnership.SetOwner(cmpCurrentUnitOwnership.GetOwner()); 40 this.promotedUnitEntity = ChangeEntityTemplate(this.entity, promotedTemplateName); 58 41 59 // ch ange promoted unit health to the same percent of hitpoints as unit had before promotion60 var cmpPromotedUnitHealth = Engine.QueryInterface(promotedUnitEntity, IID_Health);61 var healthFraction = Math.max(0, Math.min(1, cmpCurrentUnitHealth.GetHitpoints() / cmpCurrentUnitHealth.GetMaxHitpoints()));62 var promotedUnitHitpoints = Math.round(cmpPromotedUnitHealth.GetMaxHitpoints() * healthFraction);63 cmpPromotedUnitHealth.SetHitpoints(promotedUnitHitpoints);42 // cheer 43 let cmpCurrentUnitPosition = Engine.QueryInterface(this.entity, IID_Position); 44 let cmpPromotedUnitAI = Engine.QueryInterface(this.promotedUnitEntity, IID_UnitAI); 45 if (cmpCurrentUnitPosition.IsInWorld() && !cmpPromotedUnitAI.IsGarrisoned()) 46 cmpPromotedUnitAI.Cheer(); 64 47 65 var cmpPromotedUnitPromotion = Engine.QueryInterface(promotedUnitEntity, IID_Promotion); 48 // add promotion XP. 49 let cmpPromotedUnitPromotion = Engine.QueryInterface(this.promotedUnitEntity, IID_Promotion); 66 50 if (cmpPromotedUnitPromotion) 67 51 cmpPromotedUnitPromotion.IncreaseXp(this.currentXp); 68 69 var cmpCurrentUnitResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);70 var cmpPromotedUnitResourceGatherer = Engine.QueryInterface(promotedUnitEntity, IID_ResourceGatherer);71 if (cmpCurrentUnitResourceGatherer && cmpPromotedUnitResourceGatherer)72 {73 var carriedResorces = cmpCurrentUnitResourceGatherer.GetCarryingStatus();74 cmpPromotedUnitResourceGatherer.GiveResources(carriedResorces);75 }76 77 var cmpCurrentUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI);78 var cmpPromotedUnitAI = Engine.QueryInterface(promotedUnitEntity, IID_UnitAI);79 var pos = cmpCurrentUnitAI.GetHeldPosition();80 if (pos)81 cmpPromotedUnitAI.SetHeldPosition(pos.x, pos.z);82 if (cmpCurrentUnitAI.GetStanceName())83 cmpPromotedUnitAI.SwitchToStance(cmpCurrentUnitAI.GetStanceName());84 85 var orders = cmpCurrentUnitAI.GetOrders();86 if (cmpCurrentUnitAI.IsGarrisoned())87 cmpPromotedUnitAI.SetGarrisoned();88 if (cmpCurrentUnitPosition.IsInWorld()) // do not cheer if not visibly garrisoned89 cmpPromotedUnitAI.Cheer();90 cmpPromotedUnitAI.AddOrders(orders);91 92 var workOrders = cmpCurrentUnitAI.GetWorkOrders();93 cmpPromotedUnitAI.SetWorkOrders(workOrders);94 cmpPromotedUnitAI.SetGuardOf(cmpCurrentUnitAI.IsGuardOf());95 96 var cmpCurrentUnitGuard = Engine.QueryInterface(this.entity, IID_Guard);97 var cmpPromotedUnitGuard = Engine.QueryInterface(promotedUnitEntity, IID_Guard);98 if (cmpCurrentUnitGuard && cmpPromotedUnitGuard)99 cmpPromotedUnitGuard.SetEntities(cmpCurrentUnitGuard.GetEntities());100 101 Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: promotedUnitEntity });102 103 // Destroy current entity104 Engine.DestroyEntity(this.entity);105 // save the entity id106 this.promotedUnitEntity = promotedUnitEntity;107 52 }; 108 53 109 54 Promotion.prototype.IncreaseXp = function(amount) -
binaries/data/mods/public/simulation/components/UnitAI.js
diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index e23138f..b370013 100644
a b UnitAI.prototype.Flee = function(target, queued) 5423 5423 */ 5424 5424 UnitAI.prototype.Cheer = function() 5425 5425 { 5426 this.AddOrder("Cheering", { "force": true }, false);5426 this.AddOrder("Cheering", { "force": true }, true); 5427 5427 }; 5428 5428 5429 5429 UnitAI.prototype.Pack = function(queued) -
binaries/data/mods/public/simulation/helpers/Transform.js
diff --git a/binaries/data/mods/public/simulation/helpers/Transform.js b/binaries/data/mods/public/simulation/helpers/Transform.js index dbdeddd..9f6418d 100644
a b 3 3 // returns the ID of the new entity or INVALID_ENTITY. 4 4 function ChangeEntityTemplate(oldEnt, newTemplate) 5 5 { 6 // Done un/packing, copy our parameters to the final entity7 6 var newEnt = Engine.AddEntity(newTemplate); 8 7 if (newEnt == INVALID_ENTITY) 9 8 { … … function ChangeEntityTemplate(oldEnt, newTemplate) 31 30 if (cmpOwnership && cmpNewOwnership) 32 31 cmpNewOwnership.SetOwner(cmpOwnership.GetOwner()); 33 32 34 // Copy control groups35 33 CopyControlGroups(oldEnt, newEnt); 36 34 37 35 // Rescale capture points … … function ChangeEntityTemplate(oldEnt, newTemplate) 53 51 cmpNewHealth.SetHitpoints(Math.round(cmpNewHealth.GetMaxHitpoints() * healthLevel)); 54 52 } 55 53 54 var cmpUnitResourceGatherer = Engine.QueryInterface(oldEnt, IID_ResourceGatherer); 55 var cmpNewUnitResourceGatherer = Engine.QueryInterface(newEnt, IID_ResourceGatherer); 56 if (cmpUnitResourceGatherer && cmpNewUnitResourceGatherer) 57 cmpNewUnitResourceGatherer.GiveResources(cmpUnitResourceGatherer.GetCarryingStatus()); 58 56 59 var cmpUnitAI = Engine.QueryInterface(oldEnt, IID_UnitAI); 57 60 var cmpNewUnitAI = Engine.QueryInterface(newEnt, IID_UnitAI); 58 61 if (cmpUnitAI && cmpNewUnitAI) … … function ChangeEntityTemplate(oldEnt, newTemplate) 63 66 if (cmpUnitAI.GetStanceName()) 64 67 cmpNewUnitAI.SwitchToStance(cmpUnitAI.GetStanceName()); 65 68 cmpNewUnitAI.AddOrders(cmpUnitAI.GetOrders()); 69 cmpNewUnitAI.SetWorkOrders(cmpUnitAI.GetWorkOrders()); 66 70 cmpNewUnitAI.SetGuardOf(cmpUnitAI.IsGuardOf()); 71 if (cmpUnitAI.IsGarrisoned()) 72 cmpNewUnitAI.SetGarrisoned(); 67 73 } 68 74 69 // Maintain the list of guards70 75 var cmpGuard = Engine.QueryInterface(oldEnt, IID_Guard); 71 76 var cmpNewGuard = Engine.QueryInterface(newEnt, IID_Guard); 72 77 if (cmpGuard && cmpNewGuard) 73 78 cmpNewGuard.SetEntities(cmpGuard.GetEntities()); 74 79 80 var cmpGate = Engine.QueryInterface(oldEnt, IID_Gate); 81 var cmpNewGate = Engine.QueryInterface(newEnt, IID_Gate); 82 if (cmpGate && cmpNewGate) 83 { 84 cmpNewGate.opened = cmpGate.opened; 85 if (cmpGate.IsLocked) 86 cmpGate.LockGate(true); 87 } 88 89 var cmpTrader = Engine.QueryInterface(oldEnt, IID_Trader); 90 var cmpNewTrader = Engine.QueryInterface(newEnt, IID_Trader); 91 if (cmpTrader && cmpNewTrader) 92 { 93 cmpNewTrader.markets = cmpTrader.markets; 94 cmpNewTrader.index = cmpTrader.index; 95 cmpNewTrader.goods = {}; 96 for (let p of cmpTrader.goods) 97 cmpNewTrader.goods[p] = cmpTrader.goods[p]; 98 } 99 75 100 TransferGarrisonedUnits(oldEnt, newEnt); 76 101 77 102 Engine.BroadcastMessage(MT_EntityRenamed, { "entity": oldEnt, "newentity": newEnt }); … … function ChangeEntityTemplate(oldEnt, newTemplate) 83 108 84 109 function CanGarrisonedChangeTemplate(ent, template) 85 110 { 86 var cmpPosition = Engine.QueryInterface(ent, IID_Position);87 111 var unitAI = Engine.QueryInterface(ent, IID_UnitAI); 88 if ( cmpPosition && !cmpPosition.IsInWorld() &&unitAI && unitAI.IsGarrisoned())112 if (unitAI && unitAI.IsGarrisoned()) 89 113 { 90 114 // We're a garrisoned unit, assume impossibility as I've been unable to find a way to get the holder ID. 91 115 // TODO: change this if that ever becomes possibles