// FOR SYNCED MESSAGES void CGame::ActionReceived(const Action& action, int playernum) { if (action.command == "cheat") { SetBoolArg(gs->cheatEnabled, action.extra); if (gs->cheatEnabled) logOutput.Print("Cheating!"); else logOutput.Print("No more cheating"); } else if (action.command == "nohelp") { SetBoolArg(gs->noHelperAIs, action.extra); selectedUnits.PossibleCommandChange(NULL); logOutput.Print("LuaUI control is %s", gs->noHelperAIs ? "disabled" : "enabled"); } else if (action.command == "nospecdraw") { bool buf; SetBoolArg(buf, action.extra); inMapDrawer->SetSpecMapDrawingAllowed(buf); } else if (action.command == "godmode") { if (!gs->cheatEnabled) logOutput.Print("godmode requires /cheat"); else { SetBoolArg(gs->godMode, action.extra); CLuaUI::UpdateTeams(); if (gs->godMode) { logOutput.Print("God Mode Enabled"); } else { logOutput.Print("God Mode Disabled"); } CPlayer::UpdateControlledTeams(); } } else if (action.command == "globallos") { if (!gs->cheatEnabled) { logOutput.Print("globallos requires /cheat"); } else { SetBoolArg(gs->globalLOS, action.extra); if (gs->globalLOS) { logOutput.Print("Global LOS Enabled"); } else { logOutput.Print("Global LOS Disabled"); } } } else if (action.command == "nocost" && gs->cheatEnabled) { if (unitDefHandler->ToggleNoCost()) { logOutput.Print("Everything is for free!"); } else { logOutput.Print("Everything costs resources again!"); } } else if (action.command == "give" && gs->cheatEnabled) { std::string s = "give "; //FIXME lazyness s += action.extra; // .give [amount] <unitName> [team] <@x,y,z> const vector<string> &args = CSimpleParser::Tokenize(s, 0); if (args.size() < 3) { logOutput.Print("Someone is spoofing invalid .give messages!"); return; } float3 pos; if (sscanf(args[args.size() - 1].c_str(), "@%f,%f,%f", &pos.x, &pos.y, &pos.z) != 3) { logOutput.Print("Someone is spoofing invalid .give messages!"); return; } int amount = 1; int team = playerHandler->Player(playernum)->team; int allyteam = -1; int amountArgIdx = -1; int teamArgIdx = -1; if (args.size() == 5) { amountArgIdx = 1; teamArgIdx = 3; } else if (args.size() == 4) { if (args[1].find_first_not_of("0123456789") == string::npos) { amountArgIdx = 1; } else { teamArgIdx = 2; } } if (amountArgIdx >= 0) { const string& amountStr = args[amountArgIdx]; amount = atoi(amountStr.c_str()); if ((amount < 0) || (amountStr.find_first_not_of("0123456789") != string::npos)) { logOutput.Print("Bad give amount: %s", amountStr.c_str()); return; } } if (teamArgIdx >= 0) { const string& teamStr = args[teamArgIdx]; team = atoi(teamStr.c_str()); if ((team < 0) || (team >= teamHandler->ActiveTeams()) || (teamStr.find_first_not_of("0123456789") != string::npos)) { logOutput.Print("Bad give team: %s", teamStr.c_str()); return; } } const string unitName = (amountArgIdx >= 0) ? args[2] : args[1]; if (unitName == "all") { // player entered ".give all" int numRequestedUnits = unitDefHandler->unitDefs.size() - 1; /// defid=0 is not valid int currentNumUnits = teamHandler->Team(team)->units.size(); int sqSize = (int) streflop::ceil(streflop::sqrt((float) numRequestedUnits)); // make sure team unit-limit not exceeded if ((currentNumUnits + numRequestedUnits) > uh->MaxUnitsPerTeam()) { numRequestedUnits = uh->MaxUnitsPerTeam() - currentNumUnits; } // make sure square is entirely on the map float sqHalfMapSize = sqSize / 2 * 10 * SQUARE_SIZE; pos.x = std::max(sqHalfMapSize, std::min(pos.x, float3::maxxpos - sqHalfMapSize - 1)); pos.z = std::max(sqHalfMapSize, std::min(pos.z, float3::maxzpos - sqHalfMapSize - 1)); for (int a = 1; a <= numRequestedUnits; ++a) { float posx = pos.x + (a % sqSize - sqSize / 2) * 10 * SQUARE_SIZE; float posz = pos.z + (a / sqSize - sqSize / 2) * 10 * SQUARE_SIZE; float3 pos2 = float3(posx, pos.y, posz); const UnitDef* ud = unitDefHandler->GetUnitDefByID(a); if (ud) { const CUnit* unit = unitLoader.LoadUnit(ud, pos2, team, false, 0, NULL); if (unit) { unitLoader.FlattenGround(unit); } } } } else if (!unitName.empty()) { int numRequestedUnits = amount; int currentNumUnits = teamHandler->Team(team)->units.size(); if (currentNumUnits >= uh->MaxUnitsPerTeam()) { LogObject() << "Unable to give any more units to team " << team << "(current: " << currentNumUnits << ", max: " << uh->MaxUnits() << ")"; return; } // make sure team unit-limit is not exceeded if ((currentNumUnits + numRequestedUnits) > uh->MaxUnitsPerTeam()) { numRequestedUnits = uh->MaxUnitsPerTeam() - currentNumUnits; } const UnitDef* unitDef = unitDefHandler->GetUnitDefByName(unitName); if (unitDef != NULL) { int xsize = unitDef->xsize; int zsize = unitDef->zsize; int squareSize = (int) streflop::ceil(streflop::sqrt((float) numRequestedUnits)); int total = numRequestedUnits; float3 minpos = pos; minpos.x -= ((squareSize - 1) * xsize * SQUARE_SIZE) / 2; minpos.z -= ((squareSize - 1) * zsize * SQUARE_SIZE) / 2; for (int z = 0; z < squareSize; ++z) { for (int x = 0; x < squareSize && total > 0; ++x) { float minposx = minpos.x + x * xsize * SQUARE_SIZE; float minposz = minpos.z + z * zsize * SQUARE_SIZE; const float3 upos(minposx, minpos.y, minposz); const CUnit* unit = unitLoader.LoadUnit(unitDef, upos, team, false, 0, NULL); if (unit) { unitLoader.FlattenGround(unit); } --total; } } logOutput.Print("Giving %i %s to team %i", numRequestedUnits, unitName.c_str(), team); } else { if (teamArgIdx < 0) { team = -1; // default to world features allyteam = -1; } else { allyteam = teamHandler->AllyTeam(team); } const FeatureDef* featureDef = featureHandler->GetFeatureDef(unitName); if (featureDef) { int xsize = featureDef->xsize; int zsize = featureDef->zsize; int squareSize = (int) streflop::ceil(streflop::sqrt((float) numRequestedUnits)); int total = amount; // FIXME -- feature count limit? float3 minpos = pos; minpos.x -= ((squareSize - 1) * xsize * SQUARE_SIZE) / 2; minpos.z -= ((squareSize - 1) * zsize * SQUARE_SIZE) / 2; for (int z = 0; z < squareSize; ++z) { for (int x = 0; x < squareSize && total > 0; ++x) { float minposx = minpos.x + x * xsize * SQUARE_SIZE; float minposz = minpos.z + z * zsize * SQUARE_SIZE; float minposy = ground->GetHeight2(minposx, minposz); const float3 upos(minposx, minposy, minposz); CFeature* feature = new CFeature(); feature->Initialize(upos, featureDef, 0, 0, team, allyteam, ""); --total; } } logOutput.Print("Giving %i %s (feature) to team %i", numRequestedUnits, unitName.c_str(), team); } else { logOutput.Print(unitName + " is not a valid unitname"); } } } } else if (action.command == "destroy" && gs->cheatEnabled) { std::stringstream ss(action.extra); logOutput.Print("Killing units: %s", action.extra.c_str()); do { unsigned id; ss >> id; if (!ss) break; if (id >= uh->units.size()) continue; if (uh->units[id] == NULL) continue; uh->units[id]->KillUnit(false, false, 0); } while (true); }
void SeedPointFileIO::ReadPointsFromFile() { // Different possibilities to give the seedpoints, added for compatibility // with mevis lab. All in world coordinates // 1 as plain string, separated by whitespaces // 2 as itkimage file, nonzeros are converted // 3 as txtfile (check on extension, possibly with six values on each line // but only first three are taken) // 4 as ml xml file // m_Points.clear(); if (m_FileName.empty()) { std::cout << "missing filename for seedpoints" << std::endl; } if (m_Verbose) { std::cout << "reading points from \t" << m_FileName << std::endl; } // 1 string // 2 itkfile // 3 txtfile // 4 xmlfile bool succeeded(false); int guess(0); // determine extension const std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); if (ext == ".vtk" || ext == ".mhd" || ext == ".dcm" || ext == ".VTK" || ext == ".MHD" || ext == ".DCM" ) guess = 2; if (ext == ".txt" || ext == ".TXT" ) guess = 3; if (ext == ".xml" || ext == ".XML" ) guess = 4; if (guess == 0) guess = 1; // try as string if (guess == 1) { InternalPrecision buf; std::istringstream ss(m_FileName); std::vector<InternalPrecision> tokens; while (ss >> buf) { tokens.push_back(buf); } const unsigned int n = tokens.size()/3; if (n>=2) { for (unsigned int i=0; i<n; ++i) { PrecisionPointType q; q[0] = tokens[i*3]; q[1] = tokens[i*3+1]; q[2] = tokens[i*3+2]; m_Points.push_back(q); } succeeded = true; } else { if (m_Verbose) { std::cout << "error interpreting as string " << std::endl; } } }
int routingHandler::StringToInt(std::string str) { std::stringstream ss(str); int i; ss >> i; return i; }
uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType) { if (nIn >= txTo.vin.size()) { printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn); return 1; } CTransaction txTmp(txTo); // In case concatenating two scripts ends up with two codeseparators, // or an extra one at the end, this prevents all those possible incompatibilities. scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR)); // Blank out other inputs' signatures for (int i = 0; i < txTmp.vin.size(); i++) txTmp.vin[i].scriptSig = CScript(); txTmp.vin[nIn].scriptSig = scriptCode; // Blank out some of the outputs if ((nHashType & 0x1f) == SIGHASH_NONE) { // Wildcard payee txTmp.vout.clear(); // Let the others update at will for (int i = 0; i < txTmp.vin.size(); i++) if (i != nIn) txTmp.vin[i].nSequence = 0; } else if ((nHashType & 0x1f) == SIGHASH_SINGLE) { // Only lockin the txout payee at same index as txin unsigned int nOut = nIn; if (nOut >= txTmp.vout.size()) { printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut); return 1; } txTmp.vout.resize(nOut+1); for (int i = 0; i < nOut; i++) txTmp.vout[i].SetNull(); // Let the others update at will for (int i = 0; i < txTmp.vin.size(); i++) if (i != nIn) txTmp.vin[i].nSequence = 0; } // Blank out other inputs completely, not recommended for open transactions if (nHashType & SIGHASH_ANYONECANPAY) { txTmp.vin[0] = txTmp.vin[nIn]; txTmp.vin.resize(1); } // Serialize and hash CDataStream ss(SER_GETHASH); ss.reserve(10000); ss << txTmp << nHashType; return Hash(ss.begin(), ss.end()); }
// Load the object/category mappings. // void Category_Maps::load(void) { loaded = true; cat_by_image_id.clear(); cat_by_item_id.clear(); std::string fullpath = get_path_config() + std::string(filename); std::ifstream in(fullpath.c_str()); if (!in) return; while (!in.eof()) { // read the info, image_id and item_id lines std::string info_line, image_id_line, item_id_line; while (getline_nocr(in, info_line) && info_line.empty()); getline_nocr(in, image_id_line); getline_nocr(in, item_id_line); if (info_line.empty()) break; // read the category std::istringstream ss(info_line); int category = -1; ss >> category; // read and count the image id values and store in the map ss.clear(); ss.str(image_id_line); int value = 0; int actual_num_image_ids = 0; int expected_num_image_ids = 0; ss >> expected_num_image_ids; while (ss >> value) { cat_by_image_id[value] = category; actual_num_image_ids++; } // read and count the item id values and store in the map ss.clear(); ss.str(item_id_line); Uint16 ui_value = 0; int actual_num_item_ids = 0; int expected_num_item_ids = 0; ss >> expected_num_item_ids; while (ss >> ui_value) { cat_by_item_id[ui_value] = category; actual_num_item_ids++; } // check for format errors and end now if something detected if ((category<0) || (actual_num_image_ids != expected_num_image_ids) || (actual_num_item_ids != expected_num_item_ids)) { LOG_TO_CONSOLE(c_red2, item_list_cat_format_error_str); LOG_ERROR("%s: %s cat=%d expected/actual image=%d/%d item %d/%d\n", __FILE__, item_list_cat_format_error_str, category, expected_num_image_ids, actual_num_image_ids, expected_num_item_ids, actual_num_item_ids ); break; } } must_save = false; }