/** This method loads the choam section of the INI file */ void INIMapEditorLoader::loadChoam() { INIFile::KeyIterator iter; for(iter = inifile->begin("CHOAM"); iter != inifile->end("CHOAM"); ++iter) { std::string UnitStr = iter->getKeyName(); Uint32 unitID = getItemIDByName(UnitStr); if((unitID == ItemID_Invalid) || !isUnit(unitID)) { logWarning(iter->getLineNumber(), "Invalid unit string: '" + UnitStr + "'"); continue; } int num = iter->getIntValue(-2); if(num == -2) { logWarning(iter->getLineNumber(), "Invalid choam number!"); continue; } if(num == -1) { num = 0; } pMapEditor->getChoam()[unitID] = num; } }
TVector &TVector::Default() { if (isUnit()) _Status = DEFAULT; return *this; }
/** This method loads the reinforcements from the [REINFORCEMENTS] section. */ void INIMapEditorLoader::loadReinforcements() { INIFile::KeyIterator iter; for(iter = inifile->begin("REINFORCEMENTS"); iter != inifile->end("REINFORCEMENTS"); ++iter) { std::string strHouseName; std::string strUnitName; std::string strDropLocation; std::string strTime; std::string strPlus; if(splitString(iter->getStringValue(), 4, &strHouseName, &strUnitName, &strDropLocation, &strTime) == false) { if(splitString(iter->getStringValue(), 5, &strHouseName, &strUnitName, &strDropLocation, &strTime, &strPlus) == false) { logWarning(iter->getLineNumber(), "Invalid reinforcement string: " + iter->getKeyName() + " = " + iter->getStringValue()); continue; } } int houseID = getHouseID(strHouseName); if(houseID == HOUSE_UNUSED) { // skip reinforcement for unused house continue; } else if(houseID == HOUSE_INVALID) { logWarning(iter->getLineNumber(), "Invalid house string: '" + strHouseName + "'!"); continue; } Uint32 unitID = getItemIDByName(strUnitName); if((unitID == ItemID_Invalid) || !isUnit(unitID)) { logWarning(iter->getLineNumber(), "Invalid unit string: '" + strUnitName + "'!"); continue; } DropLocation dropLocation = getDropLocationByName(strDropLocation); if(dropLocation == Drop_Invalid) { logWarning(iter->getLineNumber(), "Invalid drop location string: '" + strDropLocation + "'!"); dropLocation = Drop_Homebase; } Uint32 droptime; if(!parseString(strTime, droptime)) { logWarning(iter->getLineNumber(), "Invalid drop time string: '" + strTime + "'!"); continue; } bool bRepeat = (strTime.rfind('+') == (strTime.length() - 1)) || (strPlus == "+"); pMapEditor->getReinforcements().push_back(ReinforcementInfo(houseID, unitID, dropLocation, droptime, bRepeat)); } }
ostream &TVector::write(ostream &out) const { if (isValid()){ if (isUnit()) return out<<"<"<<X()<<","<<Y()<<","<<Z()<<">"; else return out<<"["<<X()<<","<<Y()<<","<<Z()<<"]"; } return out<<"Invalid"; }
void GameUnit<UnitType>::SetPlanetOrbitData (PlanetaryTransform *t) { #ifdef FIX_TERRAIN if (isUnit()!=BUILDINGPTR) return; if (!planet) planet = (PlanetaryOrbitData *)malloc (sizeof (PlanetaryOrbitData)); else if (!t) { free (planet); planet=NULL; } if (t) { planet->trans = t; planet->dirty=true; } #endif }
int main(){ Formula f; Interpretation I; int clauses=rand()%20; int var=rand()%30; createFormula(&f, clauses, var); generateFullRandomFormula(&f,clauses,var); createAndInitializeInterpretation(&I, f.nbVariables); for (int i = 0; i < f.nbVariables; ++i) { assignVariable(I,i,rand()%2); } int randomValue= rand()%(f.nbClauses); printf("\nstatus of a random clause %d: %d",randomValue,statusClause(f.clauses[randomValue],I)); randomValue= rand()%(f.nbClauses); printf("\nsatifcation of a random clause %d : %d",randomValue,isSatisfiedClause(f.clauses[randomValue],I)); randomValue= rand()%(f.nbClauses); printf("\nfalsefcation of a random clause %d : %d",randomValue,isFalsifiedClause(f.clauses[randomValue],I)); randomValue= rand()%(f.nbClauses); printf("\nUndetermination of a random clause %d : %d",randomValue,isUndefClause(f.clauses[randomValue],I)); randomValue= rand()%(f.nbClauses); printf("\nUnit of a random clause %d : %d",randomValue,isUnit(f.clauses[randomValue],I)); printf("\nThe status of the fourmla is %d",statusFormula(f,I)); printf("\nSatification of the fourmla is %d",isSatisfiedFormula(f,I)); printf("\nFalefication of the fourmla is %d",isFalsifiedFormula(f,I)); printf("\nUndetermination of the fourmla is %d",isUndefFormula(f,I)); displayFormula(f,I); }
//does not check inside sphere float Unit::querySphereNoRecurse( const QVector &start, const QVector &end, float min_radius ) const { int i; double tmp; for (i = 0; i < nummesh(); i++) { if ( ( meshdata[i]->Position().Magnitude() > this->rSize() ) || ( meshdata[i]->rSize() > 30+this->rSize() ) ) continue; if (isUnit() == PLANETPTR && i > 0) break; double a, b, c; QVector st = start-Transform( cumulative_transformation_matrix, meshdata[i]->Position().Cast() ); QVector dir = end-start; //now start and end are based on mesh's position c = st.Dot( st ); double temp1 = ( min_radius+meshdata[i]->rSize() ); //if (st.MagnitudeSquared()<temp1*temp1) //UNCOMMENT if you want inside sphere to count...otherwise... //return 1.0e-6; if (min_radius != -FLT_MAX) c = c-temp1*temp1; else c = temp1; #ifdef VARIABLE_LENGTH_PQR c *= SizeScaleFactor*SizeScaleFactor; #endif b = 2.0f*( dir.Dot( st ) ); a = dir.Dot( dir ); //b^2-4ac if (min_radius != -FLT_MAX) c = b*b-4.0f*a*c; else c = FLT_MAX; if (c < 0 || a == 0) continue; a *= 2.0f; tmp = ( -b+sqrt( c ) )/a; c = ( -b-sqrt( c ) )/a; if (tmp > 0 && tmp <= 1) return (c > 0 && c < tmp) ? c : tmp; else if (c > 0 && c <= 1) return c; } return 0.0f; }
void RtfCssEditor::keyPressEvent(QKeyEvent *e) { if (currentCompleter == ALTERNATE) { currentCompleter = DEFAULT; setCompleter(standardCompleter); } //If enter is pressed if (((e->key() == Qt::Key_Enter) || (e->key() == Qt::Key_Return)) && (!c->popup()->isVisible())) { QTextCursor tc = textCursor(); int currentPos = tc.position(); tc.select(QTextCursor::LineUnderCursor); QString line = tc.selectedText(); tc.setPosition(currentPos); if (line.indexOf("{") != -1) { insertBrace(); return; } else { insertTabulation(); return; } } if (c && c->popup()->isVisible()) { // The following keys are forwarded by the completer to the widget switch (e->key()) { case Qt::Key_Enter: return; case Qt::Key_Return: return; case Qt::Key_Escape: case Qt::Key_Tab: case Qt::Key_Backtab: e->ignore(); return; // let the completer do default behavior default: break; } } bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_Space); // CTRL+E if (!c || !isShortcut) // dont process the shortcut when we have a completer QTextEdit::keyPressEvent(e); const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier); if (!c || (ctrlOrShift && e->text().isEmpty())) return; static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift; QString completionPrefix = textUnderCursor(); if (isUnit() && isShortcut) { insertPropriety(UNIT); return; } if (isPropriety() && isShortcut) { insertPropriety(VALUE); return; } if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3 || eow.contains(e->text().right(1)))) { c->popup()->hide(); return; } if (completionPrefix != c->completionPrefix()) { c->setCompletionPrefix(completionPrefix); c->popup()->setCurrentIndex(c->completionModel()->index(0, 0)); } QRect cr = cursorRect(); cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width()); c->complete(cr); // popup it up! }
/** This method loads the units specified by the [Units] section. */ void INIMapEditorLoader::loadUnits() { INIFile::KeyIterator iter; for(iter = inifile->begin("UNITS"); iter != inifile->end("UNITS"); ++iter) { if(iter->getKeyName().find("ID") == 0) { int unitID = 0; parseString(iter->getKeyName().substr(2), unitID); std::string HouseStr, UnitStr, health, PosStr, rotation, mode; splitString(iter->getStringValue(),6,&HouseStr,&UnitStr,&health,&PosStr,&rotation,&mode); HOUSETYPE houseID = getHouseID(HouseStr); if(houseID == HOUSE_UNUSED) { // skip unit for unused house continue; } else if(houseID == HOUSE_INVALID) { logWarning(iter->getLineNumber(), "Invalid house string for '" + UnitStr + "': '" + HouseStr + "'!"); continue; } int pos; if(!parseString(PosStr, pos) || (pos < 0)) { logWarning(iter->getLineNumber(), "Invalid position string for '" + UnitStr + "': '" + PosStr + "'!"); continue; } int angle; if(!parseString(rotation, angle) || (angle < 0) || (angle > 255)) { logWarning(iter->getLineNumber(), "Invalid rotation string: '" + rotation + "'!"); angle = 64; } angle = (angle+16)/32; angle = ((NUM_ANGLES - angle) + 2) % NUM_ANGLES; int itemID = getItemIDByName(UnitStr); if((itemID == ItemID_Invalid) || !isUnit(itemID)) { logWarning(iter->getLineNumber(), "Invalid unit string: '" + UnitStr + "'!"); continue; } int iHealth; if(!parseString(health, iHealth) || (iHealth < 0) || (iHealth > 256)) { logWarning(iter->getLineNumber(), "Invalid health string: '" + health + "'!"); iHealth = 256; } ATTACKMODE attackmode = getAttackModeByName(mode); if(attackmode == ATTACKMODE_INVALID) { logWarning(iter->getLineNumber(), "Invalid attackmode string: '" + mode + "'!"); attackmode = AREAGUARD; } if(itemID == Unit_Soldier || itemID == Unit_Saboteur || itemID == Unit_Trooper || itemID == Unit_Infantry || itemID == Unit_Troopers) { if(angle == UP) { angle = UP; } else if (angle == DOWN) { angle = DOWN; } else if (angle == LEFTUP || angle == LEFTDOWN || angle == LEFT) { angle = LEFT; } else /*(angle == RIGHT)*/ { angle = RIGHT; } } pMapEditor->units.push_back(MapEditor::Unit(unitID, houseID, itemID, iHealth, Coord(getXPos(pos),getYPos(pos)), (unsigned char) angle, attackmode)); } else { logWarning(iter->getLineNumber(), "Invalid unit key: '" + iter->getKeyName() + "'!"); continue; } } }
boost::optional<Unit> UnitFactorySingleton::createUnit(const std::string& unitString, UnitSystem system) const { if (m_callbackMaps.size() == 0) { LOG(Warn,"UnitFactorySingleton::createUnit called, but the maps appear to be empty."); } if (!unitString.empty() && !isUnit(unitString)) { LOG(Error,unitString << " is not properly formatted."); return boost::none; } OptionalUnit result = createUnitSimple(unitString,system); if (result) { return *result; } // no luck--start parsing std::string wUnitString(unitString); ScaleConstant scale = ScaleFactory::instance().createScale(0); if (isScaledUnit(wUnitString)) { std::pair<std::string,std::string> scaleAndUnit = decomposeScaledUnitString(wUnitString); scale = ScaleFactory::instance().createScale(scaleAndUnit.first); if (scale().value == 0.0) { LOG(Error,"Scaled unit string " << wUnitString << " uses invalid scale abbreviation " << scaleAndUnit.first << "."); return boost::none; } wUnitString = scaleAndUnit.second; } // wUnitString should now be compound unit std::pair< std::vector<std::string>,std::vector<std::string> > atomicUnits = decomposeCompoundUnitString(wUnitString); // loop through numerator std::vector<std::string>::const_iterator atomicUnitIter; std::vector<std::string>::const_iterator vectorEnd = atomicUnits.first.end(); std::pair<std::string,int> atomicUnit; for (atomicUnitIter = atomicUnits.first.begin(); atomicUnitIter != vectorEnd; ++atomicUnitIter) { // decompose into baseUnit and exponent atomicUnit = decomposeAtomicUnitString(*atomicUnitIter); // look for baseUnit OptionalUnit baseUnit = createUnitSimple(atomicUnit.first,system); if (!baseUnit) { // decompose into scale, baseUnit std::pair<std::string,std::string> scaleAndBaseUnit = extractScaleAbbreviation(atomicUnit.first); if (!scaleAndBaseUnit.first.empty()) { baseUnit = createUnitSimple(scaleAndBaseUnit.second,system); if (!baseUnit) { baseUnit = Unit(); baseUnit->setBaseUnitExponent(scaleAndBaseUnit.second,1); } baseUnit->setScale(scaleAndBaseUnit.first); } else { baseUnit = Unit(); baseUnit->setBaseUnitExponent(atomicUnit.first,1); } } baseUnit->pow(atomicUnit.second); if (!result) { result = baseUnit; } else { result = (*result) * (*baseUnit); } } // loop through denominator vectorEnd = atomicUnits.second.end(); for (atomicUnitIter = atomicUnits.second.begin(); atomicUnitIter != vectorEnd; ++atomicUnitIter) { // decompose into baseUnit and exponent atomicUnit = decomposeAtomicUnitString(*atomicUnitIter); // look for baseUnit OptionalUnit baseUnit = createUnitSimple(atomicUnit.first,system); if (!baseUnit) { // decompose into scale, baseUnit std::pair<std::string,std::string> scaleAndBaseUnit = extractScaleAbbreviation(atomicUnit.first); if (!scaleAndBaseUnit.first.empty()) { baseUnit = createUnitSimple(scaleAndBaseUnit.second,system); if (!baseUnit) { LOG(Info,scaleAndBaseUnit.second << " is not a registered baseUnit (in the selected system). " << "Returning it as-is in a mixed Unit (not SI, IP, etc.)."); baseUnit = Unit(); baseUnit->setBaseUnitExponent(scaleAndBaseUnit.second,1); } baseUnit->setScale(scaleAndBaseUnit.first); } else { LOG(Info,scaleAndBaseUnit.second << " is not a registered baseUnit (in the selected system). " << "Returning it as-is in a mixed Unit (not SI, IP, etc.)."); baseUnit = Unit(); baseUnit->setBaseUnitExponent(atomicUnit.first,1); } } baseUnit->pow(atomicUnit.second); if (!result) { baseUnit->pow(-1); result = baseUnit; } else { result = (*result) / (*baseUnit); } } BOOST_ASSERT(result); // impose overall scale if (scale().exponent != 0) { ScaleOpReturnType resultScale = scale()*result->scale(); result->setScale(resultScale.first().exponent); } return result; }
// Do actually the computation set<Assignment> SPGParser::computeReductible(int i, int j) { set<Assignment> as; // Base case if(i == j && isType(i)) { if(isUnit(i)) as.insert(Assignment::singleton(headType[i])); return as; } if(j == i+1) { if(isType(i) && isType(j) && gcon(i,j)) { as.insert(Assignment::singleton(headType[i])); // we could add j but headType[i] == headType[j] so it's no use } return as; } if(isType(i) && isType(j) && isStar(i+1) && isStar(j-1) && widx[j] == widx[i]+1 && gcon(i,j)) { Assignment a = Assignment::singleton(headType[i]); a.insert(headType[j]); as.insert(a); return as; } if(isType(i) && isType(j)) { // A1a for(int k = i+1; k < j-1; k++) if(isType(k) && reductible(i,k) && reductible(k+1,j)) as = as + product(assignments[i][k], assignments[k+1][j]); // A1b for(int k = i+1; k < j-1; k++) if(isRB(k) && isLB(k+1) && reductible(i,k) && reductible(k+1,j)) as = as + product(assignments[i][k], assignments[k+1][j]); // A2 if(gcon(i,j) && reductible(i+1,j-1)) { set<Assignment> a = assignments[i+1][j-1]; Assignment rhs; rhs.insert(headType[i]); rhs.insert(headType[j]); set<Assignment> b; b.insert(rhs); as = as + product(a, b); } } // A3a if(isLB(i) && isType(j)) { for(int k = i+1; k < j && widx[k] == widx[i]; k++) if(isStar(k) && reductible(k+1, j)) as = as + assignments[k+1][j]; } // A3b if(isRB(j) && isType(i)) { for(int k = j-1; k > i && widx[k] == widx[j]; k--) if(isStar(k) && reductible(i,k-1)) as = as + assignments[i][k-1]; } // A4a if(isType(i) && isType(j) && isStar(i+1) && gcon(i,j) && widx[i] != widx[j]) { for(int k = i+1; k < j && widx[k] == widx[i]; k++) if(isLB(k+1) && reductible(k+1,j-1)) as = as + assignments[k+1][j-1]; } // A4b if(isType(i) && isType(j) && isStar(j-1) && gcon(i,j) && widx[i] != widx[j]) { for(int k = j-1; k > i && widx[k] == widx[j]; k--) if(isRB(k-1) && reductible(i+1,k-1)) as = as + assignments[i+1][k-1]; } // A4c if(isType(i) && isType(j) && isStar(i+1) && isStar(j-1) && 1 + widx[i] < widx[j] && gcon(i,j)) { int k1, k2; for(k1 = i+1; k1 < j && !isRB(k1); k1++); for(k2 = j-1; k2 > i && !isLB(k2); k2--); if(reductible(k1,k2)) as = as + assignments[k1][k2]; } // A5 if(isLB(i) && isRB(j)) { float totalProb = 0; for(int k1 = i+1; k1 < j && !isRB(k1); k1++) { if(isType(k1) && isStar(k1-1)) { for(int k2 = j-2; k2 > i && !isLB(k2); k2--) { if(isType(k2) && isStar(k2+1) && reductible(k1,k2)) as = as + assignments[k1][k2]; } } } } return as; }
bool vTreeLEDControl::isAny(uint8_t id){ return(isBcast(id) || isGroup(id) || isUnit(id)); }
bool vTreeLEDControl::isUnitOrBcast(uint8_t id){ return(isUnit(id) || isBcast(id)); }