Пример #1
0
void * Damage::Decode(Collision * pCollision, ActionParameter * pActionParameter, Board * pBoard)
{
	// All types that end up calling this have a A_STRENGTH attribute.
	void * result = pCollision->GetReceiver()->GetAttributes()->LookupValue(A_STRENGTH);

	if (result != NULL)
	{
		int nStrength = INT(result);

		if (nStrength > 0)
		{
			int nVerb = GetVerb();

			int nSubject1 = GetSubject1();
			int nAttribute1 = GetAttribute1();

			int nSubject2 = GetSubject2();
			int nAttribute2 = GetAttribute2();

#if defined(_DEBUG) || defined(_RELEASE_DEBUG)
			char buffer[64];
			sprintf_s(
				buffer, 
				"Damage: %d %d %d %d\n",
				nSubject1,
				nAttribute1,
				nSubject2,
				nAttribute2);
			OutputDebugStringA(buffer);
#endif // #if defined(_DEBUG) || defined(_RELEASE_DEBUG)

			if (nSubject1 == P_SENDER)
			{
				if (nSubject2 == P_SENDER)
				{
					// "Change a Sender's attribute by a Sender's attribute"
					pCollision->GetSender()->DoDamage(
						pCollision->GetReceiver(),
						// "Change"
						nVerb,
						// "the Sender's attribute"
						nAttribute1,	
						// "By the Sender's attribute"
						INT(pCollision->GetSender()->GetAttributes()->LookupValue(nAttribute2)),	
						NULL,
						pActionParameter);
				}
				else if (nSubject2 == P_RECEIVER)
				{
					// "Change a Sender's attribute by a Receiver's attribute"
					pCollision->GetSender()->DoDamage(
						pCollision->GetReceiver(),
						nVerb,
						nAttribute1,
						INT(pCollision->GetReceiver()->GetAttributes()->LookupValue(nAttribute2)),
						NULL,
						pActionParameter);
				}

			}
			else if (nSubject1 == P_RECEIVER)
			{
				if (nSubject2 == P_SENDER)
				{
					// "Change a Receiver's attribute by a Sender's attribute" (MOST likely)

					// Rule 6: Decrease the Receiver's strength value by 
					//	the Sender's strength value.
					pCollision->GetReceiver()->DoDamage(
						pCollision->GetSender(),
						nVerb,
						nAttribute1,
						INT(pCollision->GetSender()->GetAttributes()->LookupValue(nAttribute2)),
						NULL,
						pActionParameter);
				}
				else if (nSubject2 == P_RECEIVER)
				{
					// "Change a Receiver's attribute by a Receiver's attribute."
					pCollision->GetReceiver()->DoDamage(
						pCollision->GetSender(),
						nVerb,
						nAttribute1,
						INT(pCollision->GetReceiver()->GetAttributes()->LookupValue(nAttribute2)),
						NULL,
						pActionParameter);
				}
			}
		}
	}

	return NULL;
}
Пример #2
0
std::string en::createSentence()
{
	//First of all, parse the ExtVerb files
	if(ExtVerb1!=0){
		ParseVerb(0,ExtVerb1);
		ExtVerb1=0;
	}
	if (ExtVerb2!=0){
		ParseVerb(1,ExtVerb2);
		ExtVerb2=0;
	}

	//Create blank sentence
	std::string Sentence = "";

	if (Question > 1)
	{
		Sentence += QuestionMarkers[Question-2] + " ";
	}

	//Store the subjects in a different string
	std::string SubjectString = "";

	//Loop through the subjects, adding them
	for (int i = 0; i <= NumFilledSubjects; ++i)
	{
		if (i!=0 && i < NumFilledSubjects) SubjectString +=", ";
		if (i==NumFilledSubjects && NumFilledSubjects > 0) SubjectString += " and ";
		SubjectString +=	GetNounString(&Subjects[i],false);
	}

	
	std::string Mid = "";
	
	if (Question>=1)
	{
		Mid = SubjectString;
	}
	else
	{
		Sentence += SubjectString;
		//If there is a subject, insert a space beteen the subjects and the verb.
		if (NumFilledSubjects >= 0) Sentence += " ";
	}


	//Add the first verb to the sentence, if it exists
	if (Verb1 != 0)
		Sentence += GetVerb(Subjects[0],NumFilledSubjects,Verb1,st,Mid) + " ";

	//Add the second verb to the sentenc, if it exists
	if (Verb2 != 0)
		Sentence += GetOtherVerb(Verb1,Verb2) + " ";

	//Loop through the objects, adding them to the sentence
	for (int objid = 0; objid < 8; ++objid)
	{
		for (int i = 0; i <= NumFilledObjects[objid]; ++i)
		{
			if (i != 0 && i < NumFilledObjects[objid]) Sentence += ", ";
			if (NumFilledObjects[objid] > 0 && i == NumFilledObjects[objid]) Sentence += " and ";
			Sentence += GetNounString(&Objects[objid][i],true);
		}
		if (NumFilledObjects[objid]>=0) Sentence += " ";
	}

	//If a conjunction and subclause exists, create the subclause, and add it to the sentence.
	if (SubClause && Conjunction != 0)
	{
		Sentence += GetSubClause() + " ";
	}

	if(Sentence.compare("")!=0)
		Sentence.pop_back();
	if (Punctuation && !IsClause)
	{
		if (Question==0)
			Sentence+=".";
		else
			Sentence+="?";
	}

	if (Capital && !IsClause)
	{
		int FirstLetter = Sentence.at(0);
		if (FirstLetter >= 'a' && FirstLetter <= 'z')
		{
			FirstLetter -= ('a' - 'A');
			Sentence[0] = FirstLetter;
		}
	}	
		
	return Sentence;
}
Пример #3
0
bool FHttpRequestWinInet::StartRequest()
{
	// Make sure old handles are not being reused
	CleanupRequest();

	UE_LOG(LogHttp, Log, TEXT("Start request. %p %s url=%s"), this, *GetVerb(), *GetURL());
	for (TMap<FString, FString>::TConstIterator It(RequestHeaders); It; ++It)
	{
		UE_LOG(LogHttp, Log, TEXT("%p Header %s : %s"), this, *It.Key(), *It.Value());
	}

	if (FWinInetConnection::Get().IsConnectionValid())
	{
		// Open an internet connection to the URL endpoint
		ConnectionHandle = InternetConnect(
			FWinInetConnection::Get().InternetHandle, 
			*RequestURL.GetHost(), 
			RequestURL.GetPort(), 
			NULL, 
			NULL, 
			INTERNET_SERVICE_HTTP, 
			0, 
			(DWORD_PTR)this);
	}	
	if (ConnectionHandle == NULL)
	{
		UE_LOG(LogHttp, Warning, TEXT("InternetConnect failed: %s"), *InternetTranslateError(GetLastError()));
		return false;
	}

	// Disable IE offline mode
	::BOOL bEnabled = true;
	InternetSetOption(ConnectionHandle, INTERNET_OPTION_IGNORE_OFFLINE, &bEnabled, sizeof(::BOOL));

	// Set connection timeout in ms
	if (FHttpModule::Get().GetHttpConnectionTimeout() >= 0)
	{
		uint32 HttpConnectionTimeout =  FHttpModule::Get().GetHttpConnectionTimeout() == 0 ? 0xFFFFFFFF : FHttpModule::Get().GetHttpConnectionTimeout() * 1000;
		InternetSetOption(ConnectionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, (::LPVOID)&HttpConnectionTimeout, sizeof(::DWORD));
	}
	// Set receive timeout in ms
	if (FHttpModule::Get().GetHttpReceiveTimeout() >= 0)
	{
		uint32 HttpReceiveTimeout = FHttpModule::Get().GetHttpReceiveTimeout() * 1000;
		InternetSetOption(ConnectionHandle, INTERNET_OPTION_RECEIVE_TIMEOUT, (::LPVOID)&HttpReceiveTimeout, sizeof(::DWORD));
	}
	// Set send timeout in ms
	if (FHttpModule::Get().GetHttpSendTimeout() >= 0)
	{
		uint32 HttpSendTimeout = FHttpModule::Get().GetHttpSendTimeout() * 1000;
		InternetSetOption(ConnectionHandle, INTERNET_OPTION_SEND_TIMEOUT, (::LPVOID)&HttpSendTimeout, sizeof(::DWORD));
	}

	// Query these options to verify
	{
		::DWORD OptionSize = sizeof(::DWORD);
		::DWORD OptionData = 0;
		InternetQueryOption(ConnectionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, (::LPVOID)&OptionData, (::LPDWORD)&OptionSize);
		UE_LOG(LogHttp, VeryVerbose, TEXT("INTERNET_OPTION_CONNECT_TIMEOUT: %d"), OptionData);
		InternetQueryOption(ConnectionHandle, INTERNET_OPTION_RECEIVE_TIMEOUT, (::LPVOID)&OptionData, (::LPDWORD)&OptionSize);
		UE_LOG(LogHttp, VeryVerbose, TEXT("INTERNET_OPTION_RECEIVE_TIMEOUT: %d"), OptionData);
		InternetQueryOption(ConnectionHandle, INTERNET_OPTION_SEND_TIMEOUT, (::LPVOID)&OptionData, (::LPDWORD)&OptionSize);
		UE_LOG(LogHttp, VeryVerbose, TEXT("INTERNET_OPTION_SEND_TIMEOUT: %d"), OptionData);
	}

	// Only custom request flag is for SSL/HTTPS requests
	uint32 RequestFlags = RequestURL.GetURLComponents().nScheme == INTERNET_SCHEME_HTTPS ? INTERNET_FLAG_SECURE : 0;
	// Always download from server instead of cache
	// Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy. 
	RequestFlags |= INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE;
	// Keep the connection open
	RequestFlags |= INTERNET_FLAG_KEEP_CONNECTION;
	// Build full path
	FString PathAndExtra(RequestURL.GetPath() + RequestURL.GetExtraInfo());
	// Create the request
	RequestHandle = HttpOpenRequest(
		ConnectionHandle, 
		RequestVerb.IsEmpty() ? NULL : *RequestVerb, 
		*PathAndExtra, 
		NULL, 
		NULL, 
		NULL, 
		RequestFlags, 
		(DWORD_PTR)this);

	if (RequestHandle == NULL)
	{
		UE_LOG(LogHttp, Warning, TEXT("HttpOpenRequest failed: %s"), *InternetTranslateError(GetLastError()));
		return false;
	}

	// Disable certificate checks
	::DWORD SecurityFlags = SECURITY_FLAG_IGNORE_REVOCATION;
	if (!InternetSetOption(RequestHandle, INTERNET_OPTION_SECURITY_FLAGS, (LPVOID)&SecurityFlags, sizeof(::DWORD)))
	{
		UE_LOG(LogHttp, Warning, TEXT("InternetSetOption failed: %s"), *InternetTranslateError(GetLastError()));
	}

	// Send the request with the payload if any
	FString Headers = GenerateHeaderBuffer(RequestPayload.Num());
	BOOL bSentRequest = HttpSendRequest(
		RequestHandle, 
		*Headers, 
		Headers.Len(), 
		RequestPayload.Num() > 0 ? RequestPayload.GetTypedData() : NULL,
		RequestPayload.Num());

	if (!bSentRequest &&
		GetLastError() != ERROR_IO_PENDING)
	{
		UE_LOG(LogHttp, Warning, TEXT("HttpSendRequest failed: %s"), *InternetTranslateError(GetLastError()));
		return false;
	}

	// Successfully started the request
	return true;
}