//*************************************************************** void CAutoGroup::group(CObject *newEntityDesc, const NLMISC::CVectorD &createPosition) { //H_AUTO(R2_CAutoGroup_group) CInstance *destGroup = getGroupingCandidate(); if (!destGroup || !_AutoGroupEnabled) return; _AutoGroupEnabled = false; // force user to call 'update' again clear(); // remove any activity, dialog, or event in the copy CObject *behav = newEntityDesc->findAttr("Behavior"); if (behav) { behav->setObject("Actions", new CObjectTable()); behav->setObject("Activities", new CObjectTable()); behav->setObject("ChatSequences", new CObjectTable()); newEntityDesc->setObject("ActivitiesId", new CObjectTable()); } nlassert(newEntityDesc); nlassert(destGroup); std::string targetGroupId; if (destGroup->isKindOf("NpcGrpFeature")) { // make relative to newgroup and insert CVectorD relPos = createPosition; CDisplayerVisual *vd = destGroup->getDisplayerVisual(); if (vd) { relPos = relPos - vd->getWorldPos(); } newEntityDesc->setObject("Position", buildVector(relPos)); targetGroupId = destGroup->getId(); } else { // other is a standalone entity -> create a new group std::auto_ptr<CObject> newGroup(getEditor().getDMC().newComponent("NpcGrpFeature")); if (!newGroup.get()) { nlwarning("Syntax error in r2_features_npc_group.lua."); getEditor().getDMC().getActionHistoric().endAction(); getEditor().getDMC().flushActions(); return; } ucstring readableName; CLuaState &ls = getEditor().getLua(); R2::getEditor().getEnv()["PaletteIdToGroupTranslation"][newEntityDesc->getAttr("Base")->toString()].push(); if (ls.isString(-1)) readableName.fromUtf8(ls.toString(-1)); ucstring ucGroupName = ucstring(readableName + " " + CI18N::get("uiR2EDNameGroup").toUtf8()); newGroup->set("Name", getEditor().genInstanceName(ucGroupName).toUtf8()); getEditor().getDMC().requestInsertNode(destGroup->getParentAct()->getId(), "Features", -1, "", newGroup.get()); targetGroupId = getString(newGroup.get(), "InstanceId"); // move target instance in that group (becomes the leader) getEditor().getDMC().requestMoveNode(destGroup->getId(), "", -1, targetGroupId, "Components", -1); } // move newly created entity into target group getEditor().getDMC().requestInsertNode(targetGroupId, "Components", -1, "", newEntityDesc); getEditor().getDMC().getActionHistoric().endAction(); getEditor().getDMC().flushActions(); }