// *************************************************************** void CToolSelectRotate::beginAction(CInstance &instance) { //H_AUTO(R2_CToolSelectRotate_beginAction) _MouseStartX = getMouseX(); _StartAngle = (float) instance.getObjectTable()->toNumber("Angle"); setRotateInProgress(true, instance); }
//*************************************************************** CInstance *CAutoGroup::getGroupingCandidate() { //H_AUTO(R2_CAutoGroup_getGroupingCandidate) if (!_AutoGroupEnabled) return NULL; // if I'm a bot object, don't auto-group CObject *palEntry = getEditor().getDMC().getPaletteElement(_PaletteEntry); if (!palEntry || !palEntry->isTable()) return NULL; if (getNumber(palEntry, "IsBotObject") == 1) return NULL; // auto-group feature // look in default feature and sort objects by distance CInstance *defaultFeatInst = getEditor().getDefaultFeature(getEditor().getCurrentAct()); CInstance *baseDefaultFeatInst = getEditor().getDefaultFeature(getEditor().getBaseAct()); if (!defaultFeatInst || !baseDefaultFeatInst) { nlwarning("Can't access to Default Features"); // syntax error in lua was making the client crash return NULL; //In this case there is no default features } CObjectTable *defaultFeat = defaultFeatInst->getObjectTable(); CObjectTable *baseDefaultFeat = baseDefaultFeatInst->getObjectTable(); CObject *components = defaultFeat->getAttr("Components"); CObject *baseComponents = baseDefaultFeat->getAttr("Components"); if (!components || !baseComponents || !palEntry->isTable()) return NULL; _SortedComponents.clear(); for (uint k = 0; k < (components->getSize()+baseComponents->getSize()); ++k) { CObject *obj = NULL; if(k<components->getSize()) obj = components->getValue(k); else obj = baseComponents->getValue(k - components->getSize()); CInstance *inst = getEditor().getInstanceFromObject(obj); if (!inst) { nlwarning("Error: can not find create Instance of an object."); continue; } CDisplayerVisual *dv = inst->getDisplayerVisual(); if (!dv) continue; CComponentSort cs; cs.Dist = (_TestPos - dv->getWorldPos()).norm(); if (cs.Dist > CV_AutoGroupMaxDist.get()) continue; cs.Instance = inst; _SortedComponents.push_back(cs); } // iterate through other features CObjectTable *act = getEditor().getCurrentAct()->getObjectTable(); CObjectTable *baseAct = getEditor().getBaseAct()->getObjectTable(); if (!act || !baseAct) return NULL; CObject *features = act->getAttr("Features"); CObject *baseFeatures = baseAct->getAttr("Features"); if (!features || !baseFeatures) return NULL; for (uint k = 0; k < (features->getSize()+baseFeatures->getSize()); ++k) { CObject *obj = NULL; if(k<features->getSize()) obj = features->getValue(k); else obj = baseFeatures->getValue(k - features->getSize()); CInstance *inst = getEditor().getInstanceFromObject(obj); CDisplayerVisual *dv = inst->getDisplayerVisual(); if (!dv) continue; if (inst->isKindOf("NpcGrpFeature")) { if (dv->getNumSons() == 0) continue; CComponentSort cs; cs.Dist = (_TestPos - dv->getSon(0)->getWorldPos()).norm(); if (cs.Dist > CV_AutoGroupMaxDist.get()) continue; cs.Instance = inst; _SortedComponents.push_back(cs); } } std::sort(_SortedComponents.begin(), _SortedComponents.end()); CLuaState &ls = getEditor().getLua(); const CObject *categoryObj = getObject(palEntry, "Category"); if (!categoryObj) { nlwarning("No 'Category' field in palEntry '%s'", _PaletteEntry.c_str()); return NULL; } if (!categoryObj->isString()) return NULL; std::string category = categoryObj->toString(); // const CObject *subCategoryObj = getObject(palEntry, "SubCategory"); std::string subCategory; if (subCategoryObj && subCategoryObj->isString()) { subCategory = subCategoryObj->toString(); } else { //nlwarning("No 'SubCategory' field in palEntry '%s'", paletteEntry.c_str()); } // if (category.empty()) return NULL; for(uint k = 0; k < _SortedComponents.size(); ++k) { CLuaStackRestorer lsr(&ls, 0); if (_SortedComponents[k].Instance->isKindOf("Npc")) { _SortedComponents[k].Instance->getLuaProjection().callMethodByNameNoThrow("isPlant", 0, 1); if (ls.toBoolean(-1) == true) continue; _SortedComponents[k].Instance->getLuaProjection().callMethodByNameNoThrow("isBotObject", 0, 1); if (ls.toBoolean(-1) == true) continue; } else if (!_SortedComponents[k].Instance->isKindOf("NpcGrpFeature")) { continue; } std::string destCategory; if (_SortedComponents[k].Instance->getLuaProjection().callMethodByNameNoThrow("getCategory", 0, 1)) { destCategory = ls.toString(-1); ls.pop(); } if (destCategory != category) continue; // std::string destSubCategory; if (_SortedComponents[k].Instance->getLuaProjection().callMethodByNameNoThrow("getSubCategory", 0, 1)) { if (ls.isString(-1)) { destSubCategory = ls.toString(-1); } ls.pop(); } if (destSubCategory != subCategory) continue; // good candidate return _SortedComponents[k].Instance; } return NULL; }