Esempio n. 1
0
int ThrowWeapon(gentity_t * ent, qboolean forceThrow)
{
	gclient_t *client;
	usercmd_t *ucmd;
	gitem_t *xr_item;
	gentity_t *xr_drop;
	int weap;

	client = ent->client;
	ucmd = &ent->client->pers.cmd;

	if (!forceThrow)
		if ((ucmd->buttons & BUTTON_ATTACK) || client->ps.weaponTime > 0)
			return 0;

	//Elder: remove zoom bits
	Cmd_Unzoom(ent);

// JBravo: simulate AQ drop weapon for akimbo with no special weap
	if (client->ps.weapon == WP_AKIMBO && client->uniqueWeapons == 0) {
		trap_SendServerCommand(ent - g_entities, va("stuff weapon %i\n", WP_PISTOL));
		return 0;
	}

	weap = 0;
	if (client->uniqueWeapons > 0) {
		if (client->ps.weapon == WP_AKIMBO || client->ps.weapon == WP_PISTOL || client->ps.weapon == WP_GRENADE || client->ps.weapon == WP_KNIFE || client->ps.weapon == WP_NONE)	// shouldn't have to worry about NONE, but just in case
		{
			weap = client->ps.stats[STAT_WEAPONS];
			if ((client->ps.stats[STAT_WEAPONS] & (1 << WP_M4)) == (1 << WP_M4))
				weap = WP_M4;
			if ((client->ps.stats[STAT_WEAPONS] & (1 << WP_M3)) == (1 << WP_M3))
				weap = WP_M3;
			if ((client->ps.stats[STAT_WEAPONS] & (1 << WP_MP5)) == (1 << WP_MP5))
				weap = WP_MP5;
			if ((client->ps.stats[STAT_WEAPONS] & (1 << WP_HANDCANNON)) == (1 << WP_HANDCANNON))
				weap = WP_HANDCANNON;
			if ((client->ps.stats[STAT_WEAPONS] & (1 << WP_SSG3000)) == (1 << WP_SSG3000))
				weap = WP_SSG3000;
			if (weap == 0)
				return 0;
		} else {
			weap = client->ps.weapon;
		}

		xr_item = BG_FindItemForWeapon(weap);

		client->pers.hadUniqueWeapon[weap] = qtrue;

		//Elder: for immediate weapon drops
		if (client->ps.weapon == weap) {
			client->ps.stats[STAT_RQ3] |= RQ3_THROWWEAPON;
			trap_SendServerCommand(ent - g_entities, va("rq3_cmd %i", SELECTPISTOL));
		}

		client->weaponCount[weap]--;
		if (client->weaponCount[weap] == 0)
			client->ps.stats[STAT_WEAPONS] &= ~(1 << weap);

		xr_drop = dropWeapon(ent, xr_item, 0, FL_DROPPED_ITEM | FL_THROWN_ITEM);
		xr_drop->count = -1;	// XRAY FMJ 0 is already taken, -1 means no ammo
		// remember who dropped you, child!
		xr_drop->s.otherEntityNum = client->ps.clientNum;
		client->uniqueWeapons--;
	}

	return weap;
}
Esempio n. 2
0
void ThrowItem(gentity_t * ent)
{
	gclient_t *client;
	gitem_t *xr_item;
	gentity_t *xr_drop;
//	int item;

	client = ent->client;

	//itemonTime > 0 or itemonState == itemon_dropping?  Or both?
	//item = 0;

	// JBravo: New drop item code for multiple items.
	if (client->uniqueItems > 0) {
		if (g_gametype.integer >= GT_TEAM) {
			if (client->ps.stats[STAT_HOLDABLE_ITEM] & (1 << client->teamplayItem)) {
				xr_item = BG_FindItemForHoldable(client->teamplayItem);
				xr_drop = dropWeapon(ent, xr_item, 0, FL_DROPPED_ITEM | FL_THROWN_ITEM);
				xr_drop->count = -1;
				client->ps.stats[STAT_HOLDABLE_ITEM] &= ~(1 << client->teamplayItem);
				client->uniqueItems--;
				return;
			}
		}
		if (client->ps.stats[STAT_HOLDABLE_ITEM] & (1 << HI_BANDOLIER)) {
			xr_item = BG_FindItemForHoldable(HI_BANDOLIER);
			xr_drop = dropWeapon(ent, xr_item, 0, FL_DROPPED_ITEM | FL_THROWN_ITEM);
			xr_drop->count = -1;
			client->ps.stats[STAT_HOLDABLE_ITEM] &= ~(1 << HI_BANDOLIER);
			client->uniqueItems--;
			return;
		} else if (client->ps.stats[STAT_HOLDABLE_ITEM] & (1 << HI_SLIPPERS)) {
			xr_item = BG_FindItemForHoldable(HI_SLIPPERS);
			xr_drop = dropWeapon(ent, xr_item, 0, FL_DROPPED_ITEM | FL_THROWN_ITEM);
			xr_drop->count = -1;
			client->ps.stats[STAT_HOLDABLE_ITEM] &= ~(1 << HI_SLIPPERS);
			client->uniqueItems--;
			return;
		} else if (client->ps.stats[STAT_HOLDABLE_ITEM] & (1 << HI_SILENCER)) {
			xr_item = BG_FindItemForHoldable(HI_SILENCER);
			xr_drop = dropWeapon(ent, xr_item, 0, FL_DROPPED_ITEM | FL_THROWN_ITEM);
			xr_drop->count = -1;
			client->ps.stats[STAT_HOLDABLE_ITEM] &= ~(1 << HI_SILENCER);
			client->uniqueItems--;
			return;
		// JBravo: adding the helmet :)
		} else if (client->ps.stats[STAT_HOLDABLE_ITEM] & (1 << HI_HELMET)) {
			xr_item = BG_FindItemForHoldable(HI_HELMET);
			xr_drop = dropWeapon(ent, xr_item, 0, FL_DROPPED_ITEM | FL_THROWN_ITEM);
			xr_drop->count = -1;
			client->ps.stats[STAT_HOLDABLE_ITEM] &= ~(1 << HI_HELMET);
			client->uniqueItems--;
			return;
		} else if (client->ps.stats[STAT_HOLDABLE_ITEM] & (1 << HI_LASER)) {
			xr_item = BG_FindItemForHoldable(HI_LASER);
			xr_drop = dropWeapon(ent, xr_item, 0, FL_DROPPED_ITEM | FL_THROWN_ITEM);
			xr_drop->count = -1;
			client->ps.stats[STAT_HOLDABLE_ITEM] &= ~(1 << HI_LASER);
			client->uniqueItems--;
			return;
		} else if (client->ps.stats[STAT_HOLDABLE_ITEM] & (1 << HI_KEVLAR)) {
			xr_item = BG_FindItemForHoldable(HI_KEVLAR);
			xr_drop = dropWeapon(ent, xr_item, 0, FL_DROPPED_ITEM | FL_THROWN_ITEM);
			xr_drop->count = -1;
			client->ps.stats[STAT_HOLDABLE_ITEM] &= ~(1 << HI_KEVLAR);
			client->uniqueItems--;
			return;
		}
	}
}
Esempio n. 3
0
void Player::update(float dt)
{
	if(mStunnedCounter > 0.0f)
		mStunnedCounter -= dt;
	else
		mStunned = false;

	// Update the animation
	mAnimation->animate(dt);

	// Update the head rotation
	updateHead();

	// Update the weapon
	if(mWeapon != NULL)	{
		mWeapon->updatePosition(getPosition());
		mWeapon->incrementCooldownCounter(dt);
	}

	/* Update the velocity */

	// Strafing sideways
	if(gDInput->keyDown(DIK_A) && !mStunned && getVelocity().x > -mMaxVelocity)	{	// Left
		getBody()->ApplyForce(Vector(-mAcceleration, 0), getPosition());
		setFacingDirection(LEFT);

		if(mWeapon != NULL)
			mWeapon->setFlipped(true);

		// If the player is on the ground, continue the animation
		if(!mInAir)	
			mAnimation->resume();
	}
	else if(gDInput->keyDown(DIK_D) && !mStunned && getVelocity().x < mMaxVelocity)	{	// Right
		getBody()->ApplyForce(Vector(mAcceleration, 0), getPosition());
		setFacingDirection(RIGHT);

		if(mWeapon != NULL)
			mWeapon->setFlipped(false);

		// If the player is on the ground, continue the animation
		if(!mInAir)	
			mAnimation->resume();
	}
	
	// If A or D is released set the frame to 0 if the player not is in the air
	if(gDInput->keyReleased(DIK_A) || gDInput->keyReleased(DIK_D))	{
		mAnimation->pause();

		if(!mInAir)
			mAnimation->setFrame(0);
	}

	// Jump if the player is on the ground
	if(gDInput->keyDown(DIK_SPACE) && !mInAir)	{
		setVelocity(getVelocity() + Vector(0, -500));
		getBody()->Move(0, -1);		// Move it out of collision (:HACK:)
		mAnimation->setFrame(7);	// Set the jumping frame
		mAnimation->pause();		// Pause the animation
		mInAir = true;				// The player is now in the air
	}

	// Shooting with the left mouse button
	if(gDInput->mouseButtonDown(0))	{
		if(mWeapon != NULL)	{
			if(mWeapon->isReady())	{
				mWeapon->attack();
				mWeapon->setCooldownCounter(0.0f);
				mWeapon->setAttacking(true);
			}
		}
	}

	// Drop the equipped weapon if the drop button was pressed
	if(gDInput->keyPressed(DIK_G))
		dropWeapon();

	// Loot
	if(gDInput->keyPressed(DIK_E))
		checkLoot();
}