Ticket #4334: TransformFix.patch
File TransformFix.patch, 7.8 KB (added by , 7 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Gate.js
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' … … 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
31 31 Promotion.prototype.Promote = function(promotedTemplateName) 32 32 { 33 33 // If the unit is dead, don't promote it 34 varcmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health);34 let cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health); 35 35 if (cmpCurrentUnitHealth.GetHitpoints() == 0) 36 36 return; 37 37 38 38 // Create promoted unit entity 39 var promotedUnitEntity = Engine.AddEntity(promotedTemplateName);39 this.promotedUnitEntity = ChangeEntityTemplate(this.entity, promotedTemplateName); 40 40 41 // Copy parameters from current entity to promoted one42 varcmpCurrentUnitPosition = Engine.QueryInterface(this.entity, IID_Position);43 var cmpPromotedUnitPosition = Engine.QueryInterface(promotedUnitEntity, IID_Position);41 // cheer 42 let cmpCurrentUnitPosition = Engine.QueryInterface(this.entity, IID_Position); 43 let cmpPromotedUnitAI = Engine.QueryInterface(this.promotedUnitEntity, IID_UnitAI); 44 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); 45 cmpPromotedUnitAI.Cheer(); 54 46 55 var cmpCurrentUnitOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 56 var cmpPromotedUnitOwnership = Engine.QueryInterface(promotedUnitEntity, IID_Ownership); 57 cmpPromotedUnitOwnership.SetOwner(cmpCurrentUnitOwnership.GetOwner()); 58 59 // change promoted unit health to the same percent of hitpoints as unit had before promotion 60 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); 64 65 var cmpPromotedUnitPromotion = Engine.QueryInterface(promotedUnitEntity, IID_Promotion); 47 // add promotion XP. 48 let cmpPromotedUnitPromotion = Engine.QueryInterface(this.promotedUnitEntity, IID_Promotion); 66 49 if (cmpPromotedUnitPromotion) 67 50 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 51 }; 108 52 109 53 Promotion.prototype.IncreaseXp = function(amount) -
binaries/data/mods/public/simulation/helpers/Transform.js
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 { … … 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 … … 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) … … 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 });