bool BaseModel::evalCondition( const QModelIndex & index, bool chkParents ) const { NifItem * item = static_cast<NifItem*>( index.internalPointer() ); if ( index.isValid() && index.model() == this && item ) return evalCondition( item, chkParents ); return false; }
NifItem * BaseModel::getItem( NifItem * item, const QString & name ) const { if ( ! item || item == root ) return 0; int slash = name.indexOf( "/" ); if ( slash > 0 ) { QString left = name.left( slash ); QString right = name.right( name.length() - slash - 1 ); if ( left == ".." ) return getItem( item->parent(), right ); else return getItem( getItem( item, left ), right ); } for ( int c = 0; c < item->childCount(); c++ ) { NifItem * child = item->child( c ); if ( child->name() == name && evalCondition( child ) ) return child; } return 0; }
bool PNPActionServer::EvalConditionWrapper(pnp_msgs::PNPCondition::Request &req, pnp_msgs::PNPCondition::Response &res) { //cout << "EvalConditionWrapper started " << endl; int r0 = -1; // This is necessary because multiple calls to the same condition can happen if (ConditionCache.find(req.cond) != ConditionCache.end()) { r0 = ConditionCache[req.cond]; } int r1 = evalCondition(req.cond); int r2 = check_for_event(req.cond); //cout << "EvalConditionWrapper " << req.cond << " : cache / eval / check " << r0 << " " << r1 << " " << r2 ; int result=-1; if (r0!=-1) result=r0; else if (r1!=-1) result=r1; else result=r2; //TODO implement unknown value of a condition in PNP if (result==-1) result=0; //cout << " RESULT = " << result << endl; ConditionCache[req.cond] = result; res.truth_value = result; return true; }
/* * Uses implicit load order */ NifItem * BaseModel::getItemX( NifItem * item, const QString & name ) const { if ( ! item || ! item->parent() ) return 0; NifItem * parent = item->parent(); for ( int c = item->row() - 1; c >= 0; c-- ) { NifItem * child = parent->child( c ); if ( child && child->name() == name && evalCondition( child ) ) return child; } return getItemX( parent, name ); }
bool BaseModel::evalCondition( NifItem * item, bool chkParents ) const { if ( ! evalVersion( item, chkParents ) ) return false; if ( item == root ) return true; if ( chkParents && item->parent() ) if ( ! evalCondition( item->parent(), true ) ) return false; QString cond = item->cond(); if ( cond.isEmpty() ) return true; BaseModelEval functor(this, item); return item->condexpr().evaluateBool(functor); }
Qt::ItemFlags BaseModel::flags( const QModelIndex & index ) const { if ( !index.isValid() ) return Qt::ItemIsEnabled; Qt::ItemFlags flags = Qt::ItemIsSelectable; if ( evalCondition( index, true ) ) flags |= Qt::ItemIsEnabled; switch( index.column() ) { case TypeCol: return flags; case ValueCol: if ( itemArr1( index ).isEmpty() ) return flags | Qt::ItemIsEditable; else return flags; default: return flags | Qt::ItemIsEditable; } }
static bool evalCondition(const QString &s, const QVariantMap &context) { // for now all we support is variable test with optional negation if(s.startsWith("not ")) { return !evalCondition(s.mid(4), context); } else { QVariant val = getVar(s, context); if(val.type() == QVariant::String) return !val.toString().isEmpty(); else if(val.type() == QVariant::Bool) return val.toBool(); else if(val.canConvert(QVariant::Int)) return (val.toInt() != 0); else return false; } }
static CondResult parseSingleCondition (const Key * key, const char * condition, const Key * suffixList, KeySet * ks, Key * parentKey) { Comparator cmpOp; char * opStr; opStr = condition2cmpOp (condition, &cmpOp); if (!opStr) { return ERROR; } int opLen; if (cmpOp == LT || cmpOp == GT || cmpOp == NEX) { opLen = 1; } else { opLen = 2; } unsigned long startPos = 0; unsigned long endPos = 0; char * ptr = (char *) condition; int firstNot = 1; if (*ptr == '!') { ++ptr; ++startPos; firstNot = 0; } while (isspace (*ptr)) { ++ptr; if ((cmpOp == NEX) && (*ptr == '!') && firstNot) { firstNot = 0; ++ptr; ++startPos; } ++startPos; } ptr = opStr - 1; while (ptr > condition && isspace (*ptr)) { --ptr; ++endPos; } int len = opStr - condition - endPos - startPos + 2; char * leftSide = elektraMalloc (len); char * rightSide = NULL; strncpy (leftSide, condition + startPos, len - 2); leftSide[len - 2] = '\0'; startPos = 0; endPos = 0; if (cmpOp == NEX) { goto parseSingleEnd; } ptr = opStr + opLen; while (isspace (*ptr)) { ++ptr; ++startPos; } ptr = (char *) condition + (elektraStrLen (condition) - 2); while (isspace (*ptr)) { --ptr; ++endPos; } len = elektraStrLen (condition) - (opStr - condition) - opLen - endPos - startPos; rightSide = elektraMalloc (len); strncpy (rightSide, opStr + opLen + startPos, len - 1); rightSide[len - 1] = '\0'; CondResult ret; parseSingleEnd: ret = evalCondition (key, leftSide, cmpOp, rightSide, condition, suffixList, ks, parentKey); if (rightSide) elektraFree (rightSide); elektraFree (leftSide); return ret; }
void BbvsEngine::initScene(bool sounds) { stopSpeech(); stopSounds(); _sound->unloadSounds(); _gameState = kGSScene; _prevSceneNum = _currSceneNum; _sceneVisited[_currSceneNum] = 1; _mouseCursorSpriteIndex = 0; _verbPos.x = -1; _verbPos.y = -1; _activeItemType = kITEmpty; _activeItemIndex = 0; _cameraPos.x = 0; _cameraPos.y = 0; _newCameraPos.x = 0; _newCameraPos.y = 0; _inventoryButtonIndex = -1; _currTalkObjectIndex = -1; _currCameraNum = 0; _walkMousePos.x = -1; _walkMousePos.y = -1; _currAction = 0; _currActionCommandIndex = -1; _currActionCommandTimeStamp = 0; _dialogSlotCount = 0; _buttheadObject = 0; _beavisObject = 0; memset(_backgroundSoundsActive, 0, sizeof(_backgroundSoundsActive)); memset(_sceneObjects, 0, sizeof(_sceneObjects)); for (int i = 0; i < kSceneObjectsCount; ++i) { _sceneObjects[i].walkDestPt.x = -1; _sceneObjects[i].walkDestPt.y = -1; } memset(_dialogItemStatus, 0, sizeof(_dialogItemStatus)); _sceneObjectActions.clear(); loadScene(_newSceneNum); _currSceneNum = _newSceneNum; _newSceneNum = 0; for (int i = 0; i < _gameModule->getSceneObjectDefsCount(); ++i) _sceneObjects[i].sceneObjectDef = _gameModule->getSceneObjectDef(i); for (int i = 0; i < _gameModule->getSceneObjectInitsCount(); ++i) { SceneObjectInit *soInit = _gameModule->getSceneObjectInit(i); if (evalCondition(soInit->conditions)) { SceneObject *sceneObject = &_sceneObjects[soInit->sceneObjectIndex]; sceneObject->anim = _gameModule->getAnimation(soInit->animIndex); sceneObject->animIndex = soInit->animIndex; sceneObject->frameIndex = sceneObject->anim->frameCount - 1; sceneObject->frameTicks = 1; sceneObject->x = soInit->x << 16; sceneObject->y = soInit->y << 16; } } if (_gameModule->getButtheadObjectIndex() >= 0) { _buttheadObject = &_sceneObjects[_gameModule->getButtheadObjectIndex()]; // Search for the Beavis object for (int i = 0; i < _gameModule->getSceneObjectDefsCount(); ++i) if (!strcmp(_sceneObjects[i].sceneObjectDef->name, "Beavis")) { _beavisObject = &_sceneObjects[i]; break; } } updateSceneObjectsTurnValue(); updateWalkableRects(); _currCameraNum = 0; if (_buttheadObject) { int minDistance = 0xFFFFFF; for (int cameraNum = 0; cameraNum < 4; ++cameraNum) { CameraInit *cameraInit = _gameModule->getCameraInit(cameraNum); int curDistance = ABS(cameraInit->cameraPos.x - (int)(_buttheadObject->x >> 16) + 160); if (curDistance < minDistance) { minDistance = curDistance; _currCameraNum = cameraNum; } } } _cameraPos = _gameModule->getCameraInit(_currCameraNum)->cameraPos; _newCameraPos = _cameraPos; _walkAreaActions.clear(); for (int i = 0; i < _gameModule->getActionsCount(); ++i) { Action *action = _gameModule->getAction(i); for (int j = 0; j < 8; ++j) if (action->conditions.conditions[j].cond == kCondIsButtheadAtBgObject) _walkAreaActions.push_back(action); } _mouseCursorSpriteIndex = 0; _activeItemIndex = 0; _activeItemType = kITEmpty; for (int i = 0; i < _gameModule->getActionsCount(); ++i) { Action *action = _gameModule->getAction(i); if (evalCondition(action->conditions)) { _gameState = kGSWait; _currAction = action; for (uint j = 0; j < action->actionCommands.size(); ++j) { ActionCommand *actionCommand = &action->actionCommands[j]; if (actionCommand->cmd == kActionCmdSetCameraPos) { _currCameraNum = actionCommand->param; _cameraPos = _gameModule->getCameraInit(_currCameraNum)->cameraPos; _newCameraPos = _cameraPos; break; } } break; } } if (sounds) updateBackgroundSounds(); }
static int parseSingleCondition(const char *condition, KeySet *ks, Key *parentKey) { Comparator cmpOp; char *opStr; if((opStr = strstr(condition, "=="))) cmpOp = EQU; else if((opStr = strstr(condition, "!="))) cmpOp = NOT; else if((opStr = strstr(condition, "<="))) cmpOp = LE; else if((opStr = strstr(condition, "<"))) cmpOp = LT; else if((opStr = strstr(condition, ">="))) cmpOp = GE; else if((opStr = strstr(condition, ">"))) cmpOp = GT; else if((opStr = strstr(condition, ":="))) cmpOp = SET; else return -1; int opLen; if(cmpOp == LT || cmpOp == GT) opLen = 1; else opLen = 2; unsigned long startPos = 0; unsigned long endPos = 0; char *ptr = (char *)condition; while(isspace(*ptr)) { ++ptr; ++startPos; } ptr = opStr-1; while(isspace(*ptr)) { --ptr; ++endPos; } char *leftSide = NULL; int len = opStr - condition - endPos - startPos + 2; leftSide = elektraMalloc(len); strncpy(leftSide, condition+startPos, len-2); leftSide[len-2] = '\0'; startPos = 0; endPos = 0; ptr = opStr+opLen; while(isspace(*ptr)) { ++ptr; ++startPos; } ptr = (char *)condition+(elektraStrLen(condition)-2); while(isspace(*ptr)) { --ptr; ++endPos; } char *rightSide = NULL; len = elektraStrLen(condition) - (opStr - condition) -opLen - endPos - startPos; rightSide = elektraMalloc(len); strncpy(rightSide, opStr+opLen+startPos, len-1); rightSide[len-1] = '\0'; int ret; ret = evalCondition(leftSide, cmpOp, rightSide, ks, parentKey); elektraFree(rightSide); elektraFree(leftSide); return ret; }