Ejemplo n.º 1
0
void MonsterManager::storeExplodedBullets(std::vector<NameValueList> explodedBullets)
{
	/// 清空上次所有炮弹的信息
	mExplodeBulletsLists.clear();

	/// 用于利用空格分解坐标信息的临时变量
	std::vector<std::string> bulletPosStrings;

	/// 用于储存单个炮弹信息的临时变量
	ExplodedBulletsStruct* explodedBulletsTemp;

	/// 遍历子弹,储存所有炮弹信息
	for(auto iter = explodedBullets.begin(); iter != explodedBullets.end(); ++iter)
	{
		explodedBulletsTemp = new ExplodedBulletsStruct();
		/// 获取炮弹数据,将其转换成应有类型
		/// 炮弹伤害
		if ((*iter).find("damage") != (*iter).end())
			explodedBulletsTemp->bulletHarm = (float)atof((*iter)["damage"].c_str());
		/// 炮弹附加伤害
		if ((*iter).find("appendDamage") != (*iter).end())
			explodedBulletsTemp->bulletAppendHarm = (float)atof((*iter)["appendDamage"].c_str());
		/// 炮弹半径范围
		if ((*iter).find("range") != (*iter).end())
			explodedBulletsTemp->bulletRadius = (float)atof((*iter)["range"].c_str());
		/// 炮弹属性
		if ((*iter).find("spell") != (*iter).end())
			explodedBulletsTemp->bulletType = ((*iter)["spell"].c_str());
		/// 炮弹效果持续时间
		if ((*iter).find("time") != (*iter).end())
			explodedBulletsTemp->bulletEffectTime = (float)atof((*iter)["time"].c_str());
		/// 炮弹中心点位置
		if ((*iter).find("position") != (*iter).end())
		{	
			bulletPosStrings = mysplit((*iter)["position"]);
			explodedBulletsTemp->bulletPos[0] = (float)atof(bulletPosStrings[0].c_str());
			explodedBulletsTemp->bulletPos[1] = (float)atof(bulletPosStrings[1].c_str());
			explodedBulletsTemp->bulletPos[2] = (float)atof(bulletPosStrings[2].c_str());

		}
		mExplodeBulletsLists.push_back(explodedBulletsTemp);
	}

}
Ejemplo n.º 2
0
int fromCatFile(KategProblem *p,const char *fname,bool verb)
{
  leda_h_array<string,int> translation(-1);
  int maxCat=2;
  ifstream in(fname);
  if(!in)
    {
      cerr << "Error: File '" << fname << "' cannot be opened.\n";
      exit(1);
    }
  for(int i=0;i<p->wordFreq.nWords;i++)
    (p->initLike)[i]= -1;
  
  
  translation["1"]=1;
  translation["0"]=0;

  
  string s;
  while( getline(in,s) ) 
    {
      string str,categ;
      mysplit(s,str,categ);
      int i=p->words->binary_locate(str);
      if(i>=0 && (*(p->words))[i]==str )
	{
	  
	  if( translation[categ]==-1 )
	    translation[categ]=maxCat++;
	  int cat=translation[categ];
	  if( (p->initLike)[i]!= -1 )
	    cerr << "Warning: Word '" << ((*(p->words))[i])<< "' is already in a category.\n";
	  (p->initLike)[i]=cat;
	}
      else
	cerr << "Warning: Word '" << str << "' " << i << " is not in training corpus.\n";
    }
  
  if( verboseMode )
    cout << "We have " << maxCat << " read non-empty categories" 
      " (with words from the corpus).\n";
  
  if(maxCat>p->katFreq.nKats)
    {
      cerr << "Error: Not enough categories reserved (only " 
	   << p->katFreq.nKats << ", but i need " << maxCat << ").\n";
      exit(1);
    }
  
  
  int i=p->words->binary_locate("$");
  if( i>=0 &&  (*(p->words))[i]=="$" )
    (p->initLike)[i]=0;
  else
    if( verboseMode )
      cerr << "Warning: No '$' in vocabulary!\n";
  
  
  int errors=0;
  for(i=0;i<p->wordFreq.nWords;i++)
    if((p->initLike)[i]== -1 )
      {
	if( verb ) cerr << "Error: I don't know the category of word " << i 
	     << " (" << (*(p->words))[i] << ") " << ".\n";
	errors=1;
      }
  return errors;
}