Guest User

Untitled

a guest
Sep 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.23 KB | None | 0 0
  1. Index: binaries/data/mods/public/simulation/components/Health.js
  2. ===================================================================
  3. --- binaries/data/mods/public/simulation/components/Health.js   (revision 12465)
  4. +++ binaries/data/mods/public/simulation/components/Health.js   (working copy)
  5. @@ -124,18 +124,10 @@
  6.             }
  7.             else if (this.template.DeathType == "remain")
  8.             {
  9. -               // Don't destroy the entity
  10. -
  11. -               // TODO: This is a workaround so players don't retain LOS when
  12. -               // their livestock animals die. See ticket #1600.
  13. -               var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
  14. -               if (cmpOwnership)
  15. -                   cmpOwnership.SetOwner(0);
  16. -
  17. -               // Make it fall over
  18. -               var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
  19. -               if (cmpVisual)
  20. -                   cmpVisual.SelectAnimation("death", true, 1.0, "");
  21. +               var resource = this.CreateCorpse(true);
  22. +               if (resource != INVALID_ENTITY)
  23. +                   Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: resource });
  24. +               Engine.DestroyEntity(this.entity);
  25.             }
  26.  
  27.             var old = this.hitpoints;
  28. @@ -178,22 +170,26 @@
  29.  
  30.  //// Private functions ////
  31.  
  32. -Health.prototype.CreateCorpse = function()
  33. +Health.prototype.CreateCorpse = function(leaveResources)
  34.  {
  35.     // If the unit died while not in the world, don't create any corpse for it
  36.     // since there's nowhere for the corpse to be placed
  37.     var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
  38.     if (!cmpPosition.IsInWorld())
  39. -       return;
  40. +       return INVALID_ENTITY;
  41.  
  42.     // Create a static local version of the current entity
  43.     var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
  44.     var templateName = cmpTempMan.GetCurrentTemplateName(this.entity);
  45. -   var corpse = Engine.AddLocalEntity("corpse|" + templateName);
  46. +   var newentity;
  47. +   if (leaveResources)
  48. +       newentity = Engine.AddEntity("resource|" + templateName);
  49. +   else
  50. +       newentity = Engine.AddLocalEntity("corpse|" + templateName);
  51.  
  52.     // Copy various parameters so it looks just like us
  53.  
  54. -   var cmpCorpsePosition = Engine.QueryInterface(corpse, IID_Position);
  55. +   var cmpCorpsePosition = Engine.QueryInterface(newentity, IID_Position);
  56.     var pos = cmpPosition.GetPosition();
  57.     cmpCorpsePosition.JumpTo(pos.x, pos.z);
  58.     var rot = cmpPosition.GetRotation();
  59. @@ -201,12 +197,14 @@
  60.     cmpCorpsePosition.SetXZRotation(rot.x, rot.z);
  61.  
  62.     var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
  63. -   var cmpCorpseOwnership = Engine.QueryInterface(corpse, IID_Ownership);
  64. +   var cmpCorpseOwnership = Engine.QueryInterface(newentity, IID_Ownership);
  65.     cmpCorpseOwnership.SetOwner(cmpOwnership.GetOwner());
  66.  
  67.     // Make it fall over
  68. -   var cmpCorpseVisual = Engine.QueryInterface(corpse, IID_Visual);
  69. +   var cmpCorpseVisual = Engine.QueryInterface(newentity, IID_Visual);
  70.     cmpCorpseVisual.SelectAnimation("death", true, 1.0, "");
  71. +
  72. +   return newentity;
  73.  };
  74.  
  75.  Health.prototype.Repair = function(builderEnt, work)
  76. Index: binaries/data/mods/public/simulation/components/UnitAI.js
  77. ===================================================================
  78. --- binaries/data/mods/public/simulation/components/UnitAI.js   (revision 12462)
  79. +++ binaries/data/mods/public/simulation/components/UnitAI.js   (working copy)
  80. @@ -815,6 +815,12 @@
  81.             "EntityRenamed": function(msg) {
  82.                 if (this.order.data.target == msg.entity)
  83.                     this.order.data.target = msg.newentity;
  84. +
  85. +               // If we're hunting, that means we have a queued gather order
  86. +               // whose target also needs to be updated.
  87. +               if (this.order.data.hunting && this.orderQueue[1] &&
  88. +                       this.orderQueue[1].type == "Gather")
  89. +                   this.orderQueue[1].data.target = msg.newentity;
  90.             },
  91.  
  92.             "Attacked": function(msg) {
  93. @@ -2319,6 +2325,11 @@
  94.         var type = cmpResourceSupply.GetType();
  95.         var amount = cmpResourceSupply.GetCurrentAmount();
  96.         var template = cmpTemplateManager.GetCurrentTemplateName(ent);
  97. +
  98. +       // Remove "resource|" prefix from template names, if present.
  99. +       if (template.substr(0,9) == "resource|")
  100. +           template = template.slice(9);
  101. +
  102.         if (amount > 0 && filter(ent, type, template))
  103.             return ent;
  104.     }
  105. @@ -2968,6 +2979,10 @@
  106.     var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
  107.     var template = cmpTemplateManager.GetCurrentTemplateName(target);
  108.  
  109. +   // Remove "resource|" prefix from template name, if present.
  110. +   if (template.substr(0,9) == "resource|")
  111. +       template = template.slice(9);
  112. +
  113.     // Remember the position of our target, if any, in case it disappears
  114.     // later and we want to head to its last known position
  115.     // (TODO: if the target moves a lot (e.g. it's an animal), maybe we
  116. Index: source/simulation2/components/CCmpTemplateManager.cpp
  117. ===================================================================
  118. --- source/simulation2/components/CCmpTemplateManager.cpp   (revision 12462)
  119. +++ source/simulation2/components/CCmpTemplateManager.cpp   (working copy)
  120. @@ -174,6 +174,10 @@
  121.     // Copy the components of an entity necessary for a construction foundation
  122.     // (position, actor, armour, health, etc) into a new entity template
  123.     void CopyFoundationSubset(CParamNode& out, const CParamNode& in);
  124. +
  125. +   // Copy the components of an entity necessary for a gatherable resource
  126. +   // into a new entity template
  127. +   void CopyResourceSubset(CParamNode& out, const CParamNode& in);
  128.  };
  129.  
  130.  REGISTER_COMPONENT_TYPE(TemplateManager)
  131. @@ -324,6 +328,21 @@
  132.         return true;
  133.     }
  134.  
  135. +   // Handle special case "resource|foo"
  136. +   if (templateName.find("resource|") == 0)
  137. +   {
  138. +       // Load the base entity template, if it wasn't already loaded
  139. +       std::string baseName = templateName.substr(9);
  140. +       if (!LoadTemplateFile(baseName, depth+1))
  141. +       {
  142. +           LOGERROR(L"Failed to load entity template '%hs'", baseName.c_str());
  143. +           return false;
  144. +       }
  145. +       // Copy a subset to the requested template
  146. +       CopyResourceSubset(m_TemplateFileData[templateName], m_TemplateFileData[baseName]);
  147. +       return true;
  148. +   }
  149. +
  150.     // Normal case: templateName is an XML file:
  151.  
  152.     VfsPath path = VfsPath(TEMPLATE_ROOT) / wstring_from_utf8(templateName + ".xml");
  153. @@ -553,3 +572,26 @@
  154.     if (out.GetChild("Entity").GetChild("Vision").IsOk())
  155.         CParamNode::LoadXMLString(out, "<Entity><Vision><Range>0</Range></Vision></Entity>");
  156.  }
  157. +
  158. +void CCmpTemplateManager::CopyResourceSubset(CParamNode& out, const CParamNode& in)
  159. +{
  160. +   // Currently used for animals which die and leave a gatherable corpse.
  161. +   // Mostly serves to filter out components like Vision, UnitAI, etc.
  162. +   std::set<std::string> permittedComponentTypes;
  163. +   permittedComponentTypes.insert("Ownership");
  164. +   permittedComponentTypes.insert("Position");
  165. +   permittedComponentTypes.insert("VisualActor");
  166. +   permittedComponentTypes.insert("Identity");
  167. +   permittedComponentTypes.insert("Obstruction");
  168. +   permittedComponentTypes.insert("Minimap");
  169. +   permittedComponentTypes.insert("ResourceSupply");
  170. +   permittedComponentTypes.insert("Selectable");
  171. +   permittedComponentTypes.insert("Footprint");
  172. +   permittedComponentTypes.insert("StatusBars");
  173. +   permittedComponentTypes.insert("OverlayRenderer");
  174. +   permittedComponentTypes.insert("Sound");
  175. +   permittedComponentTypes.insert("AIProxy");
  176. +
  177. +   CParamNode::LoadXMLString(out, "<Entity/>");
  178. +   out.CopyFilteredChildrenOfChild(in, "Entity", permittedComponentTypes);
  179. +}
Add Comment
Please, Sign In to add comment