void ArgList::setArgValue(const std::string & sName, const std::string & sValue) { ArgBasePtr pArg = getArg(sName); Arg<string>* pStringArg = dynamic_cast<Arg<string>* >(&*pArg); Arg<UTF8String>* pUTF8StringArg = dynamic_cast<Arg<UTF8String>* >(&*pArg); Arg<int>* pIntArg = dynamic_cast<Arg<int>* >(&*pArg); Arg<float>* pFloatArg = dynamic_cast<Arg<float>* >(&*pArg); Arg<bool>* pBoolArg = dynamic_cast<Arg<bool>* >(&*pArg); Arg<glm::vec2>* pVec2Arg = dynamic_cast<Arg<glm::vec2>* >(&*pArg); Arg<glm::vec3>* pVec3Arg = dynamic_cast<Arg<glm::vec3>* >(&*pArg); Arg<glm::ivec3>* pIVec3Arg = dynamic_cast<Arg<glm::ivec3>* >(&*pArg); Arg<vector<float> >* pFVectorArg = dynamic_cast<Arg<vector<float> >* >(&*pArg); Arg<vector<int> >* pIVectorArg = dynamic_cast<Arg<vector<int> >* >(&*pArg); Arg<vector<glm::vec2> >* pVec2VectorArg = dynamic_cast<Arg<vector<glm::vec2> >* >(&*pArg); Arg<vector<glm::ivec3> >* pIVec3VectorArg = dynamic_cast<Arg<vector<glm::ivec3> >* >(&*pArg); Arg<CollVec2Vector>* pCollVec2VectorArg = dynamic_cast<Arg<CollVec2Vector>* >(&*pArg); if (pStringArg) { pStringArg->setValue(sValue); } else if (pUTF8StringArg) { pUTF8StringArg->setValue(sValue); } else if (pIntArg) { pIntArg->setValue(stringToInt(sValue)); } else if (pFloatArg) { pFloatArg->setValue(stringToFloat(sValue)); } else if (pBoolArg) { pBoolArg->setValue(stringToBool(sValue)); } else if (pVec2Arg) { pVec2Arg->setValue(stringToVec2(sValue)); } else if (pVec3Arg) { pVec3Arg->setValue(stringToVec3(sValue)); } else if (pIVec3Arg) { pIVec3Arg->setValue(stringToIVec3(sValue)); } else if (pFVectorArg) { vector<float> v; fromString(sValue, v); pFVectorArg->setValue(v); } else if (pIVectorArg) { vector<int> v; fromString(sValue, v); pIVectorArg->setValue(v); } else if (pVec2VectorArg) { vector<glm::vec2> v; fromString(sValue, v); pVec2VectorArg->setValue(v); } else if (pIVec3VectorArg) { vector<glm::ivec3> v; fromString(sValue, v); pIVec3VectorArg->setValue(v); } else if (pCollVec2VectorArg) { CollVec2Vector v; fromString(sValue, v); pCollVec2VectorArg->setValue(v); } else { AVG_ASSERT(false); } }
bool DataCenter::loadLevelInfo(int id, LevelInfo &info) { std::stringstream buffer; std::string str; buffer << "level_info_" << id << ".xml"; str = FileUtils::getInstance()->fullPathForFilename(buffer.str()); tinyxml2::XMLDocument doc; auto data = FileUtils::getInstance()->getDataFromFile(str); auto ret = doc.Parse((const char*)data.getBytes(), data.getSize()); //auto ret = doc.LoadFile(str.c_str()); if (ret != tinyxml2::XML_NO_ERROR) { return false; } const tinyxml2::XMLElement* e_root = nullptr; const tinyxml2::XMLElement* e_child_1 = nullptr; const tinyxml2::XMLElement* e_child_2 = nullptr; const tinyxml2::XMLElement* e_child_3 = nullptr; const tinyxml2::XMLElement* e_child_4 = nullptr; const tinyxml2::XMLElement* e_child_5 = nullptr; const tinyxml2::XMLElement* e_child_6 = nullptr; const tinyxml2::XMLElement* e_child_7 = nullptr; const tinyxml2::XMLElement* e_child_8 = nullptr; // set level id e_root = doc.RootElement(); CC_ASSERT(e_root != nullptr); info.id = e_root->FindAttribute("id")->IntValue(); // // Section: hound entry e_child_1 = e_root->FirstChildElement("Hound"); CC_ASSERT(e_child_1 != nullptr); e_child_1->FirstChildElement("Scale")->QueryFloatText(&info.hound_scale); scaleByDesign(info.hound_scale); e_child_1->FirstChildElement("BoundingCircleRadius")->QueryFloatText(&info.hound_bounding_circle_radius); scaleByDesign(info.hound_bounding_circle_radius); e_child_2 = e_child_1->FirstChildElement("Entry"); CC_ASSERT(e_child_2 != nullptr); str = e_child_2->FirstChildElement("From")->GetText(); stringToVec2(str, info.hound_entry_from); scaleByDesign(info.hound_entry_from); str = e_child_2->FirstChildElement("To")->GetText(); stringToVec2(str, info.hound_entry_to); scaleByDesign(info.hound_entry_to); e_child_2->FirstChildElement("Speed")->QueryFloatText(&info.hound_entry_speed); scaleByDesign(info.hound_entry_speed); e_child_2->FirstChildElement("AutoFacing")->QueryBoolText(&info.hound_entry_auto_facing); // // Section: hound leave e_child_2 = e_child_1->FirstChildElement("Leave"); CC_ASSERT(e_child_2 != nullptr); e_child_2->FirstChildElement("Speed")->QueryFloatText(&info.hound_leave_speed); scaleByDesign(info.hound_leave_speed); e_child_2->FirstChildElement("AutoFacing")->QueryBoolText(&info.hound_leave_auto_facing); // // Section: backgrounds e_child_1 = e_root->FirstChildElement("Backgrounds"); CC_ASSERT(e_child_1 != nullptr); for (e_child_2 = e_child_1->FirstChildElement(); e_child_2 != nullptr; e_child_2 = e_child_2->NextSiblingElement()) { info.sbg_layer_texture_names.push_back(e_child_2->GetText()); } // // Section: Enemy Waves WaveInfo w_info; EnemyInfo ef_info; BarrelInfo barrel; WeaponInfo weapon; StateInfo state; StateMapInfo state_map; Movement movement; e_child_1 = e_root->FirstChildElement("EnemyWaves"); if (e_child_1 == nullptr) { return true; // empty level } // for each wave for (e_child_2 = e_child_1->FirstChildElement(); e_child_2 != nullptr; e_child_2 = e_child_2->NextSiblingElement()) { w_info.time_offset = e_child_2->FindAttribute("time_offset")->FloatValue(); // for each enemy for (e_child_3 = e_child_2->FirstChildElement(); e_child_3 != nullptr; e_child_3 = e_child_3->NextSiblingElement()) { ef_info.id = e_child_3->FindAttribute("id")->IntValue(); charToString(e_child_3->FirstChildElement("Type")->GetText(), str); ef_info.type = getCommonType(str); e_child_3->FirstChildElement("Level")->QueryUnsignedText(&ef_info.level); auto mla = getEnemyMaxLifeArmor(ef_info.type, ef_info.level); ef_info.max_life = mla.first; ef_info.armor = mla.second; e_child_3->FirstChildElement("Scale")->QueryFloatText(&ef_info.scale_xy); scaleByDesign(ef_info.scale_xy); e_child_3->FirstChildElement("BoundingCircleRadius")->QueryFloatText(&ef_info.bounding_circle_radius); scaleByDesign(ef_info.bounding_circle_radius); e_child_3->FirstChildElement("RotateAngle")->QueryFloatText(&ef_info.rotate_angle); charToString(e_child_3->FirstChildElement("Asset")->GetText(), ef_info.body_texture_name); // entry e_child_4 = e_child_3->FirstChildElement("Entry"); charToString(e_child_4->FirstChildElement("From")->GetText(), str); stringToVec2(str, ef_info.entry_from); scaleByDesign(ef_info.entry_from); charToString(e_child_4->FirstChildElement("To")->GetText(), str); stringToVec2(str, ef_info.entry_to); scaleByDesign(ef_info.entry_to); e_child_4->FirstChildElement("Speed")->QueryFloatText(&ef_info.entry_speed); scaleByDesign(ef_info.entry_speed); e_child_4->FirstChildElement("AutoFacing")->QueryBoolText(&ef_info.entry_auto_facing); // leave e_child_4 = e_child_3->FirstChildElement("Leave"); e_child_4->FirstChildElement("Speed")->QueryFloatText(&ef_info.leave_speed); scaleByDesign(ef_info.leave_speed); e_child_4->FirstChildElement("AutoFacing")->QueryBoolText(&ef_info.leave_auto_facing); // for each weapon e_child_4 = e_child_3->FirstChildElement("Weapons"); if (e_child_4 != nullptr) { for (e_child_5 = e_child_4->FirstChildElement(); e_child_5 != nullptr; e_child_5 = e_child_5->NextSiblingElement()) { weapon.id = e_child_5->FindAttribute("id")->IntValue(); charToString(e_child_5->FirstChildElement("Type")->GetText(), str); weapon.type = getCommonType(str); e_child_5->FirstChildElement("Level")->QueryUnsignedText(&weapon.level); auto wds = getEnemyWeaponDSAT(weapon.type, weapon.level); weapon.damage = wds.first; weapon.speed = wds.second; weapon.acceleration = wds.third; weapon.steering_accel = wds.fourth; scaleByDesign(weapon.speed); scaleByDesign(weapon.acceleration); scaleByDesign(weapon.steering_accel); e_child_5->FirstChildElement("RotateAngle")->QueryFloatText(&weapon.rotate_angle); e_child_5->FirstChildElement("AutoAim")->QueryBoolText(&weapon.auto_aim); charToString(e_child_5->FirstChildElement("DockAt")->GetText(), str); stringToVec2(str, weapon.dock_position); e_child_5->FirstChildElement("FiringStart")->QueryFloatText(&weapon.time_offset_firing_start); e_child_5->FirstChildElement("FiringStop")->QueryFloatText(&weapon.time_offset_firing_stop); charToString(e_child_5->FirstChildElement("Asset")->GetText(), weapon.texture_name); // for each barrel e_child_6 = e_child_5->FirstChildElement("Barrells"); if (e_child_6 != nullptr) { for (e_child_7 = e_child_6->FirstChildElement(); e_child_7 != nullptr; e_child_7 = e_child_7->NextSiblingElement()) { charToString(e_child_7->FindAttribute("type")->Value(), str); barrel.type = getCommonType(str); e_child_7->FirstChildElement("RotateAngle")->QueryFloatText(&barrel.rotate_angle); e_child_7->FirstChildElement("FiringInterval")->QueryFloatText(&barrel.firing_interval); charToString(e_child_7->FirstChildElement("ProjectileType")->GetText(), str); barrel.projectile_type = getCommonType(str); e_child_7->FirstChildElement("ProjectileLevel")->QueryIntText(&barrel.projectile_level); e_child_7->FirstChildElement("ProjectileScale")->QueryFloatText(&barrel.projectile_scale_xy); scaleByDesign(barrel.projectile_scale_xy); auto pds = getEnemyProjectileDSAT(barrel.projectile_type, barrel.projectile_level); barrel.projectile_damage = pds.first; barrel.projectile_speed = pds.second; barrel.projectile_acceleration = pds.third; barrel.projectile_steering_accel = pds.fourth; scaleByDesign(barrel.projectile_speed); scaleByDesign(barrel.projectile_acceleration); barrel.projectile_final_damage = barrel.projectile_damage + weapon.damage; barrel.projectile_final_speed = barrel.projectile_speed + weapon.speed; barrel.projectile_final_acceleration = barrel.projectile_acceleration + weapon.acceleration; scaleByDesign(barrel.projectile_speed); charToString(e_child_7->FirstChildElement("Asset")->GetText(), barrel.projectile_asset_name); weapon.barrells.push_back(barrel); } } ef_info.weapons.push_back(weapon); weapon.barrells.clear(); } } // for each state e_child_4 = e_child_3->FirstChildElement("States"); if (e_child_4 != nullptr) { for (e_child_5 = e_child_4->FirstChildElement(); e_child_5 != nullptr; e_child_5 = e_child_5->NextSiblingElement()) { state.id = e_child_5->FindAttribute("id")->IntValue(); charToString(e_child_5->FindAttribute("type")->Value(), str); state.type = getCommonType(str); state.life_threshold = -FLT_MAX; e_child_6 = e_child_5->FirstChildElement("LifeThreshold"); if (e_child_6 != nullptr) { e_child_6->QueryFloatText(&state.life_threshold); } state.repeat_movements = false; e_child_6 = e_child_5->FirstChildElement("RepeatMovements"); if (e_child_6 != nullptr) { e_child_6->QueryBoolText(&state.repeat_movements); } // for each movement e_child_6 = e_child_5->FirstChildElement("Movements"); if (e_child_6 != nullptr) { for (e_child_7 = e_child_6->FirstChildElement(); e_child_7 != nullptr; e_child_7 = e_child_7->NextSiblingElement()) { charToString(e_child_7->FindAttribute("type")->Value(), str); movement.type = getCommonType(str); charToString(e_child_7->FirstChildElement("TargetPosition")->GetText(), str); stringToVec2(str, movement.target_position); scaleByDesign(movement.target_position); movement.displmt_auto_facing = false; e_child_8 = e_child_7->FirstChildElement("DisplacementAutoFacing"); if (e_child_8 != nullptr) { e_child_8->QueryBoolText(&movement.displmt_auto_facing); } movement.stay_period = FLT_MAX; e_child_8 = e_child_7->FirstChildElement("StayPeriod"); if (e_child_8 != nullptr) { e_child_8->QueryFloatText(&movement.stay_period); } movement.target_angle = 0.0f; e_child_8 = e_child_7->FirstChildElement("TargetAngle"); if (e_child_8 != nullptr) { e_child_8->QueryFloatText(&movement.target_angle); } movement.speed = 0.0f; e_child_8 = e_child_7->FirstChildElement("Speed"); if (e_child_8 != nullptr) { e_child_8->QueryFloatText(&movement.speed); if (movement.type == (int)MOVEMENT_TYPE::DISPLACEMENT) scaleByDesign(movement.speed); } movement.jump = false; e_child_8 = e_child_7->FirstChildElement("Jump"); if (e_child_8 != nullptr) { e_child_8->QueryBoolText(&movement.jump); } state.movements.push_back(movement); } } // for each weapon index e_child_6 = e_child_5->FirstChildElement("WeaponGroup"); if (e_child_6 != nullptr) { for (e_child_7 = e_child_6->FirstChildElement(); e_child_7 != nullptr; e_child_7 = e_child_7->NextSiblingElement()) { int weapon_index; e_child_7->QueryIntText(&weapon_index); state.weapons.push_back(weapon_index); } } ef_info.state_infoes.push_back(state); state.movements.clear(); state.weapons.clear(); } } // for each state transition e_child_4 = e_child_3->FirstChildElement("StateTransitions"); if (e_child_4 != nullptr) { for (e_child_5 = e_child_4->FirstChildElement(); e_child_5 != nullptr; e_child_5 = e_child_5->NextSiblingElement()) { charToString(e_child_5->FirstChildElement("Event")->GetText(), str); state_map.event = getCommonType(str); e_child_5->FirstChildElement("From")->QueryIntText(&state_map.from); e_child_5->FirstChildElement("To")->QueryIntText(&state_map.to); ef_info.state_map_infoes.push_back(state_map); } } w_info.enemies.push_back(ef_info); ef_info.weapons.clear(); ef_info.state_infoes.clear(); ef_info.state_map_infoes.clear(); } info.enemy_waves.push_back(w_info); w_info.enemies.clear(); } // return true; }
bool DataCenter::loadHoundInfoFromXml(HoundInfo &info) { std::string str; str = FileUtils::getInstance()->fullPathForFilename("hound_info.xml"); tinyxml2::XMLDocument doc; auto data = FileUtils::getInstance()->getDataFromFile(str); auto ret = doc.Parse((const char*)data.getBytes(), data.getSize()); //auto ret = doc.LoadFile(str.c_str()); if (ret != tinyxml2::XML_NO_ERROR) { return false; } const tinyxml2::XMLElement* e_root = nullptr; const tinyxml2::XMLElement* e_child_1 = nullptr; const tinyxml2::XMLElement* e_child_2 = nullptr; const tinyxml2::XMLElement* e_child_3 = nullptr; const tinyxml2::XMLElement* e_child_4 = nullptr; // get root element e_root = doc.RootElement(); CC_ASSERT(e_root != nullptr); // // Section: body e_child_1 = e_root->FirstChildElement("Body"); CC_ASSERT(e_child_1 != nullptr); charToString(e_child_1->FirstChildElement("Type")->GetText(), str); info.body_type = getCommonType(str); e_child_1->FirstChildElement("Level")->QueryUnsignedText(&info.body_level); charToString(e_child_1->FirstChildElement("Asset")->GetText(), info.body_asset_name); // exacting docking positions std::map<int, Vec2> docks; int dock_id; Vec2 dock_pos; e_child_2 = e_child_1->FirstChildElement("DockPoints"); for (e_child_3 = e_child_2->FirstChildElement(); e_child_3 != nullptr; e_child_3 = e_child_3->NextSiblingElement()) { dock_id = e_child_3->FindAttribute("id")->IntValue(); charToString(e_child_3->GetText(), str); stringToVec2(str, dock_pos); docks[dock_id] = dock_pos; } // Section: armor e_child_1 = e_root->FirstChildElement("Armor"); CC_ASSERT(e_child_1 != nullptr); charToString(e_child_1->FirstChildElement("Type")->GetText(), str); info.armor_type = getCommonType(str); e_child_1->FirstChildElement("Level")->QueryUnsignedText(&info.armor_level); charToString(e_child_1->FirstChildElement("Asset")->GetText(), info.armor_asset_name); // Section: engine e_child_1 = e_root->FirstChildElement("Engine"); CC_ASSERT(e_child_1 != nullptr); charToString(e_child_1->FirstChildElement("Type")->GetText(), str); info.engine_type = getCommonType(str); e_child_1->FirstChildElement("Level")->QueryUnsignedText(&info.engine_level); charToString(e_child_1->FirstChildElement("Asset")->GetText(), info.engine_asset_name); // get hound max life and armor value info.max_life = getHoundMaxLife(info.body_type, info.body_level); info.armor = getHoundArmor(info.armor_type, info.armor_level); // for each weapon e_child_1 = e_root->FirstChildElement("Weapons"); if (e_child_1 != nullptr) { for (e_child_2 = e_child_1->FirstChildElement(); e_child_2 != nullptr; e_child_2 = e_child_2->NextSiblingElement()) { WeaponInfo weapon; weapon.id = e_child_2->FindAttribute("id")->IntValue(); charToString(e_child_2->FirstChildElement("Type")->GetText(), str); weapon.type = getCommonType(str); e_child_2->FirstChildElement("Level")->QueryUnsignedText(&weapon.level); auto wds = getHoundWeaponDSAT(weapon.type, weapon.level); weapon.damage = wds.first; weapon.speed = wds.second; weapon.acceleration = wds.third; weapon.steering_accel = wds.fourth; scaleByDesign(weapon.speed); scaleByDesign(weapon.acceleration); e_child_2->FirstChildElement("RotateAngle")->QueryFloatText(&weapon.rotate_angle); e_child_2->FirstChildElement("AutoAim")->QueryBoolText(&weapon.auto_aim); e_child_2->FirstChildElement("DockAt")->QueryIntText(&dock_id); weapon.dock_position = docks[dock_id]; e_child_2->FirstChildElement("FiringStart")->QueryFloatText(&weapon.time_offset_firing_start); e_child_2->FirstChildElement("FiringStop")->QueryFloatText(&weapon.time_offset_firing_stop); charToString(e_child_2->FirstChildElement("Asset")->GetText(), weapon.texture_name); // for each barrel e_child_3 = e_child_2->FirstChildElement("Barrells"); if (e_child_3 != nullptr) { for (e_child_4 = e_child_3->FirstChildElement(); e_child_4 != nullptr; e_child_4 = e_child_4->NextSiblingElement()) { BarrelInfo barrel; charToString(e_child_4->FindAttribute("type")->Value(), str); barrel.type = getCommonType(str); e_child_4->FirstChildElement("RotateAngle")->QueryFloatText(&barrel.rotate_angle); e_child_4->FirstChildElement("FiringInterval")->QueryFloatText(&barrel.firing_interval); charToString(e_child_4->FirstChildElement("ProjectileType")->GetText(), str); barrel.projectile_type = getCommonType(str); e_child_4->FirstChildElement("ProjectileLevel")->QueryIntText(&barrel.projectile_level); e_child_4->FirstChildElement("ProjectileScale")->QueryFloatText(&barrel.projectile_scale_xy); scaleByDesign(barrel.projectile_scale_xy); auto pds = getHoundProjectileDSAT(barrel.projectile_type, barrel.projectile_level); barrel.projectile_damage = pds.first; barrel.projectile_speed = pds.second; barrel.projectile_acceleration = pds.third; barrel.projectile_steering_accel = pds.fourth; scaleByDesign(barrel.projectile_speed); scaleByDesign(barrel.projectile_acceleration); scaleByDesign(barrel.projectile_steering_accel); barrel.projectile_final_damage = barrel.projectile_damage + weapon.damage; barrel.projectile_final_speed = barrel.projectile_speed + weapon.speed; barrel.projectile_final_acceleration = barrel.projectile_acceleration + weapon.acceleration; barrel.projectile_final_steering_accel = barrel.projectile_steering_accel + weapon.steering_accel; charToString(e_child_4->FirstChildElement("Asset")->GetText(), barrel.projectile_asset_name); weapon.barrells.push_back(barrel); } } info.weapons.push_back(weapon); weapon.barrells.clear(); } } return true; }