Пример #1
0
void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
{
	int Dir = 0;

	// The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
	switch (m_BlockFace)
	{
		case BLOCK_FACE_ZP: break;  // Initialised to zero
		case BLOCK_FACE_ZM: Dir = 2; break;
		case BLOCK_FACE_XM: Dir = 1; break;
		case BLOCK_FACE_XP: Dir = 3; break;
		default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return;
	}

	if ((Dir == 0) || (Dir == 2))  // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180
	{
		SetYaw((Dir * 90) - 180);
	}
	else
	{
		SetYaw(Dir * 90);
	}

	a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch());
	a_ClientHandle.SendEntityMetadata(*this);
}
Пример #2
0
void cPlayer::TossItems(const cItems & a_Items)
{
	m_Stats.AddValue(statItemsDropped, a_Items.Size());

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(a_Items, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}
Пример #3
0
//-----------------------------------------------------------------------------
// Purpose: Yaws the camera's forward axis toward the camera's right axis a
//			given number of degrees.
//-----------------------------------------------------------------------------
void CCamera::Yaw(float fDegrees)
{
	if (fDegrees != 0)
	{
		float fYaw = GetYaw();
		fYaw += fDegrees;
		SetYaw(fYaw);
	}
}
bool CCameraInputHelper::UpdateTargetInterpolation()
{
	if(!m_bInterpolationTargetActive || HasForceDirection())
		return false;

	//check timeout just in case
	m_fInterpolationTargetTimeout -= gEnv->pTimer->GetFrameTime();
	if(m_fInterpolationTargetTimeout < 0.0f)
	{
		m_bInterpolationTargetActive = false;
		return true;
	}

	//work in 0 .. 2pi range
	float targetYaw = m_fInterpolationTargetYaw + gf_PI;
	float curYaw = GetYaw() + gf_PI;

	//compute yaw delta
	float yawDelta = targetYaw - curYaw;
	if(yawDelta > gf_PI)
		yawDelta = -(gf_PI2 - yawDelta);
	else if(yawDelta < -gf_PI)
		yawDelta = gf_PI2 + yawDelta;

	//compute pitch delta
	float pitchDelta = m_fInterpolationTargetPitch - GetPitch();

	//termination
	float absYawDelta = fabsf(yawDelta);
	float absPitchDelta = fabsf(pitchDelta);
	if(absYawDelta < m_fInterpolationTargetMaxError && absPitchDelta < m_fInterpolationTargetMaxError)
	{
		m_bInterpolationTargetActive = false;
		return true;
	}

	//compute safe rotation speed
	float interpolationSpeed = m_fInterpolationTargetSpeed * gEnv->pTimer->GetFrameTime();
	if(absYawDelta < INTERPOLATION_SLOWDOWN_DIST && absYawDelta > INTERPOLATION_TARGET_MAX_ERROR)
		interpolationSpeed *= max(0.02f, absYawDelta / INTERPOLATION_SLOWDOWN_DIST);
	else if(absPitchDelta < INTERPOLATION_SLOWDOWN_DIST && absPitchDelta > INTERPOLATION_TARGET_MAX_ERROR)
		interpolationSpeed *= max(0.02f, absPitchDelta / INTERPOLATION_SLOWDOWN_DIST);
	//scale yaw and pitch delta
	if(absYawDelta > interpolationSpeed)
		yawDelta = ((yawDelta < 0.0f)?-1.0f:1.0f) * interpolationSpeed;
	if(absPitchDelta > interpolationSpeed)
		pitchDelta = ((pitchDelta < 0.0f)?-1.0f:1.0f) * interpolationSpeed * INTERPOLATION_PITCH_REL_SPEED;

	//set deltas
	if(absYawDelta >= INTERPOLATION_TARGET_MAX_ERROR)
		SetYawDelta(yawDelta);
	if(absPitchDelta >= INTERPOLATION_TARGET_MAX_ERROR)
		SetPitchDelta(pitchDelta);

	return true;
}
Пример #5
0
void cPlayer::TossPickup(const cItem & a_Item)
{
	cItems Drops;
	Drops.push_back(a_Item);

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}
Пример #6
0
double IMU::GetAngle()
{
    double accumulated_yaw_angle = (double)yaw_crossing_count * 360.0f;
    double curr_yaw = GetYaw();
    if ( curr_yaw < 0.0f ) {
        curr_yaw += 360.0f;
    }
    accumulated_yaw_angle += curr_yaw;
    return accumulated_yaw_angle;
}
Пример #7
0
void cPlayer::TossItems(const cItems & a_Items)
{
	if (IsGameModeSpectator())  // Players can't toss items in spectator
	{
		return;
	}
	
	m_Stats.AddValue(statItemsDropped, (StatValue)a_Items.Size());

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(a_Items, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true);  // 'true' because created by player
}
Пример #8
0
Location* Particle::getMeterLocation(){
	Location* location;
	// Convert To Meters         *10->CM  /100>Meter
	//for x 0 139	>  -6.875 6.875
	//for y 0 95	>	-4.25 4.25
	double x = GetX()/139*13.75-6.875;
	double y = 9.5-(GetY()/95*9.5-4.25);
	//Set Location To Manager
	location->setX(x);
	location->setY(y);
	location->setYaw(DTOR(GetYaw()));
	//cout << "robot location by Meters   X: " << x << " y: " << y<< " Yaw: " << best->GetYaw() << endl;
	return location;
}
Пример #9
0
	Matrix4* BMaxObject::GetRenderMatrix(Matrix4& mxWorld, int nRenderNumber /*= 0*/)
	{
		mxWorld.identity();

		// order of rotation: roll * pitch * yaw , where roll is applied first. 
		bool bIsIdentity = true;

		float fScaling = GetScaling();
		if (fScaling != 1.f)
		{
			Matrix4 matScale;
			ParaMatrixScaling((Matrix4*)&matScale, fScaling, fScaling, fScaling);
			mxWorld = (bIsIdentity) ? matScale : matScale.Multiply4x3(mxWorld);
			bIsIdentity = false;
		}

		float fYaw = GetYaw();
		if (fYaw != 0.f)
		{
			Matrix4 matYaw;
			ParaMatrixRotationY((Matrix4*)&matYaw, fYaw);
			mxWorld = (bIsIdentity) ? matYaw : matYaw.Multiply4x3(mxWorld);
			bIsIdentity = false;
		}

		if (GetPitch() != 0.f)
		{
			Matrix4 matPitch;
			ParaMatrixRotationX(&matPitch, GetPitch());
			mxWorld = (bIsIdentity) ? matPitch : matPitch.Multiply4x3(mxWorld);
			bIsIdentity = false;
		}

		if (GetRoll() != 0.f)
		{
			Matrix4 matRoll;
			ParaMatrixRotationZ(&matRoll, GetRoll());
			mxWorld = (bIsIdentity) ? matRoll : matRoll.Multiply4x3(mxWorld);
			bIsIdentity = false;
		}

		// world translation
		Vector3 vPos = GetRenderOffset();
		mxWorld._41 += vPos.x;
		mxWorld._42 += vPos.y;
		mxWorld._43 += vPos.z;

		return &mxWorld;
	}
/**
 * {@inheritDoc}
 */
void ADIS16448_IMU::UpdateTable() {
  auto table = GetTable();
  if (table) {
    table->PutNumber("Value", GetAngle());
    table->PutNumber("Pitch", GetPitch());
    table->PutNumber("Roll", GetRoll());
    table->PutNumber("Yaw", GetYaw());
    table->PutNumber("AccelX", GetAccelX());
    table->PutNumber("AccelY", GetAccelY());
    table->PutNumber("AccelZ", GetAccelZ());
    table->PutNumber("AngleX", GetAngleX());
    table->PutNumber("AngleY", GetAngleY());
    table->PutNumber("AngleZ", GetAngleZ());
  }
}
Пример #11
0
cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) :
	super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5),
	m_PickupState(psNoPickup),
	m_DamageCoeff(2),
	m_IsCritical(false),
	m_Timer(0),
	m_HitGroundTimer(0),
	m_bIsCollected(false),
	m_HitBlockPos(Vector3i(0, 0, 0))
{
	SetSpeed(a_Speed);
	SetMass(0.1);
	SetYawFromSpeed();
	SetPitchFromSpeed();
	LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}",
		m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
		GetYaw(), GetPitch()
	);
}
Пример #12
0
//------------------------------------------------------------------------
void CGunTurret::UpdateSearchingGoal(float deltaTime)
{
	const float epsilon_goal = DEG2RAD(1.f);

	m_goalPitch = DEG2RAD((m_turretparams.max_pitch+m_turretparams.min_pitch)/2.0f);

	float max_yaw = min(gf_PI, 0.5f*DEG2RAD(m_turretparams.yaw_range));
	float yaw = To2PI(GetYaw());
	float pitch = GetPitch();

	if(!m_searchparams.hints.empty())
	{
		// search by hints
		const Vec2 &hint = m_searchparams.hints[m_searchHint];

		m_goalYaw = hint.x*max_yaw;
		m_goalYaw = (m_goalYaw <= 0.f) ? -m_goalYaw : gf_PI2-m_goalYaw; // [0..PI2]

		m_goalPitch = abs(hint.y) * DEG2RAD((hint.y > 0.f) ? m_turretparams.max_pitch : m_turretparams.min_pitch);

		if(abs(m_goalYaw-yaw) < epsilon_goal && abs(m_goalPitch-pitch) < epsilon_goal)
		{
			if(++m_searchHint == m_searchparams.hints.size())
				m_searchHint = 0;
		}
	}
	else
	{
		// horizontal search within angle limits
		m_goalYaw = (m_searchHint) ? max_yaw : -max_yaw;
		m_goalYaw = (m_goalYaw <= 0.f) ? -m_goalYaw : gf_PI2-m_goalYaw;

		if(abs(m_goalYaw-yaw) < epsilon_goal)
			m_searchHint^=1;
	}

	GetGameObject()->ChangedNetworkState(ASPECT_GOALORIENTATION);
}
Пример #13
0
void cPlayer::TossEquippedItem(char a_Amount)
{
	cItems Drops;
	cItem DroppedItem(GetInventory().GetEquippedItem());
	if (!DroppedItem.IsEmpty())
	{
		char NewAmount = a_Amount;
		if (NewAmount > GetInventory().GetEquippedItem().m_ItemCount)
		{
			NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there
		}

		GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount);

		DroppedItem.m_ItemCount = NewAmount;
		Drops.push_back(DroppedItem);
	}

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}
Пример #14
0
void cPlayer::TossHeldItem(char a_Amount)
{
	cItems Drops;
	cItem & Item = GetDraggingItem();
	if (!Item.IsEmpty())
	{
		char OriginalItemAmount = Item.m_ItemCount;
		Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount);
		Drops.push_back(Item);
		if (OriginalItemAmount > a_Amount)
		{
			Item.m_ItemCount = OriginalItemAmount - a_Amount;
		}
		else
		{
			Item.Empty();
		}
	}

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}
/**
 * {@inheritDoc}
 */
