Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: binaries/data/mods/public/simulation/components/Health.js
- ===================================================================
- --- binaries/data/mods/public/simulation/components/Health.js (revision 12465)
- +++ binaries/data/mods/public/simulation/components/Health.js (working copy)
- @@ -124,18 +124,10 @@
- }
- else if (this.template.DeathType == "remain")
- {
- - // Don't destroy the entity
- -
- - // TODO: This is a workaround so players don't retain LOS when
- - // their livestock animals die. See ticket #1600.
- - var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
- - if (cmpOwnership)
- - cmpOwnership.SetOwner(0);
- -
- - // Make it fall over
- - var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
- - if (cmpVisual)
- - cmpVisual.SelectAnimation("death", true, 1.0, "");
- + var resource = this.CreateCorpse(true);
- + if (resource != INVALID_ENTITY)
- + Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: resource });
- + Engine.DestroyEntity(this.entity);
- }
- var old = this.hitpoints;
- @@ -178,22 +170,26 @@
- //// Private functions ////
- -Health.prototype.CreateCorpse = function()
- +Health.prototype.CreateCorpse = function(leaveResources)
- {
- // If the unit died while not in the world, don't create any corpse for it
- // since there's nowhere for the corpse to be placed
- var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
- if (!cmpPosition.IsInWorld())
- - return;
- + return INVALID_ENTITY;
- // Create a static local version of the current entity
- var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
- var templateName = cmpTempMan.GetCurrentTemplateName(this.entity);
- - var corpse = Engine.AddLocalEntity("corpse|" + templateName);
- + var newentity;
- + if (leaveResources)
- + newentity = Engine.AddEntity("resource|" + templateName);
- + else
- + newentity = Engine.AddLocalEntity("corpse|" + templateName);
- // Copy various parameters so it looks just like us
- - var cmpCorpsePosition = Engine.QueryInterface(corpse, IID_Position);
- + var cmpCorpsePosition = Engine.QueryInterface(newentity, IID_Position);
- var pos = cmpPosition.GetPosition();
- cmpCorpsePosition.JumpTo(pos.x, pos.z);
- var rot = cmpPosition.GetRotation();
- @@ -201,12 +197,14 @@
- cmpCorpsePosition.SetXZRotation(rot.x, rot.z);
- var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
- - var cmpCorpseOwnership = Engine.QueryInterface(corpse, IID_Ownership);
- + var cmpCorpseOwnership = Engine.QueryInterface(newentity, IID_Ownership);
- cmpCorpseOwnership.SetOwner(cmpOwnership.GetOwner());
- // Make it fall over
- - var cmpCorpseVisual = Engine.QueryInterface(corpse, IID_Visual);
- + var cmpCorpseVisual = Engine.QueryInterface(newentity, IID_Visual);
- cmpCorpseVisual.SelectAnimation("death", true, 1.0, "");
- +
- + return newentity;
- };
- Health.prototype.Repair = function(builderEnt, work)
- Index: binaries/data/mods/public/simulation/components/UnitAI.js
- ===================================================================
- --- binaries/data/mods/public/simulation/components/UnitAI.js (revision 12462)
- +++ binaries/data/mods/public/simulation/components/UnitAI.js (working copy)
- @@ -815,6 +815,12 @@
- "EntityRenamed": function(msg) {
- if (this.order.data.target == msg.entity)
- this.order.data.target = msg.newentity;
- +
- + // If we're hunting, that means we have a queued gather order
- + // whose target also needs to be updated.
- + if (this.order.data.hunting && this.orderQueue[1] &&
- + this.orderQueue[1].type == "Gather")
- + this.orderQueue[1].data.target = msg.newentity;
- },
- "Attacked": function(msg) {
- @@ -2319,6 +2325,11 @@
- var type = cmpResourceSupply.GetType();
- var amount = cmpResourceSupply.GetCurrentAmount();
- var template = cmpTemplateManager.GetCurrentTemplateName(ent);
- +
- + // Remove "resource|" prefix from template names, if present.
- + if (template.substr(0,9) == "resource|")
- + template = template.slice(9);
- +
- if (amount > 0 && filter(ent, type, template))
- return ent;
- }
- @@ -2968,6 +2979,10 @@
- var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
- var template = cmpTemplateManager.GetCurrentTemplateName(target);
- + // Remove "resource|" prefix from template name, if present.
- + if (template.substr(0,9) == "resource|")
- + template = template.slice(9);
- +
- // Remember the position of our target, if any, in case it disappears
- // later and we want to head to its last known position
- // (TODO: if the target moves a lot (e.g. it's an animal), maybe we
- Index: source/simulation2/components/CCmpTemplateManager.cpp
- ===================================================================
- --- source/simulation2/components/CCmpTemplateManager.cpp (revision 12462)
- +++ source/simulation2/components/CCmpTemplateManager.cpp (working copy)
- @@ -174,6 +174,10 @@
- // Copy the components of an entity necessary for a construction foundation
- // (position, actor, armour, health, etc) into a new entity template
- void CopyFoundationSubset(CParamNode& out, const CParamNode& in);
- +
- + // Copy the components of an entity necessary for a gatherable resource
- + // into a new entity template
- + void CopyResourceSubset(CParamNode& out, const CParamNode& in);
- };
- REGISTER_COMPONENT_TYPE(TemplateManager)
- @@ -324,6 +328,21 @@
- return true;
- }
- + // Handle special case "resource|foo"
- + if (templateName.find("resource|") == 0)
- + {
- + // Load the base entity template, if it wasn't already loaded
- + std::string baseName = templateName.substr(9);
- + if (!LoadTemplateFile(baseName, depth+1))
- + {
- + LOGERROR(L"Failed to load entity template '%hs'", baseName.c_str());
- + return false;
- + }
- + // Copy a subset to the requested template
- + CopyResourceSubset(m_TemplateFileData[templateName], m_TemplateFileData[baseName]);
- + return true;
- + }
- +
- // Normal case: templateName is an XML file:
- VfsPath path = VfsPath(TEMPLATE_ROOT) / wstring_from_utf8(templateName + ".xml");
- @@ -553,3 +572,26 @@
- if (out.GetChild("Entity").GetChild("Vision").IsOk())
- CParamNode::LoadXMLString(out, "<Entity><Vision><Range>0</Range></Vision></Entity>");
- }
- +
- +void CCmpTemplateManager::CopyResourceSubset(CParamNode& out, const CParamNode& in)
- +{
- + // Currently used for animals which die and leave a gatherable corpse.
- + // Mostly serves to filter out components like Vision, UnitAI, etc.
- + std::set<std::string> permittedComponentTypes;
- + permittedComponentTypes.insert("Ownership");
- + permittedComponentTypes.insert("Position");
- + permittedComponentTypes.insert("VisualActor");
- + permittedComponentTypes.insert("Identity");
- + permittedComponentTypes.insert("Obstruction");
- + permittedComponentTypes.insert("Minimap");
- + permittedComponentTypes.insert("ResourceSupply");
- + permittedComponentTypes.insert("Selectable");
- + permittedComponentTypes.insert("Footprint");
- + permittedComponentTypes.insert("StatusBars");
- + permittedComponentTypes.insert("OverlayRenderer");
- + permittedComponentTypes.insert("Sound");
- + permittedComponentTypes.insert("AIProxy");
- +
- + CParamNode::LoadXMLString(out, "<Entity/>");
- + out.CopyFilteredChildrenOfChild(in, "Entity", permittedComponentTypes);
- +}
Add Comment
Please, Sign In to add comment