<commit_before>//
// CItemShip.cpp
//

#include "graysvr.h"	// predef header.
#include "../network/send.h"

/////////////////////////////////////////////////////////////////////////////

CItemShip::CItemShip( ITEMID_TYPE id, CItemBase * pItemDef ) : CItemMulti( id, pItemDef )
{
	m_NextMove = CServTime::GetCurrentTime();
}

CItemShip::~CItemShip()
{
	g_Serv.ShipTimers_Delete(this);
}

bool CItem::Ship_Plank( bool fOpen )
{
	ADDTOCALLSTACK("CItem::Ship_Plank");
	// IT_SHIP_PLANK to IT_SHIP_SIDE and IT_SHIP_SIDE_LOCKED
	// This item is the ships plank.

	CItemBase * pItemDef = Item_GetDef();
	ITEMID_TYPE idState = static_cast<ITEMID_TYPE>(RES_GET_INDEX(pItemDef->m_ttShipPlank.m_idState));
	if ( !idState )
		return( false );

	if ( IsType(IT_SHIP_PLANK))
	{
		if ( fOpen )
			return( true );
	}
	else
	{
		if ( ! fOpen )
			return( true );
	}

	IT_TYPE oldType = GetType();
	SetID( idState );

	if ( IsType(IT_SHIP_PLANK) && (oldType == IT_SHIP_SIDE || oldType == IT_SHIP_SIDE_LOCKED) )
	{
		// Save the original Type of the plank if it used to be a ship side
		m_itShipPlank.m_itSideType = static_cast<WORD>(oldType);
	}
	else if ( oldType == IT_SHIP_PLANK )
	{
		// Restore the type of the ship side
		if ( m_itShipPlank.m_itSideType == IT_SHIP_SIDE || m_itShipPlank.m_itSideType == IT_SHIP_SIDE_LOCKED )
			SetType(static_cast<IT_TYPE>(m_itShipPlank.m_itSideType));

		m_itShipPlank.m_itSideType = IT_NORMAL;
	}

	Update();
	return( true );
}

void CItemShip::Ship_Stop()
{
	ADDTOCALLSTACK("CItemShip::Ship_Stop");
	// Make sure we have stopped.
	m_itShip.m_fSail = 0;
}

