void ribi::xnz::SpriteMissile::Move()
{
  ChangeX(mDx);
  ChangeY(mDy);
  const int x = GetX();
  const int y = GetY();
  if ( x < mMinx || x > mMaxx || y < mMiny || y > mMaxy)
  {
    ChangeHealth( -GetHealth() - 1 );
  }
}
//moves the player down and changes his stamina
void Player::MoveDown()
{
	if (Stamina > 0)
	{
		ChangeStamina(-1);
	}
	else
	{
		ChangeHealth(-2);
	}
	yLocation++;
}
//moves the player up and changes his stamina
void Player::MoveUp()
{
	if (Stamina > 0)
	{
		ChangeStamina(-1);
	}
	else
	{
		ChangeHealth(-2);
	}
	yLocation--;
}
//moves the player right and changes his stamina
void Player::MoveRight()
{
	if (Stamina > 0)
	{
		ChangeStamina(-1);
	}
	else
	{
		ChangeHealth(-2);
	}
	xLocation++;
}
//uses food to heal the player
string Player::Eat()
{
	if (Food == 0)
	{
		return "You're out of Food!";
	}
	else
	{
		Food--;
		ChangeHealth(35);
		return "Your health has been restored!";
	}
}
Beispiel #6
0
void AMech_RPGCharacter::Resurrect()
{
	FindSpawnpoint();


	SetDead(false);
	SetActorHiddenInGame(false);
	SetActorEnableCollision(true);

	FHealthChange change;
	change.heals = true;
	change.healthChange = GetMaxHealth();
	change.manipulator = this;
	change.target = this;
	ChangeHealth(change);

	ApplyCrowdControl(EffectEnums::Damage, false);
	GetWorld()->GetTimerManager().SetTimer(TimerHandle_Invunrelbility, this, &AMech_RPGCharacter::ResetInvunrelbility, 3.0F);
}
void Entity::AdvanceInWater( Unit *_unit )
{
    m_inWater += SERVER_ADVANCE_PERIOD;
    if( m_inWater > 10.0 /* && m_type != TypeInsertionSquadie */ )
    {
        ChangeHealth( -500 );
    }

    Vector3 targetPos;
    if( _unit )
    {
        targetPos = _unit->GetWayPoint();
        targetPos.y = 0.0;
        Vector3 offset = _unit->GetFormationOffset(Unit::FormationRectangle, m_id.GetIndex() );
        targetPos += offset;
    }

    if( targetPos != g_zeroVector )
    {
        Vector3 distance = targetPos - m_pos;
        distance.y = 0.0;
        m_vel = distance;
        m_vel.Normalise();
        m_front = m_vel;
        m_vel *= m_stats[StatSpeed] * 0.3;

        if (distance.Mag() < m_vel.Mag() * SERVER_ADVANCE_PERIOD)
        {                    
            m_vel = distance / SERVER_ADVANCE_PERIOD;
        }
    }

    m_vel.SetLength( 5.0 );
    m_pos += m_vel * SERVER_ADVANCE_PERIOD;
    m_pos.y = 0.0 - iv_sin(m_inWater * 3.0) - 4.0;

    double groundLevel = g_app->m_location->m_landscape.m_heightMap->GetValue(m_pos.x, m_pos.z);
    if( groundLevel > 0.0 )
    {
        m_inWater = -1;
    }
}
//restores the player's health and stamina when he sleeps in a bed
void Player::Sleep()
{
	ChangeHealth(40);
	ChangeStamina(20);
}
Beispiel #9
0
void Block::Update(DWORD)
{
	Bullet** pList = BulletDepot.GetList();

	switch (level)
	{
	case LV1 :
				{
					for (int i = 0; i < BulletManager::count; i++)
					{
						if (pList[i])
						{
							const Point pt = pList[i]->GetPosition();
							LONG BulletR = pList[i]->GetRadius();

							LONG BlockR = size * 2;

							if ((BlockR - BulletR) * (BlockR - BulletR) >= (ptCollide ^ pt) ||
								(pt.x - BLT.lt.x) * (pt.x - BLT.lt.x) + (pt.y - BLT.lt.y) * (pt.y - BLT.lt.y) <= (BulletR * BulletR) ||
								(pt.x - BRT.rt.x) * (pt.x - BRT.rt.x) + (pt.y - BRT.rt.y) * (pt.y - BRT.rt.y) <= (BulletR * BulletR) ||
								(pt.x - BLB.lb.x) * (pt.x - BLB.lb.x) + (pt.y - BLB.lb.y) * (pt.y - BLB.lb.y) <= (BulletR * BulletR) ||
								(pt.x - BRB.rb.x) * (pt.x - BRB.rb.x) + (pt.y - BRB.rb.y) * (pt.y - BRB.rb.y) <= (BulletR * BulletR))
							{
								ChangeHealth(-10);

								if (hp_current <= (hp_total/4) * 3)
									level = LV2;

								BulletDepot.pop(i);
							}
						}
					} // for (int i = 0; i < BulletManager::count; i++)
				}
				break;
	case LV2 :
				{
					for (int i = 0; i < BulletManager::count; i++)
					{
						if (pList[i])
						{
							const Point pt = pList[i]->GetPosition();
							LONG BulletR = pList[i]->GetRadius();

							if ((size + BulletR) * (size + BulletR) >= (BLT.center ^ pt) ||
								(size + BulletR) * (size + BulletR) >= (BLB.center ^ pt) ||
								(size + BulletR) * (size + BulletR) >= (BRB.center ^ pt) ||
								(pt.x - BLT.lt.x) * (pt.x - BLT.lt.x) + (pt.y - BLT.lt.y) * (pt.y - BLT.lt.y) <= (BulletR * BulletR) ||
								(pt.x - BLT.rt.x) * (pt.x - BLT.rt.x) + (pt.y - BLT.rt.y) * (pt.y - BLT.rt.y) <= (BulletR * BulletR) ||
								(pt.x - BLB.lb.x) * (pt.x - BLB.lb.x) + (pt.y - BLB.lb.y) * (pt.y - BLB.lb.y) <= (BulletR * BulletR) ||
								(pt.x - BRB.rt.x) * (pt.x - BRB.rt.x) + (pt.y - BRB.rt.y) * (pt.y - BRB.rt.y) <= (BulletR * BulletR) ||
								(pt.x - BRB.rb.x) * (pt.x - BRB.rb.x) + (pt.y - BRB.rb.y) * (pt.y - BRB.rb.y) <= (BulletR * BulletR))
							{
								ChangeHealth(-10);

								if (hp_current <= (hp_total/4) * 2)
									level = LV3;

								BulletDepot.pop(i);
							}
						}
					} // for (int i = 0; i < BulletManager::count; i++)
				}
				break;
	case LV3 :
				{
					for (int i = 0; i < BulletManager::count; i++)
					{
						if (pList[i])
						{
							const Point pt = pList[i]->GetPosition();
							LONG BulletR = pList[i]->GetRadius();

							if ((size + BulletR) * (size + BulletR) >= (BLT.center ^ pt) ||
								(size + BulletR) * (size + BulletR) >= (BRB.center ^ pt) ||
								(pt.x - BLT.lt.x) * (pt.x - BLT.lt.x) + (pt.y - BLT.lt.y) * (pt.y - BLT.lt.y) <= (BulletR * BulletR) ||
								(pt.x - BLT.rt.x) * (pt.x - BLT.rt.x) + (pt.y - BLT.rt.y) * (pt.y - BLT.rt.y) <= (BulletR * BulletR) ||
								(pt.x - BLT.lb.x) * (pt.x - BLT.lb.x) + (pt.y - BLT.lb.y) * (pt.y - BLT.lb.y) <= (BulletR * BulletR) ||
								(pt.x - BRB.rt.x) * (pt.x - BRB.rt.x) + (pt.y - BRB.rt.y) * (pt.y - BRB.rt.y) <= (BulletR * BulletR) ||
								(pt.x - BRB.lb.x) * (pt.x - BRB.lb.x) + (pt.y - BRB.lb.y) * (pt.y - BRB.lb.y) <= (BulletR * BulletR) ||
								(pt.x - BRB.rb.x) * (pt.x - BRB.rb.x) + (pt.y - BRB.rb.y) * (pt.y - BRB.rb.y) <= (BulletR * BulletR))
							{
								ChangeHealth(-10);

								if (hp_current <= (hp_total/4) * 1)
									level = LV4;

								BulletDepot.pop(i);
							}
						}
					} // for (int i = 0; i < BulletManager::count; i++)
				}
				break;
	case LV4 :
				{
					for (int i = 0; i < BulletManager::count; i++)
					{
						if (pList[i])
						{
							const Point pt = pList[i]->GetPosition();
							LONG BulletR = pList[i]->GetRadius();

							if ((size + BulletR) * (size + BulletR) >= (BLT.center ^ pt) ||
								(pt.x - BLT.lt.x) * (pt.x - BLT.lt.x) + (pt.y - BLT.lt.y) * (pt.y - BLT.lt.y) <= (BulletR * BulletR) ||
								(pt.x - BLT.rt.x) * (pt.x - BLT.rt.x) + (pt.y - BLT.rt.y) * (pt.y - BLT.rt.y) <= (BulletR * BulletR) ||
								(pt.x - BLT.lb.x) * (pt.x - BLT.lb.x) + (pt.y - BLT.lb.y) * (pt.y - BLT.lb.y) <= (BulletR * BulletR) ||
								(pt.x - BLT.rb.x) * (pt.x - BLT.rb.x) + (pt.y - BLT.rb.y) * (pt.y - BLT.rb.y) <= (BulletR * BulletR))
							{
								ChangeHealth(-10);

								if (hp_current == 0)
									level = LV0;

								BulletDepot.pop(i);
							}
						}
					} // for (int i = 0; i < BulletManager::count; i++)
				}
				break;
	case LV0 :
				break;
	default :
				break;
	}
}
Vector3 Entity::PushFromObstructions( Vector3 const &pos, bool killem )
{
    Vector3 result = pos;    
    if( m_onGround )
    {
        result.y = g_app->m_location->m_landscape.m_heightMap->GetValue( result.x, result.z );
    }

    Matrix34 transform( m_front, g_upVector, result );

    //
    // Push from Water

    if( result.y <= 1.0 )
    {        
        double pushAngle = syncsfrand(1.0);
        double distance = 0.0;
        while( distance < 50.0 )
        {
            double angle = distance * pushAngle * M_PI;
            Vector3 offset( iv_cos(angle) * distance, 0.0, iv_sin(angle) * distance );
            Vector3 newPos = result + offset;
            double height = g_app->m_location->m_landscape.m_heightMap->GetValue( newPos.x, newPos.z );
            if( height > 1.0 )
            {
                result = newPos;
                result.y = height;
                break;
            }
            distance += 1.0;
        }
    }
    

    //
    // Push from buildings

    LList<int> *buildings = g_app->m_location->m_obstructionGrid->GetBuildings( result.x, result.z );

    for( int b = 0; b < buildings->Size(); ++b )
    {
        int buildingId = buildings->GetData(b);
        Building *building = g_app->m_location->GetBuilding( buildingId );
        if( building )
        {        
            bool hit = false;
            if( m_shape && building->DoesShapeHit( m_shape, transform ) ) hit = true;
            if( (!m_shape || m_type == TypeOfficer ) && building->DoesSphereHit( result, 1.0 ) ) hit = true;
            // cheap hack, but no point overriding the entire function for this one line
            if( !hit )
            {
                Vector3 oldPos = m_pos - m_vel * SERVER_ADVANCE_PERIOD;
                if( building->DoesRayHit( oldPos, m_front, (m_pos - oldPos).Mag() ) ) hit = true;
            }

            if( hit )
            {            
                if( building->m_type == Building::TypeLaserFence && killem &&
                    ((LaserFence *) building)->IsEnabled())
                {
                    if( !g_app->m_location->IsFriend(building->m_id.GetTeamId(), m_id.GetTeamId() ) )
                    {
                        ChangeHealth( -9999 );
                        ((LaserFence *) building)->Electrocute( m_pos );
                    }
                }
                else
                {               
                    Vector3 pushForce = (building->m_pos - result);
                    pushForce.y = 0.0f;
                    pushForce.SetLength(4.0f);
                    while( building->DoesSphereHit( result, 2.0f ) )
                    {
                        result -= pushForce;   
                        //result.y = g_app->m_location->m_landscape.m_heightMap->GetValue( result.x, result.z );
                    }
                }
            }
        }
    }

    return result;
}