Esempio n. 1
0
bool ParseRepetition(Repetition *Repetition, CallExpr *Call, Assertion *A,
                     vector<ValueDecl*>& References,
                     ASTContext& Ctx) {
  unsigned Args = Call->getNumArgs();
  if (Args < 3) {
    Report("Repetition must have at least three arguments (min, max, events)",
        Call->getLocStart(), Ctx)
      << Call->getSourceRange();
    return false;
  }

  auto Min = ParseIntegerLiteral(Call->getArg(0), Ctx);
  Repetition->set_min(Min.getLimitedValue());

  auto Max = ParseIntegerLiteral(Call->getArg(1), Ctx);
  if (Max != INT_MAX) Repetition->set_max(Max.getLimitedValue());

  for (unsigned i = 2; i < Args; ++i) {
    auto Ev = Call->getArg(i);
    if (!ParseEvent(Repetition->add_event(), Ev, A, References, Ctx)) {
      Report("Failed to parse repeated event", Ev->getLocStart(), Ctx)
        << Ev->getSourceRange();
      return false;
    }
  }

  return true;
}
Esempio n. 2
0
	FOR_EACH_SUBKEY(kv, subkey) {
		/* this is crustier then the other parsers:
		 * keeps calling subkey->GetName() instead of storing it in a local;
		 * also doesn't do a strlen check on the name */
		
		if (V_stricmp(subkey->GetName(), "WaveSpawn") == 0) {
			CWaveSpawnPopulator *wavespawn =
				new CWaveSpawnPopulator(this->m_PopMgr);
			if (!wavespawn->Parse(subkey)) {
				Warning("Error reading WaveSpawn definition\n");
				return false;
			}
			this->m_WaveSpawns.AddToTail(wavespawn);
			
			if (!wavespawn->m_bSupport) {
				this->m_iTotalCountNonSupport += wavespawn->m_iTotalCount;
			}
			this->m_iTotalCurrency += wavespawn->m_iTotalCurrency;
			
			wavespawn->m_Wave = this;
			
			IPopulationSpawner *spawner = wavespawn->m_Spawner;
			if (spawner != nullptr) {
				if (spawner->IsVarious()) {
					for (int i = 0; i < wavespawn->m_iTotalCount; ++i) {
						unsigned int flags = (wavespawn->m_bSupport ?
							CLASSFLAG_SUPPORT : CLASSFLAG_NORMAL);
						if (wavespawn->m_Spawner->IsMiniBoss()) {
							flags |= CLASSFLAG_MINIBOSS;
						}
						if (wavespawn->m_Spawner->HasAttribute(CTFBot::AttributeType::ALWAYSCRIT, i)) {
							flags |= CLASSFLAG_CRITICAL;
						}
						if (wavespawn->m_bSupportLimited) {
							flags |= CLASSFLAG_SUPPORT_LIMITED;
						}
						
						this->AddClassType(wavespawn->m_Spawner->GetClassIcon(i),
							1, flags);
					}
				} else {
					unsigned int flags = (wavespawn->m_bSupport ?
						CLASSFLAG_SUPPORT : CLASSFLAG_NORMAL);
					if (wavespawn->m_Spawner->IsMiniBoss()) {
						flags |= CLASSFLAG_MINIBOSS;
					}
					if (wavespawn->m_Spawner->HasAttribute(CTFBot::AttributeType::ALWAYSCRIT, -1)) {
						flags |= CLASSFLAG_CRITICAL;
					}
					if (wavespawn->m_bSupportLimited) {
						flags |= CLASSFLAG_SUPPORT_LIMITED;
					}
					
					this->AddClassType(wavespawn->m_Spawner->GetClassIcon(-1),
						wavespawn->m_iTotalCount, flags);
				}
			}
		} else if (V_stricmp(subkey->GetName(), "Sound") == 0) {
			this->m_strSound.sprintf("%s", subkey->GetString());
		} else if (V_stricmp(subkey->GetName(), "Description") == 0) {
			this->m_strDescription.sprintf("%s", subkey->GetString());
		} else if (V_stricmp(subkey->GetName(), "WaitWhenDone") == 0) {
			this->m_flWaitWhenDone = subkey->GetFloat();
		} else if (V_stricmp(subkey->GetName(), "Checkpoint") == 0) {
			/* doesn't do anything! */
		} else if (V_stricmp(subkey->GetName(), "StartWaveOutput") == 0) {
			this->m_StartWaveOutput = ParseEvent(subkey);
		} else if (V_stricmp(subkey->GetName(), "DoneOutput") == 0) {
			this->m_DoneOutput = ParseEvent(subkey);
		} else if (V_stricmp(subkey->GetName(), "InitWaveOutput") == 0) {
			this->m_InitWaveOutput = ParseEvent(subkey);
		} else {
			Warning("Unknown attribute '%s' in Wave definition.\n",
				subkey->GetName());
		}
	}