bool CItemShip::Ship_SetMoveDir(DIR_TYPE dir, BYTE speed, bool bWheelMove)
{
	ADDTOCALLSTACK("CItemShip::Ship_SetMoveDir");
	// Set the direction we will move next time we get a tick.
	// Called from Packet 0xBF.0x32 : PacketWheelBoatMove to check if ship can move while setting dir and checking times in the proccess, otherwise for each click with mouse it will do 1 move.

	m_itShip.m_DirMove = static_cast<BYTE>(dir);	// we set new direction regardless of click limitations, so click in another direction means changing dir but makes not more moves until ship's timer moves it.
	if ( bWheelMove && m_NextMove > CServTime::GetCurrentTime() )
		return false;

	if ( m_itShip.m_DirFace == m_itShip.m_DirMove && m_itShip.m_fSail == 1 )
		speed = 2;
	else if ( !speed )
		speed = 1;

	if ( !IsAttr(ATTR_MAGIC) && !Calc_GetRandVal(10) )	// make sound.
		Sound(Calc_GetRandVal(2) ? 0x12 : 0x13);

	m_itShip.m_fSail = min(speed, 2);		// checking here that packet is legit from client and not modified by 3rd party tools to send speed > 2.
	GetTopSector()->SetSectorWakeStatus();	// may get here b4 my client does.
	CItemMulti *pItemMulti = static_cast<CItemMulti *>(this);
	pItemMulti->m_SpeedMode = (speed == 1) ? 3 : 4;
	g_Serv.ShipTimers_Delete(this);
	g_Serv.ShipTimers_Add(this);

	if ( IsSetOF(OF_NoSmoothSailing) )
		m_NextMove = CServTime::GetCurrentTime() + maximum(1, (m_itShip.m_fSail == 1) ? pItemMulti->m_shipSpeed.period * 2 : pItemMulti->m_shipSpeed.period);
	else
		m_NextMove = CServTime::GetCurrentTime() + maximum(1, (m_itShip.m_fSail == 1) ? pItemMulti->m_shipSpeed.period : pItemMulti->m_shipSpeed.period / 2);
	return true;<commit_msg>Fixed compiler broken on Linux<commit_after>//
// CItemShip.cpp
//

#include "graysvr.h"	// predef header.
#include "../network/send.h"

/////////////////////////////////////////////////////////////////////////////

CItemShip::CItemShip( ITEMID_TYPE id, CItemBase * pItemDef ) : CItemMulti( id, pItemDef )
{
	m_NextMove = CServTime::GetCurrentTime();
}

CItemShip::~CItemShip()
{
	g_Serv.ShipTimers_Delete(this);
}

bool CItem::Ship_Plank( bool fOpen )
{
	ADDTOCALLSTACK("CItem::Ship_Plank");
	// IT_SHIP_PLANK to IT_SHIP_SIDE and IT_SHIP_SIDE_LOCKED
	// This item is the ships plank.

	CItemBase * pItemDef = Item_GetDef();
	ITEMID_TYPE idState = static_cast<ITEMID_TYPE>(RES_GET_INDEX(pItemDef->m_ttShipPlank.m_idState));
	if ( !idState )
		return( false );

	if ( IsType(IT_SHIP_PLANK))
	{
		if ( fOpen )
			return( true );
	}
	else
	{
		if ( ! fOpen )
			return( true );
	}

	IT_TYPE oldType = GetType();
	SetID( idState );

	if ( IsType(IT_SHIP_PLANK) && (oldType == IT_SHIP_SIDE || oldType == IT_SHIP_SIDE_LOCKED) )
	{
		// Save the original Type of the plank if it used to be a ship side
		m_itShipPlank.m_itSideType = static_cast<WORD>(oldType);
	}
	else if ( oldType == IT_SHIP_PLANK )
	{
		// Restore the type of the ship side
		if ( m_itShipPlank.m_itSideType == IT_SHIP_SIDE || m_itShipPlank.m_itSideType == IT_SHIP_SIDE_LOCKED )
			SetType(static_cast<IT_TYPE>(m_itShipPlank.m_itSideType));

		m_itShipPlank.m_itSideType = IT_NORMAL;
	}

	Update();
	return( true );
}

void CItemShip::Ship_Stop()
{
	ADDTOCALLSTACK("CItemShip::Ship_Stop");
	// Make sure we have stopped.
	m_itShip.m_fSail = 0;
}

bool CItemShip::Ship_SetMoveDir(DIR_TYPE dir, BYTE speed, bool bWheelMove)
{
	ADDTOCALLSTACK("CItemShip::Ship_SetMoveDir");
	// Set the direction we will move next time we get a tick.
	// Called from Packet 0xBF.0x32 : PacketWheelBoatMove to check if ship can move while setting dir and checking times in the proccess, otherwise for each click with mouse it will do 1 move.

	m_itShip.m_DirMove = static_cast<BYTE>(dir);	// we set new direction regardless of click limitations, so click in another direction means changing dir but makes not more moves until ship's timer moves it.
	if ( bWheelMove && m_NextMove > CServTime::GetCurrentTime() )
		return false;

	if ( m_itShip.m_DirFace == m_itShip.m_DirMove && m_itShip.m_fSail == 1 )
		speed = 2;
	else if ( !speed )
		speed = 1;

	if ( !IsAttr(ATTR_MAGIC) && !Calc_GetRandVal(10) )	// make sound.
		Sound(Calc_GetRandVal(2) ? 0x12 : 0x13);

	m_itShip.m_fSail = minimum(speed, 2);	// checking here that packet is legit from client and not modified by 3rd party tools to send speed > 2.
	GetTopSector()->SetSectorWakeStatus();	// may get here b4 my client does.
	CItemMulti *pItemMulti = static_cast<CItemMulti *>(this);
	pItemMulti->m_SpeedMode = (speed == 1) ? 3 : 4;
	g_Serv.ShipTimers_Delete(this);
	g_Serv.ShipTimers_Add(this);

	if ( IsSetOF(OF_NoSmoothSailing) )
		m_NextMove = CServTime::GetCurrentTime() + maximum(1, (m_itShip.m_fSail == 1) ? pItemMulti->m_shipSpeed.period * 2 : pItemMulti->m_shipSpeed.period);
	else
		m_NextMove = CServTime::GetCurrentTime() + maximum(1, (m_itShip.m_fSail == 1) ? pItemMulti->m_shipSpeed.period : pItemMulti->m_shipSpeed.period / 2);
	return true;
{'fraction_non_alphanumeric': 0.14122725871107, 'fraction_numerical': 0.009559050262102992, 'mean_word_length': 3.982334869431644, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3188421', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2512, 'n_words': 571}