float ADIS16448_IMU::GetAngle() const {
  return GetYaw();
}
Пример #16
0
void IMU::UpdateTable() {
        if (m_table != NULL) {
                m_table->PutNumber("Value", GetYaw());
        }
}
Пример #17
0
/**
 * Get the angle in degrees for the PIDSource base object.
 *
 * @return The angle in degrees.
 */
double IMU::PIDGet()
{
        return GetYaw();
}
Пример #18
0
void cEnderCrystal::SpawnOn(cClientHandle & a_ClientHandle)
{
	a_ClientHandle.SendSpawnObject(*this, 51, 0, (Byte)GetYaw(), (Byte)GetPitch());
}
Пример #19
0
/**
 * Returns the current yaw value reported by the sensor.  This
 * yaw value is useful for implementing features including "auto rotate
 * to a known angle".
 * @return The current yaw angle in degrees (-180 to 180).
 */
double AHRS::PIDGet() {
    return GetYaw();
}
Пример #20
0
void AHRS::UpdateTable() {
    if (table != 0) {
        table->PutNumber("Value", GetYaw());
    }
}
Пример #21
0
bool cPlayer::SaveToDisk()
{
	cFile::CreateFolder(FILE_IO_PREFIX + AString("players"));

	// create the JSON data
	Json::Value JSON_PlayerPosition;
	JSON_PlayerPosition.append(Json::Value(GetPosX()));
	JSON_PlayerPosition.append(Json::Value(GetPosY()));
	JSON_PlayerPosition.append(Json::Value(GetPosZ()));

	Json::Value JSON_PlayerRotation;
	JSON_PlayerRotation.append(Json::Value(GetYaw()));
	JSON_PlayerRotation.append(Json::Value(GetPitch()));
	JSON_PlayerRotation.append(Json::Value(GetRoll()));

	Json::Value JSON_Inventory;
	m_Inventory.SaveToJson(JSON_Inventory);

	Json::Value root;
	root["position"]       = JSON_PlayerPosition;
	root["rotation"]       = JSON_PlayerRotation;
	root["inventory"]      = JSON_Inventory;
	root["health"]         = m_Health;
	root["xpTotal"]        = m_LifetimeTotalXp;
	root["xpCurrent"]      = m_CurrentXp;
	root["air"]            = m_AirLevel;
	root["food"]           = m_FoodLevel;
	root["foodSaturation"] = m_FoodSaturationLevel;
	root["foodTickTimer"]  = m_FoodTickTimer;
	root["foodExhaustion"] = m_FoodExhaustionLevel;
	root["world"]          = GetWorld()->GetName();
	root["isflying"]       = IsFlying();

	if (m_GameMode == GetWorld()->GetGameMode())
	{
		root["gamemode"] = (int) eGameMode_NotSet;
	}
	else
	{
		root["gamemode"] = (int) m_GameMode;
	}

	Json::StyledWriter writer;
	std::string JsonData = writer.write(root);

	AString SourceFile;
	Printf(SourceFile, "players/%s.json", GetName().c_str() );

	cFile f;
	if (!f.Open(SourceFile, cFile::fmWrite))
	{
		LOGERROR("ERROR WRITING PLAYER \"%s\" TO FILE \"%s\" - cannot open file", GetName().c_str(), SourceFile.c_str());
		return false;
	}
	if (f.Write(JsonData.c_str(), JsonData.size()) != (int)JsonData.size())
	{
		LOGERROR("ERROR WRITING PLAYER JSON TO FILE \"%s\"", SourceFile.c_str()); 
		return false;
	}

	// Save the player stats.
	// We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
	cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
	if (!StatSerializer.Save())
	{
		LOGERROR("Could not save stats for player %s", GetName().c_str());
		return false;
	}

	return true;
}
Пример #22
0
void MoveUnit(Unit* u)
{
	UnitT* t = &g_utype[u->type];
	u->prevpos = u->cmpos;
	u->collided = false;

	if(u->threadwait)
		return;

	if(Magnitude(u->goal - u->cmpos) <= t->cmspeed)
		return;

	if(u->underorder && u->target < 0 && Magnitude(u->goal - u->cmpos) <= PATHNODE_SIZE)
		return;

	if(u->path.size() <= 0 || *u->path.rbegin() != u->goal)
	{
#if 1
		if(t->military)
		{
			if(g_simframe - u->lastpath < u->pathdelay)
			{
				return;
			}

			//u->pathdelay += 1;
			//u->pathdelay *= 2;
			u->pathdelay += 10;
			u->lastpath = g_simframe;

			int nodesdist = Magnitude( u->goal - u->cmpos ) / PATHNODE_SIZE;
#if 1
			PartialPath(u->type, u->mode,
						u->cmpos.x, u->cmpos.y, u->target, u->target2, u->targtype, &u->path, &u->subgoal,
						u, NULL, NULL,
						u->goal.x, u->goal.y,
						u->goal.x, u->goal.y, u->goal.x, u->goal.y,
						nodesdist*10);
			//TILE_SIZE*4/PATHNODE_SIZE);
#else
			JPSPartPath(u->type, u->mode,
						u->cmpos.x, u->cmpos.y, u->target, u->target2, u->targtype, &u->path, &u->subgoal,
						u, NULL, NULL,
						u->goal.x, u->goal.y,
						u->goal.x, u->goal.y, u->goal.x, u->goal.y,
						nodesdist*4);
#endif

#if 0
			RichText rtext("ppathf");
			NewTransx(u->drawpos + Vec3f(0,t->size.y,0), &rtext);
#endif
		}
		else if(!u->pathblocked)
#endif
		{
#if 0
			if(!FullPath(0,
						 u->type, u->mode,
						 u->cmpos.x, u->cmpos.y, u->target, u->target, u->target2, u->path, u->subgoal,
						 u, NULL, NULL,
						 u->goal.x, u->goal.y,
						 u->goal.x, u->goal.y, u->goal.x, u->goal.y))
#endif

				JPSPath(
					u->type, u->mode,
					u->cmpos.x, u->cmpos.y, u->target, u->target2, u->targtype, &u->path, &u->subgoal,
					u, NULL, NULL,
					u->goal.x, u->goal.y,
					u->goal.x, u->goal.y, u->goal.x, u->goal.y);
		}

		return;
	}

	u->freecollider();

	Vec2i dir = u->subgoal - u->cmpos;

	if(Magnitude2(u->subgoal - u->cmpos) <= t->cmspeed * t->cmspeed)
	{
		u->cmpos = u->subgoal;

		if(u->path.size() >= 2)
		{
			u->path.erase( u->path.begin() );
			u->subgoal = *u->path.begin();
			dir = u->subgoal - u->cmpos;
		}
#if 0
		else
		{
			u->fillcollider();
			u->drawpos.x = u->cmpos.x;
			u->drawpos.z = u->cmpos.y;
			u->drawpos.y = g_hmap.accheight(u->drawpos.x, u->drawpos.z);
			u->rotation.y = GetYaw(dir.x, dir.y);
			return;
		}
#endif
	}

	if(dir.x != 0 || dir.y != 0)
	{
		u->rotation.y = GetYaw(dir.x, dir.y);

		int mag = Magnitude(dir);
#if 0
		if(mag <= 0)
			mag = 1;
#endif

		Vec2i scaleddir = dir * t->cmspeed / mag;
		u->cmpos = u->cmpos + scaleddir;

#if 1
		if(UnitCollides(u, u->cmpos, u->type))
#else
		if(Trace(u->type, u->mode, u->prevpos, u->cmpos, u, NULL, NULL) != COLLIDER_NONE)
#endif
		{
			u->collided = true;
			u->cmpos = u->prevpos;
			u->path.clear();
			u->subgoal = u->cmpos;
			u->fillcollider();
			return;
		}
#if 0
		u->collided = false;
#endif
	}

	if(UnitCollides(u, u->cmpos, u->type))
		u->collided = true;

	u->fillcollider();
	u->drawpos.x = u->cmpos.x;
	u->drawpos.z = u->cmpos.y;
	u->drawpos.y = g_hmap.accheight(u->cmpos.x, u->cmpos.y);
}
Пример #23
0
void cSplashPotionEntity::SpawnOn(cClientHandle & a_Client)
{
	a_Client.SendSpawnObject(*this, 73, m_PotionColor, ANGLE_TO_PROTO(GetYaw()), ANGLE_TO_PROTO(GetPitch()));
	a_Client.SendEntityMetadata(*this);
}
Пример #24
0
bool cPlayer::SaveToDisk()
{
	cFile::CreateFolder(FILE_IO_PREFIX + AString("players/"));  // Create the "players" folder, if it doesn't exist yet (#1268)
	cFile::CreateFolder(FILE_IO_PREFIX + AString("players/") + m_UUID.substr(0, 2));

	// create the JSON data
	Json::Value JSON_PlayerPosition;
	JSON_PlayerPosition.append(Json::Value(GetPosX()));
	JSON_PlayerPosition.append(Json::Value(GetPosY()));
	JSON_PlayerPosition.append(Json::Value(GetPosZ()));

	Json::Value JSON_PlayerRotation;
	JSON_PlayerRotation.append(Json::Value(GetYaw()));
	JSON_PlayerRotation.append(Json::Value(GetPitch()));
	JSON_PlayerRotation.append(Json::Value(GetRoll()));

	Json::Value JSON_Inventory;
	m_Inventory.SaveToJson(JSON_Inventory);

	Json::Value JSON_EnderChestInventory;
	cEnderChestEntity::SaveToJson(JSON_EnderChestInventory, m_EnderChestContents);

	Json::Value root;
	root["position"]            = JSON_PlayerPosition;
	root["rotation"]            = JSON_PlayerRotation;
	root["inventory"]           = JSON_Inventory;
	root["enderchestinventory"] = JSON_EnderChestInventory;
	root["health"]              = m_Health;
	root["xpTotal"]             = m_LifetimeTotalXp;
	root["xpCurrent"]           = m_CurrentXp;
	root["air"]                 = m_AirLevel;
	root["food"]                = m_FoodLevel;
	root["foodSaturation"]      = m_FoodSaturationLevel;
	root["foodTickTimer"]       = m_FoodTickTimer;
	root["foodExhaustion"]      = m_FoodExhaustionLevel;
	root["isflying"]            = IsFlying();
	root["lastknownname"]       = GetName();
	root["SpawnX"]              = GetLastBedPos().x;
	root["SpawnY"]              = GetLastBedPos().y;
	root["SpawnZ"]              = GetLastBedPos().z;

	if (m_World != NULL)
	{
		root["world"] = m_World->GetName();
		if (m_GameMode == m_World->GetGameMode())
		{
			root["gamemode"] = (int) eGameMode_NotSet;
		}
		else
		{
			root["gamemode"] = (int) m_GameMode;
		}
	}
	else
	{
		// This happens if the player is saved to new format after loading from the old format
		root["world"]    = m_LoadedWorldName;
		root["gamemode"] = (int) eGameMode_NotSet;
	}

	Json::StyledWriter writer;
	std::string JsonData = writer.write(root);

	AString SourceFile = GetUUIDFileName(m_UUID);

	cFile f;
	if (!f.Open(SourceFile, cFile::fmWrite))
	{
		LOGWARNING("Error writing player \"%s\" to file \"%s\" - cannot open file. Player will lose their progress.",
			GetName().c_str(), SourceFile.c_str()
		);
		return false;
	}
	if (f.Write(JsonData.c_str(), JsonData.size()) != (int)JsonData.size())
	{
		LOGWARNING("Error writing player \"%s\" to file \"%s\" - cannot save data. Player will lose their progress. ",
			GetName().c_str(), SourceFile.c_str()
		);
		return false;
	}

	// Save the player stats.
	// We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
	cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
	if (!StatSerializer.Save())
	{
		LOGWARNING("Could not save stats for player %s", GetName().c_str());
		return false;
	}

	return true;
}
Пример #25
0
void cProjectileEntity::SpawnOn(cClientHandle & a_Client)
{
    // Default spawning - use the projectile kind to spawn an object:
    a_Client.SendSpawnObject(*this, m_ProjectileKind, 12, ANGLE_TO_PROTO(GetYaw()), ANGLE_TO_PROTO(GetPitch()));
    a_Client.SendEntityMetadata(*this);
}
f32 GetYaw( const Vec2& v0, const Vec2& v1)
{
	Vec3 _v0= Vec3(v0.x, v0.y, 0);
	Vec3 _v1= Vec3(v1.x, v1.y, 0);
	return GetYaw( _v0, _v1);
}