Exemplo n.º 1
0
void AMainCharacter::OnCollision(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	AWeapon* CollidedWeapon = Cast<AWeapon>(OtherActor);
	if (CollidedWeapon)
	{
		if (CollidedWeapon->Config.Name == TEXT("Glock") && Inventory[0] == NULL)
		{
			Inventory[0] = CollidedWeapon->GetClass();
			CollidedWeapon->Destroy();
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "Weapon picked up: " + CollidedWeapon->Config.Name);
		}
		if (CollidedWeapon->Config.Name == TEXT("M4A1") && Inventory[1] == NULL)
		{
			Inventory[1] = CollidedWeapon->GetClass();
			CollidedWeapon->Destroy();
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "Weapon picked up: " + CollidedWeapon->Config.Name);
		}
		if (CollidedWeapon->Config.Name == TEXT("Shotgun") && Inventory[2] == NULL)
		{
			Inventory[2] = CollidedWeapon->GetClass();
			CollidedWeapon->Destroy();
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "Weapon picked up: " + CollidedWeapon->Config.Name);
		}
	}
}
Exemplo n.º 2
0
static bool FindMostRecentWeapon(player_t *player, int *slot, int *index)
{
	if (player->PendingWeapon != WP_NOCHANGE)
	{
		return player->weapons.LocateWeapon(player->PendingWeapon->GetClass(), slot, index);
	}
	else if (player->ReadyWeapon != NULL)
	{
		AWeapon *weap = player->ReadyWeapon;
		if (!player->weapons.LocateWeapon(weap->GetClass(), slot, index))
		{
			// If the current weapon wasn't found and is powered up,
			// look for its non-powered up version.
			if (weap->WeaponFlags & WIF_POWERED_UP && weap->SisterWeaponType != NULL)
			{
				return player->weapons.LocateWeapon(weap->SisterWeaponType, slot, index);
			}
			return false;
		}
		return true;
	}
	else
	{
		return false;
	}
}
Exemplo n.º 3
0
static bool DoSubstitution (FString &out, const char *in)
{
	player_t *player = &players[consoleplayer];
	AWeapon *weapon = player->ReadyWeapon;
	const char *a, *b;

	a = in;
	out = "";
	while ( (b = strchr(a, '$')) )
	{
		out.AppendCStrPart(a, b - a);

		a = ++b;
		while (*b && isalpha(*b))
		{
			++b;
		}

		ptrdiff_t len = b - a;

		if (len == 6)
		{
			if (strnicmp(a, "health", 6) == 0)
			{
				out.AppendFormat("%d", player->health);
			}
			else if (strnicmp(a, "weapon", 6) == 0)
			{
				if (weapon == NULL)
				{
					out += "no weapon";
				}
				else
				{
					out += weapon->GetClass()->TypeName;
				}
			}
		}
		else if (len == 5)
		{
			if (strnicmp(a, "armor", 5) == 0)
			{
				AInventory *armor = player->mo->FindInventory<ABasicArmor>();
				out.AppendFormat("%d", armor != NULL ? armor->Amount : 0);
			}
		}
		else if (len == 9)
		{
			if (strnicmp(a, "ammocount", 9) == 0)
			{
				if (weapon == NULL)
				{
					out += '0';
				}
				else
				{
					out.AppendFormat("%d", weapon->Ammo1 != NULL ? weapon->Ammo1->Amount : 0);
					if (weapon->Ammo2 != NULL)
					{
						out.AppendFormat("/%d", weapon->Ammo2->Amount);
					}
				}
			}
		}
		else if (len == 4)
		{
			if (strnicmp(a, "ammo", 4) == 0)
			{
				if (weapon == NULL || weapon->Ammo1 == NULL)
				{
					out += "no ammo";
				}
				else
				{
					out.AppendFormat("%s", weapon->Ammo1->GetClass()->TypeName.GetChars());
					if (weapon->Ammo2 != NULL)
					{
						out.AppendFormat("/%s", weapon->Ammo2->GetClass()->TypeName.GetChars());
					}
				}
			}
		}
		else if (len == 0)
		{
			out += '$';
			if (*b == '$')
			{
				b++;
			}
		}
		else
		{
			out += '$';
			out.AppendCStrPart(a, len);
		}
		a = b;
	}

	// Return false if no substitution was performed
	if (a == in)
	{
		return false;
	}

	out += a;
	return true;
}
Exemplo n.º 4
0
//*****************************************************************************
//
// [CW]
void chat_DoSubstitution( FString &Input )
{
	player_t *pPlayer = &players[consoleplayer];
	AWeapon *pReadyWeapon = pPlayer->ReadyWeapon;

	if ( chat_substitution )
	{
		FString Output;
		const char *pszString = Input.GetChars( );

		for ( ; *pszString != 0; pszString++ )
		{
			if ( !strncmp( pszString, "$ammocount", 10 ))
			{
				if ( pReadyWeapon && pReadyWeapon->Ammo1 )
				{
					Output.AppendFormat( "%d", pReadyWeapon->Ammo1->Amount );

					if ( pReadyWeapon->Ammo2 )
						Output.AppendFormat( "/%d", pReadyWeapon->Ammo2->Amount );
				}
				else
				{
					Output.AppendFormat( "no ammo" );
				}

				pszString += 9;
			}
			else if ( !strncmp( pszString, "$ammo", 5 ))
			{
				if ( pReadyWeapon && pReadyWeapon->Ammo1 )
				{
					Output.AppendFormat( "%s", pReadyWeapon->Ammo1->GetClass( )->TypeName.GetChars( ) );

					if ( pReadyWeapon->Ammo2 )
					{
						Output.AppendFormat( "/%s", pReadyWeapon->Ammo2->GetClass( )->TypeName.GetChars( ));
					}
				}
				else
				{
					Output.AppendFormat( "no ammo" );
				}

				pszString += 4;
			}
			else if ( !strncmp( pszString, "$armor", 6 ))
			{
				AInventory *pArmor = pPlayer->mo->FindInventory<ABasicArmor>( );
				int iArmorCount = 0;
				
				if ( pArmor )
					iArmorCount = pArmor->Amount;

				Output.AppendFormat( "%d", iArmorCount );

				pszString += 5;
			}
			else if ( !strncmp( pszString, "$health", 7 ))
			{
				Output.AppendFormat ("%d", pPlayer->health);

				pszString += 6;
			}
			else if ( !strncmp( pszString, "$weapon", 7 ))
			{
				if ( pReadyWeapon )
					Output.AppendFormat( "%s", pReadyWeapon->GetClass( )->TypeName.GetChars( ) );
				else
					Output.AppendFormat( "no weapon" );

				pszString += 6;
			}
			else if ( !strncmp( pszString, "$location", 9 ))
			{
				Output += SECTINFO_GetPlayerLocation( consoleplayer );
				pszString += 8;
			}
			else
			{
				Output.AppendCStrPart( pszString, 1 );
			}
		}

		Input = Output;
	}
}
Exemplo n.º 5
0
static bool DoSubstitution (char *out, const char *in)
{
	player_t *player = &players[consoleplayer];
	AWeapon *weapon = player->ReadyWeapon;
	const char *a, *b;

	a = in;
	while ((b = strchr (a, '$')))
	{
		strncpy (out, a, b - a);
		out += b - a;

		a = ++b;
		while (*b && isalpha (*b))
		{
			++b;
		}

		ptrdiff_t len = b - a;

		if (len == 6)
		{
			if (strnicmp (a, "health", 6) == 0)
			{
				out += sprintf (out, "%d", player->health);
			}
			else if (strnicmp (a, "weapon", 6) == 0)
			{
				if (weapon == NULL)
				{
					out += sprintf (out, "no weapon");
				}
				else
				{
					out += sprintf (out, "%s", weapon->GetClass()->Name+1);
				}
			}
		}
		else if (len == 5)
		{
			if (strnicmp (a, "armor", 5) == 0)
			{
				AInventory *armor = player->mo->FindInventory<ABasicArmor>();
				int armorpoints = armor != NULL ? armor->Amount : 0;
				out += sprintf (out, "%d", armorpoints);
			}
		}
		else if (len == 9)
		{
			if (strnicmp (a, "ammocount", 9) == 0)
			{
				if (weapon == NULL)
				{
					out += sprintf (out, "0");
				}
				else
				{
					out += sprintf (out, "%d", weapon->Ammo1 != NULL ? weapon->Ammo1->Amount : 0);
					if (weapon->Ammo2 != NULL)
					{
						out += sprintf (out, "/%d", weapon->Ammo2->Amount);
					}
				}
			}
		}
		else if (len == 4)
		{
			if (strnicmp (a, "ammo", 4) == 0)
			{
				if (weapon == NULL || weapon->Ammo1 == NULL)
				{
					out += sprintf (out, "no ammo");
				}
				else
				{
					out += sprintf (out, "%s", weapon->Ammo1->GetClass()->Name+1);
					if (weapon->Ammo2 != NULL)
					{
						out += sprintf (out, "/%s", weapon->Ammo2->GetClass()->Name+1);
					}
				}
			}
		}
		else if (len == 0)
		{
			*out++ = '$';
			*out = 0;
			if (*b == '$')
			{
				b++;
			}
		}
		else
		{
			*out++ = '$';
			strncpy (out, a, len);
			out += len;
		}
		a = b;
	}

	// Return false if no substitution was performed
	if (a == in)
	{
		return false;
	}

	strcpy (out, a);
	return true;
}