Esempio n. 3
0
bool CWaveSpawnPopulator::Parse(KeyValues *kv)
{
	/* handle the template reference (if any) before doing anything else */
	KeyValues *kv_tref = kv->FindKey("Template");
	if (kv_tref != nullptr) {
		const char *tname = kv_tref->GetString();
		
		KeyValues *kv_timpl =
			this->m_Populator->m_PopMgr->m_kvTemplates->FindKey(tname);
		if (kv_timpl != nullptr) {
			if (!this->Parse(kv_timpl)) {
				return false;
			}
		} else {
			Warning("Unknown Template '%s' in WaveSpawn definition\n",
				tname);
		}
	}
	
	FOR_EACH_SUBKEY(kv, subkey) {
		const char *name = subkey->GetName();
		if (strlen(name) <= 0) {
			continue;
		}
		
		if (this->m_Where->Parse(subkey)) {
			continue;
		}
		
		if (V_stricmp(name, "Template") == 0) {
			continue;
		}
		
		if (V_stricmp(name, "TotalCount") == 0) {
			this->m_iTotalCount = subkey->GetInt();
		} else if (V_stricmp(name, "MaxActive") == 0) {
			this->m_iMaxActive = subkey->GetInt();
		} else if (V_stricmp(name, "SpawnCount") == 0) {
			this->m_iSpawnCount = subkey->GetInt();
		} else if (V_stricmp(name, "WaitBeforeStarting") == 0) {
			this->m_flWaitBeforeStarting = subkey->GetFloat();
		} else if (V_stricmp(name, "WaitBetweenSpawns") == 0) {
			if (this->m_flWaitBetweenSpawns == 0.0f ||
				!this->m_bWaitBetweenSpawnsAfterDeath) {
				this->m_flWaitBetweenSpawns = subkey->GetFloat();
			} else {
				Warning("Already specified WaitBetweenSpawnsAfterDeath time, "
					"WaitBetweenSpawns won't be used\n");
				continue;
			}
		} else if (V_stricmp(name, "WaitBetweenSpawnsAfterDeath") == 0) {
			if (this->m_flWaitBetweenSpawns == 0.0f) {
				this->m_bWaitBetweenSpawnsAfterDeath = true;
				this->m_flWaitBetweenSpawns = subkey->GetFloat();
			} else {
				Warning("Already specified WaitBetweenSpawns time, "
					"WaitBetweenSpawnsAfterDeath won't be used\n");
				continue;
			}
		} else if (V_stricmp(name, "StartWaveWarningSound") == 0) {
			this->m_strStartWaveWarningSound.sprintf("%s",
				subkey->GetString());
		} else if (V_stricmp(name, "StartWaveOutput") == 0) {
			this->m_StartWaveOutput = ParseEvent(subkey);
		} else if (V_stricmp(name, "FirstSpawnWarningSound") == 0) {
			this->m_strFirstSpawnWarningSound.sprintf("%s",
				subkey->GetString());
		} else if (V_stricmp(name, "FirstSpawnOutput") == 0) {
			this->m_FirstSpawnOutput = ParseEvent(subkey);
		} else if (V_stricmp(name, "LastSpawnWarningSound") == 0) {
			this->m_strLastSpawnWarningSound.sprintf("%s",
				subkey->GetString());
		} else if (V_stricmp(name, "LastSpawnOutput") == 0) {
			this->m_LastSpawnOutput = ParseEvent(subkey);
		} else if (V_stricmp(name, "DoneWarningSound") == 0) {
			this->m_strDoneWarningSound.sprintf("%s",
				subkey->GetString());
		} else if (V_stricmp(name, "DoneOutput") == 0) {
			this->m_DoneOutput = ParseEvent(subkey);
		} else if (V_stricmp(name, "TotalCurrency") == 0) {
			this->m_iTotalCurrency = subkey->GetInt();
		} else if (V_stricmp(name, "Name") == 0) {
			this->m_strName = subkey->GetString();
		} else if (V_stricmp(name, "WaitForAllSpawned") == 0) {
			this->m_strWaitForAllSpawned = subkey->GetString();
		} else if (V_stricmp(name, "WaitForAllDead") == 0) {
			this->m_strWaitForAllDead = subkey->GetString();
		} else if (V_stricmp(name, "Support") == 0) {
			this->m_bSupport = true;
			this->m_bSupportLimited =
				(V_stricmp(subkey->GetString(), "Limited") == 0);
		} else if (V_stricmp(name, "RandomSpawn") == 0) {
			this->m_bRandomSpawn = subkey->GetBool();
		} else {
			/* BUG: duplicate spawner definitions will leak memory */
			this->m_Spawner = IPopulationSpawner::ParseSpawner(this, subkey);
			if (this->m_Spawner == nullptr) {
				Warning("Unknown attribute '%s' in WaveSpawn definition.\n",
					name);
			}
		}
		
		this->m_iCountNotYetSpawned = this->m_iTotalCount;
		this->m_iCurrencyLeft = this->m_iTotalCurrency;
	}
	
	return true;
}
shared_ptr<osb::SpriteList> ReadOSBEvents(std::istream& event_str)
{
	auto list = make_shared<osb::SpriteList>();
	int previous_lead = 100;
	shared_ptr<osb::BGASprite> sprite = nullptr;
	shared_ptr<osb::Loop> loop = nullptr;
	bool readingLoop = false;

	GString line;
	while (std::getline(event_str, line))
	{
		int lead_spaces;
		line = line.substr(line.find("//")); // strip comments
		lead_spaces = line.find_first_not_of("\t _");
		line = line.substr(lead_spaces, line.length() - lead_spaces + 1);

		vector<GString> split_result;
		boost::split(split_result, line, boost::is_any_of(","));
		for (auto &&s : split_result) boost::algorithm::to_lower(s);

		if (!line.length() || !split_result.size()) continue;

		if (lead_spaces < previous_lead && !readingLoop)
		{
			if (split_result[0] == "sprite")
			{
				Vec2 new_position(latof(split_result[3]), latof(split_result[4]));
				sprite = make_shared<osb::BGASprite>(split_result[1], OriginFromString(split_result[2]), new_position);
				list->push_back(sprite);
			}
		} else {
			if (!sprite)
				throw std::runtime_error("OSB command unpaired with sprite.");

			// If it's a loop, check if we're out of it.
			// If we're out of it, read a regular event, otherwise, read an event to the loop
			if (readingLoop)
			{
				if (lead_spaces < previous_lead) {
					readingLoop = false;

					// We're done reading the loop - unroll it.
					auto loop_events = loop->Unroll();
					for (auto i = 0; i < osb::EVT_COUNT; i++)
						for (auto evt : (*loop_events)[i])
							sprite->AddEvent(evt);
				}
				else
					loop->AddEvent(ParseEvent(split_result));
			}
			
			// It's not a command on the loop, or we weren't reading a loop in the first place.
			// Read a regular command.

			// Not "else" because we do want to execute this if we're no longer reading the loop.
			if (!readingLoop) {
				auto ev = ParseEvent(split_result);

				// A loop began - set that we are reading a loop and set this loop as where to add the following commands.
				if (ev->GetEventType() == osb::EVT_LOOP)
				{
					loop = static_pointer_cast<osb::Loop>(ev);
					readingLoop = true;
				}else // add this event, if not a loop to this sprite. It'll be unrolled once outside.
					sprite->AddEvent(ev);
			}
		}

		previous_lead = lead_spaces;
	}

	return list;
}
Esempio n. 5
0
void CEventInfo::ParseEvents(CMarkup & xml)
{
	// Jump into elem
	xml.IntoElem();

	// Search for OnNewVersion event
	if (xml.FindElem(_T("ONNEWVERSION")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_ONNEWVERSION]);
	}

	// Reset pos
	xml.ResetMainPos();

	// Search for OnNoNewVersion event
	if (xml.FindElem(_T("ONNONEWVERSION")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_ONNONEWVERSION]);
	}

	// Reset pos
	xml.ResetMainPos();

	// Search for BeforeHtmlMessage event
	if (xml.FindElem(_T("BEFOREHTMLMESSAGE")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_BEFOREHTMLMESSAGE]);
	}
	
	// Reset pos
	xml.ResetMainPos();

	// Search for AfterHtmlMessage event
	if (xml.FindElem(_T("AFTERHTMLMESSAGE")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_AFTERHTMLMESSAGE]);
	}

	// Reset pos
	xml.ResetMainPos();

	// Search for BeforeLicense event
	if (xml.FindElem(_T("BEFORELICENSE")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_BEFORELICENSE]);
	}
	
	// Reset pos
	xml.ResetMainPos();

	// Search for AfterLicense event
	if (xml.FindElem(_T("AFTERLICENSE")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_AFTERLICENSE]);
	}

	// Reset pos
	xml.ResetMainPos();

	// Search for BeforeSelectUpdate event
	if (xml.FindElem(_T("BEFORESELECTUPDATE")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_BEFORESELECTUPDATE]);
	}
	
	// Reset pos
	xml.ResetMainPos();

	// Search for AfterSelectUpdate event
	if (xml.FindElem(_T("AFTERSELECTUPDATE")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_AFTERSELECTUPDATE]);
	}

	// Reset pos
	xml.ResetMainPos();

	// Search for BeforeDownload event
	if (xml.FindElem(_T("BEFOREDOWNLOAD")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_BEFOREDOWNLOAD]);
	}
	
	// Reset pos
	xml.ResetMainPos();

	// Search for AfterDownload event
	if (xml.FindElem(_T("AFTERDOWNLOAD")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_AFTERDOWNLOAD]);
	}

	// Reset pos
	xml.ResetMainPos();

	// Search for BeforeInstall event
	if (xml.FindElem(_T("BEFOREINSTALL")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_BEFOREINSTALL]);
	}

	// Reset pos
	xml.ResetMainPos();

	// Search for AfterInstall event
	if (xml.FindElem(_T("AFTERINSTALL")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_AFTERINSTALL]);
	}
	
	// Reset pos
	xml.ResetMainPos();
	
	// Search for BeforeInstall event
	if (xml.FindElem(_T("BEFOREROLLBACK")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_BEFOREROLLBACK]);
	}
	
	// Reset pos
	xml.ResetMainPos();
	
	// Search for AfterInstall event
	if (xml.FindElem(_T("AFTERROLLBACK")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_AFTERROLLBACK]);
	}

	// Reset pos
	xml.ResetMainPos();

	// Search for OnClose event
	if (xml.FindElem(_T("ONCLOSE")))
	{
		// Parse event
		ParseEvent(xml, m_arrEvents[EVENT_ONCLOSE]);
	}

	// Jump out of elem
	xml.OutOfElem();
}
void MMatchEventFactoryManager::ParseLocale( MXmlElement& chrElement )
{
	EventData ed;
	char szAttrName[ 128 ];
	char szAttrValue[ 256 ];
	const int nAttrCnt = chrElement.GetAttributeCount();
	for( int i = 0; i < nAttrCnt; ++i )
	{
		chrElement.GetAttribute( i, szAttrName, szAttrValue );
		
		if( 0 == stricmp(EL_COUNTRY, szAttrName) )
		{
			/*  // MBaseLocale.h // 
			enum MCountry
			{
				MC_KOREA			= 82,		// 한국
				MC_US				= 1,		// 미국(인터네셔날)
				MC_JAPAN			= 81,		// 일본
			};
			*/

			string strCountry;
			switch( MGetLocale()->GetCountry() )
			{
			case MC_KOREA :
				{
					strCountry = "kor";
				}
				break;

			case MC_US :
				{
					strCountry = "us";
				}
				break;

			case MC_JAPAN :
				{
					strCountry = "jpn";
				}
				break;

			case MC_BRAZIL :
				{
					strCountry = "brz";
				}
				break;

			case MC_INDIA :
				{
					strCountry = "ind";
				}
				break;

			default :
				{
					ASSERT( 0 );
				}
				break;
			}

			// 현제 서버랑 같은 국가 타입만 파싱함. 
            // if( 0 == stricmp(strCountry.c_str(), szAttrValue) )
			// 국가코드 구분 안함. 이미 국가별로 나눠줘 있음.
			if( true )
			{
				MXmlElement chrNode;
				char szTag[ 128 ];
				const int nChrCnt = chrElement.GetChildNodeCount();
				for( int j = 0; j < nChrCnt; ++j )
				{
					chrNode = chrElement.GetChildNode( j );
					chrNode.GetTagName( szTag );

					if( 0 == stricmp(EL_EVENT, szTag) )
					{
						ParseEvent( chrNode );
					}
				}
			}
		}
	}
}