void BattleSquad::turnStart() { if (this->getUnitNum()==0) { return; } DataLibrary* datalib = DataLibrary::getSingletonPtr(); float ap = getAttr(ATTR_ACTIONPOINT,ATTRCALC_FULL); setActionPoint(ap); setAPSetup(0.0f); setAPBattle(0.0f); std::vector<std::string> activeskills; activeskills = datalib->getChildList(mPath + "/Skill"); std::vector<std::string>::iterator ite; for(ite = activeskills.begin(); ite != activeskills.end(); ite++) { int cooldown = 0; datalib->getData(mPath + "/Skill/" + (*ite) + "/CoolDown", cooldown); if(cooldown > 0) cooldown -= 1; datalib->setData(mPath + "/Skill/" + (*ite) + "/CoolDown", cooldown); } LuaTempContext* luatempcontext = new LuaTempContext(); luatempcontext->strMap["squadid"] = getSquadId(); Trigger("TurnStart", luatempcontext); delete luatempcontext; }
bool BattleSquad::addParticle(std::string particlename, int object, std::string &particleid) { DataLibrary* datalib = DataLibrary::getSingletonPtr(); std::string distpath = mPath + std::string("/ParticleList"); std::vector<std::string> particlelist = datalib->getChildList(distpath); int x = 0; particleid = std::string("p") + Ogre::StringConverter::toString(x); std::vector<std::string>::iterator ite = std::find(particlelist.begin(), particlelist.end(),particleid); while(ite != particlelist.end()) { x = x + 1; particleid = std::string("p") + Ogre::StringConverter::toString(x); ite = std::find(particlelist.begin(), particlelist.end(),particleid); } distpath = distpath + std::string("/") + particleid; datalib->setData(distpath + std::string("/ParticleName"), particlename, true); datalib->setData(distpath + std::string("/AffectUnit"), object, true); return true; }
void MapLoader::loadMapObj() { DataLibrary* datalibrary = DataLibrary::getSingletonPtr(); Terrain* terrain = Terrain::getSingletonPtr(); std::string datapath("GameData/BattleData/MapData/MapObjModleInfo"); std::vector<std::string> childlist; childlist = datalibrary->getChildList(datapath); if(childlist.size()>0) { for(unsigned int n = 0; n < childlist.size(); n++) { std::string meshname; int x,y,dir; datalibrary->getData(datapath + std::string("/") + childlist[n] + std::string("/Mesh"),meshname); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridX"),x); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridY"),y); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/Direction"),dir); int index; index = terrain->createMapObj(x,y,meshname, dir); datalibrary->setData(datapath + std::string("/") + childlist[n] + std::string("/Index"),index); } } datapath = "GameData/BattleData/MapData/MapParticleInfo"; childlist = datalibrary->getChildList(datapath); if(childlist.size()>0) { for(unsigned int n = 0; n < childlist.size(); n++) { std::string particlename; int x,y; datalibrary->getData(datapath + std::string("/") + childlist[n] + std::string("/Particle"),particlename); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridX"),x); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridY"),y); int index; index = terrain->createMapParticle(x,y,particlename); datalibrary->setData(datapath + std::string("/") + childlist[n] + std::string("/Index"),index); } } }
void BattleSquad::setUnitNum(int val) { DataLibrary* datalib = DataLibrary::getSingletonPtr(); datalib->setData(getPath() + "/UnitNum", val); LuaTempContext* luatempcontext = new LuaTempContext(); luatempcontext->strMap["squadid"] = getSquadId(); Trigger("UnitNumChange", luatempcontext); delete luatempcontext; if(getUnitNum() <= 0) { LuaTempContext* luatempcontext = new LuaTempContext(); luatempcontext->strMap["squadid"] = getSquadId(); MapDataManager::getSingleton().Trigger("SquadAnnihilated", luatempcontext); delete luatempcontext; } }
bool BattleSquad::useSkillAt(int x, int y, std::string skillid) { if(canUseSkill(skillid) != SKILLSTATE_AVAILABLE) return false; DataLibrary* datalib = DataLibrary::getSingletonPtr(); std::string skillpath = getPath() + std::string("/Skill/") + skillid; std::string skillinfopath = std::string("StaticData/SkillData/")+ skillid; std::string skillscript; datalib->getData(skillinfopath + std::string("/Script"),skillscript); LuaTempContext* context = new LuaTempContext; context->strMap.insert(std::make_pair("squadid", getSquadId())); context->intMap.insert(std::make_pair("targetx", x)); context->intMap.insert(std::make_pair("targety", y)); context->intMap.insert(std::make_pair("castsuccess", 0)); bool re = LuaSystem::getSingleton().executeFunction(skillscript, "useskill" , skillpath + std::string("/ScriptContext"), context); if(re) { if(context->intMap["castsuccess"] == 1) { float apcost = getSkillApCost(skillid); float apleft = getActionPoint() - apcost; setActionPoint(apleft); int aptype = SKILLAPTYPE_BATTLE; datalib->getData(skillinfopath + "/APType", aptype); if(aptype != SKILLAPTYPE_DEFENCE) { apcost = getAPTypeCostModify(aptype); apcost += 1.0f; setAPTypeCostModify(aptype, apcost); } int cooldown; datalib->getData(skillinfopath + "/CoolDown", cooldown); datalib->setData(skillpath + "/CoolDown", cooldown); } } delete context; return false; }
bool MapLoader::loadMapFormFile(std::string mapname) { int mapsize; Terrain* terrain = Terrain::getSingletonPtr(); DataLibrary* datalibrary = DataLibrary::getSingletonPtr(); std::string path = ".\\..\\Media\\Map\\" + mapname; //ticpp::Document *doc = new ticpp::Document(); rapidxml::xml_document<> doc; //doc.LoadFile(path,TIXML_ENCODING_UTF8); Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(mapname, "Data", true); char* s=new char[stream->size()+1]; stream->read(s,stream->size()); s[stream->size()]='\0'; doc.parse<0>(s); std::string str1; //载入地图名字,介绍和脚本名 //ticpp::Element *element = doc.FirstChildElement("MapName"); rapidxml::xml_node<> * element = doc.first_node("MapName"); //element->GetText(&str1); str1 = element->value(); datalibrary->setData("GameData/BattleData/MapData/MapName", StringTable::getSingleton().getString(str1)); //delete element; //element = doc.FirstChildElement("MapScript"); element = doc.first_node("MapScript"); //element->GetText(&str1); str1 = element->value(); datalibrary->setData("GameData/BattleData/MapData/MapScript", str1); //delete element; element = doc.first_node("MapMini"); //element->GetText(&str1); if (element!=NULL) { str1 = element->value(); } else { str1="MiniMap1.png"; } datalibrary->setData("GameData/BattleData/MapData/MapMini", str1); //element = doc.FirstChildElement("MapInfo"); element = doc.first_node("MapInfo"); //element->GetText(&str1); str1 = element->value(); datalibrary->setData("GameData/BattleData/MapData/MapInfo",str1); //delete element; //element = doc.FirstChildElement("MapLoadBG"); element = doc.first_node("MapLoadBG"); //element->GetText(&str1); str1 = element->value(); datalibrary->setData("GameData/BattleData/MapData/MapLoadBG",str1); //delete element; //载入地图地形信息 //element = doc.FirstChildElement("MapSize"); element = doc.first_node("MapSize"); //element->GetText(&mapsize); mapsize = Ogre::StringConverter::parseUnsignedInt(element->value()); MapDataManager::getSingleton().mMapSize = mapsize; datalibrary->setData("GameData/BattleData/MapData/MapSize", mapsize); //delete element; //element= doc.FirstChildElement("MapGround"); element = doc.first_node("MapGround"); //ticpp::Iterator<ticpp::Element> child; rapidxml::xml_node<> *child = element->first_node(); std::string datapath; //for(child = child.begin(element); child != child.end(); child++) for(; child; child =child->next_sibling()) { std::string layer,type,texture; //child->GetValue(&layer); layer = child->name(); //child->GetAttribute("Type",&type); rapidxml::xml_attribute<> *attr = child->first_attribute("Type"); type = attr->value(); //child->GetAttribute("Texture",&texture); attr = child->first_attribute("Texture"); texture = attr->value(); datapath = str(boost::format("GameData/BattleData/MapData/Ground/%1%")%layer); datalibrary->setData(datapath, type); datapath = str(boost::format("GameData/BattleData/MapData/Ground/%1%Tex")%layer); datalibrary->setData(datapath, texture); } //delete element; //element = doc.FirstChildElement("MapData"); element = doc.first_node("MapData"); //element->GetText(&str1); str1 = element->value(); for(int y = 0; y < mapsize; y++) { for(int x = 0; x < mapsize; x++) { int index = y * mapsize + x; char datapathtemp[64]; sprintf_s(datapathtemp, 64, "GameData/BattleData/MapData/Map/M%d", MapDataManager::getSingleton().getGridId(x, y)); std::string datapath = datapathtemp; if(str1[index * 2] == 'l') { bool iscliff = false; for(int i = y - 1; i < y + 2; i ++) { for(int j = x - 1; j < x + 2; j++) { int u = (i<0)?0:i; u = (u >= mapsize)?mapsize-1:u; int v = (j<0)?0:j; v = (v >= mapsize)?mapsize-1:v; int tempindex = u * mapsize + v; if(str1[tempindex * 2] == 'h' ) { iscliff = true; } } } if(iscliff) datalibrary->setData(datapath + "/TerrainType", Cliff); else datalibrary->setData(datapath + "/TerrainType", LowGround); } else if(str1[index * 2] == 'w') { datalibrary->setData(datapath + "/TerrainType", Water); } else if(str1[index * 2] == 'h') { datalibrary->setData(datapath + "/TerrainType", HighGround); } else if(str1[index * 2] == 'r') { datalibrary->setData(datapath + "/TerrainType", Ramp); } if(str1[index * 2+1] == 'g') { datalibrary->setData(datapath + "/GroundType", GreenLand); } else if(str1[index * 2+1] == 'd') { datalibrary->setData(datapath + "/GroundType", Desert); } else if(str1[index * 2+1] == 'w') { datalibrary->setData(datapath + "/GroundType", Swamp); } else if(str1[index * 2+1] == 's') { datalibrary->setData(datapath + "/GroundType", Snow); } } } //delete element; //element = doc.FirstChildElement("MapObject"); element = doc.first_node("MapObject"); //for(child = child.begin(element); child != child.end(); child++) for(child = element->first_node(); child; child =child->next_sibling()) { std::string objname; //child->GetValue(&objname); objname = child->name(); datapath = std::string("GameData/BattleData/MapData/MapObjModleInfo/") + objname; int objx,objy, objdir; std::string meshname,objtype; //child->GetAttribute("GridX",&objx); rapidxml::xml_attribute<> *attr = child->first_attribute("GridX"); objx = Ogre::StringConverter::parseInt(attr->value()); //child->GetAttribute("GridY",&objy); attr = child->first_attribute("GridY"); objy = Ogre::StringConverter::parseInt(attr->value()); //child->GetAttribute("Mesh",&meshname); attr=child->first_attribute("Mesh"); meshname = attr->value(); //child->GetAttribute("Type",&objtype); attr=child->first_attribute("Type"); objtype = attr->value(); attr=child->first_attribute("Direction"); objdir = Ogre::StringConverter::parseInt(attr->value()); datalibrary->setData(datapath + "/GridX", objx); datalibrary->setData(datapath + "/GridY", objy); datalibrary->setData(datapath + "/Mesh", meshname); datalibrary->setData(datapath + "/Direction", objdir); //物品类型脚本 std::string mapobjscript("none"); datalibrary->getData(str(boost::format("StaticData/MapObjType/%1%/Script")%objtype), mapobjscript); datapath = std::string("GameData/BattleData/MapData/Map/M") + Ogre::StringConverter::toString(MapDataManager::getSingleton().getGridId(objx, objy)) + std::string("/MapObjType"); if(mapobjscript != "none") { MapObjScriptInfo scriptinfo; scriptinfo.x = objx; scriptinfo.y = objy; scriptinfo.script = mapobjscript; scriptinfo.path = datapath + "/ScriptContext"; mMapObjScriptInfo.push(scriptinfo); } datalibrary->setData(datapath, objtype); datalibrary->setData(datapath + "/MapObjModuleId", objname); } //delete element; //element = doc.FirstChildElement("MapEffect"); element = doc.first_node("MapEffect"); //for(child = child.begin(element); child != child.end(); child++) for(child = element->first_node(); child; child =child->next_sibling()) { std::string particlename; //child->GetValue(&particlename); particlename = child->name(); datapath = std::string("GameData/BattleData/MapData/MapParticleInfo/") + particlename; int particlex,particley; std::string name; //child->GetAttribute("GridX",&particlex); rapidxml::xml_attribute<> *attr = child->first_attribute("GridX"); particlex = Ogre::StringConverter::parseInt(attr->value()); //child->GetAttribute("GridY",&particley); attr = child->first_attribute("GridY"); particley = Ogre::StringConverter::parseInt(attr->value()); //child->GetAttribute("Type",&name); attr = child->first_attribute("Type"); name = attr->value(); datalibrary->setData(datapath + "/GridX", particlex); datalibrary->setData(datapath + "/GridY", particley); datalibrary->setData(datapath + "/Type", name); } terrain->createTerrain(); //delete element; //载入区域信息 //element = doc.FirstChildElement("MapArea"); element = doc.first_node("MapArea"); //for(child = child.begin(element); child != child.end(); child++) for(child = element->first_node(); child; child =child->next_sibling()) { std::string areaname; //child->GetValue(&areaname); areaname = child->name(); datapath = std::string("GameData/BattleData/MapData/Area/") + areaname; Area area(datapath + "/CoordList"); std::vector<Crood> croodVec; //ticpp::Iterator<ticpp::Element> childchild; rapidxml::xml_node<> *childchild = child->first_node(); //for(childchild = childchild.begin(child.Get()); childchild != childchild.end(); childchild++) for(; childchild; childchild=childchild->next_sibling()) { std::string coordname; //childchild->GetValue(&coordname); coordname = childchild->name(); int x; int y; //childchild->GetAttribute("X",&x); rapidxml::xml_attribute<> *attr = childchild->first_attribute("X"); x = Ogre::StringConverter::parseInt(attr->value()); //childchild->GetAttribute("Y",&y); attr = childchild->first_attribute("Y"); y = Ogre::StringConverter::parseInt(attr->value()); croodVec.push_back(Crood(x, y)); } area.setCroodVec(croodVec); MapDataManager::getSingleton().mMapArea.insert(std::make_pair(areaname, area)); } //delete element; //载入队伍信息 //element = doc.FirstChildElement("MapTeam"); element = doc.first_node("MapTeam"); for(int n = 2; n < 5; n++) { std::string name = std::string("Team") + Ogre::StringConverter::toString(n); std::string factionid; //ticpp::Element* subelement = element->FirstChildElement(name); child = element->first_node(name.c_str()); //subelement->GetAttribute("TeamFaction",&factionid); rapidxml::xml_attribute<> *attr = child->first_attribute("TeamFaction"); factionid = attr->value(); datalibrary->setData(std::string("GameData/BattleData/Team/")+ name+ "/FactionId", factionid); if(factionid != "none") { //subelement->GetAttribute("TeamType",&factionid); attr = child->first_attribute("TeamType"); factionid = attr->value(); datalibrary->setData(std::string("GameData/BattleData/Team/")+ name+ "/Relation", factionid); } //delete subelement; } std::string playerfactionid; datalibrary->getData("GameData/StoryData/Faction",playerfactionid); datalibrary->setData("GameData/BattleData/Team/Team1/FactionId",playerfactionid); datalibrary->setData("GameData/BattleData/Team/Team1/Relation","player"); //delete element; //载入部队信息 //element = doc.FirstChildElement("MapSquad"); element = doc.first_node("MapSquad"); MapSquadInfo mapsquadinfo; //for(child = child.begin(element); child != child.end(); child++) for(child = element->first_node(); child;child = child->next_sibling()) { std::string teamid; //child->GetValue(&teamid); teamid = child->name(); if(teamid == "Team1") mapsquadinfo.team = 1; else if(teamid == "Team2") mapsquadinfo.team = 2; else if(teamid == "Team3") mapsquadinfo.team = 3; else mapsquadinfo.team = 4; datapath = std::string("GameData/BattleData/SquadList"); //ticpp::Iterator<ticpp::Element> childchild; rapidxml::xml_node<> *childchild = child->first_node(); //for(childchild = childchild.begin(child.Get()); childchild != childchild.end(); childchild++) for(; childchild; childchild =childchild->next_sibling()) { // std::string squadid; // std::string squadtype; //childchild->GetValue(&mapsquadinfo.squadId); mapsquadinfo.squadId = childchild->name(); // int x; // int y; // Direction d; // int unitnum; // int morale; //childchild->GetAttribute("Type",&mapsquadinfo.squadTempId); rapidxml::xml_attribute<> *attr = childchild->first_attribute("Type"); mapsquadinfo.squadTempId = attr->value(); //childchild->GetAttribute("GridX",&mapsquadinfo.x); attr = childchild->first_attribute("GridX"); mapsquadinfo.x = Ogre::StringConverter::parseInt(attr->value()); //childchild->GetAttribute("GridY",&mapsquadinfo.y); attr = childchild->first_attribute("GridY"); mapsquadinfo.y = Ogre::StringConverter::parseInt(attr->value()); //childchild->GetAttribute("UnitNum",&mapsquadinfo.unitNum); attr = childchild->first_attribute("UnitNum"); mapsquadinfo.unitNum = Ogre::StringConverter::parseInt(attr->value()); //childchild->GetAttribute("Direction",&mapsquadinfo.dir); attr = childchild->first_attribute("Direction"); mapsquadinfo.dir = Ogre::StringConverter::parseInt(attr->value()); mMapSquadInfo.push(mapsquadinfo); // AVGSquadManager::getSingleton().addSquad(squadid,squadtype, datapath); // int type; // Formation f; // datalibrary->getData(datapath + std::string("/") + squadid + std::string("/Type"), type ); // if(type == SQUAD_NORMAL) // f = Line; // else // f = Loose; // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/GridX"), x, true ); // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/GridY"), y, true ); // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/UnitNumber"), unitnum, true ); // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/Direction"), d, true ); // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/Formation"), f, true ); // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/TeamId"), teamid, true ); // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/CreateType"), MapSquad, true ); // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/ActionPoint"), 0.0f, true ); // datalibrary->setData(datapath + std::string("/") + squadid + std::string("/Morale"), morale, true ); } } //delete element; delete []s; return true; }