//////////////////////////////////////////////////////////////////////////////
//
// AVP_Actor_Messages.cpp
//
// Created by NJD - 23 November 2006
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

// core
#include "Core/Asura.h"

// header
#include "Entity/PhysicalObject/Projectile/AVP_Projectile_Messages.h"

// asura
#include "Network/Asura_Message.h"

#ifdef ASURA_SUPPORT_NETMSG_SYSTEM
#include "Network/Asura_NetMsg.h"
#endif //#ifdef ASURA_SUPPORT_NETMSG_SYSTEM

// avp
#include "Entity/AVP_Entity_Classification.h"
#include "Entity/PhysicalObject/Projectile/AVP_ServerProjectile_GenericProjectile.h"
#include "Entity/PhysicalObject/Projectile/AVP_ServerProjectile_Disc.h"
#include "Entity/PhysicalObject/Projectile/AVP_ServerProjectile_Mine.h"

void AVP_Message_ProjectileClientUpdate::FillProjectile(const AVP_ServerEntity_Projectile* pxData)
{
	PARENT::FillPhysicalObject(pxData);
	m_uOwnerGuid = pxData->GetOwnerGuid();
	m_uDisarmFlag = pxData->IsDisarmed();
	m_fScale = pxData->GetDamageMultiplier();
}

#ifdef ASURA_SUPPORT_NETMSG_SYSTEM
void AVP_Message_ProjectileClientUpdate::RegisterFields(u_short usMsgID, u_short usEntityClassification)
{
	Asura_Assert(usMsgID == ASURA_MSG_CLIENTUPDATE, "invalid msg ID");
	Asura_Assert(!Asura_NetMsg::FindNetMsgObject(usMsgID, usEntityClassification), "already exists");

	u_char ucNumFields = GetNumFields();

	Asura_NetMsg* pxNetMsg = new Asura_NetMsg(usMsgID, usEntityClassification, ucNumFields, sizeof(AVP_Message_ProjectileClientUpdate));
	RegisterFields(pxNetMsg);
	pxNetMsg->EndRegistration();
}

void AVP_Message_ProjectileClientUpdate::RegisterFields(class Asura_NetMsg* pxNetMsg)
{
	AVP_Message_ProjectileClientUpdate xDummy;
	PARENT::RegisterFields(pxNetMsg);

	Asura_NetMsg_RegisterField(pxNetMsg, xDummy, Asura_FieldType_uint, m_uDisarmFlag, 1, Asura_Threshold_AnyChange, 0.0f);
	Asura_NetMsg_RegisterField(pxNetMsg, xDummy, Asura_FieldType_uint, m_uOwnerGuid, 1, Asura_Threshold_AnyChange, 0.0f);
	Asura_NetMsg_RegisterField(pxNetMsg, xDummy, Asura_FieldType_float, m_fScale, 1, Asura_Threshold_AnyChange, 0.0f);
}
#endif//#ifdef ASURA_SUPPORT_NETMSG_SYSTEM

void AVP_Message_GenericProjectileClientUpdate::FillGenericProjectile( const AVP_ServerProjectile_GenericProjectile* pxData )
{
	PARENT::FillProjectile( pxData );
	m_bIsEmbedded = pxData->IsEmbedded();
}

#ifdef ASURA_SUPPORT_NETMSG_SYSTEM
void AVP_Message_GenericProjectileClientUpdate::RegisterFields(u_short usMsgID, u_short usEntityClassification)
{
	Asura_Assert(usMsgID == ASURA_MSG_CLIENTUPDATE, "invalid msg ID");
	Asura_Assert(!Asura_NetMsg::FindNetMsgObject(usMsgID, usEntityClassification), "already exists");

	u_char ucNumFields = GetNumFields();

	Asura_NetMsg* pxNetMsg = new Asura_NetMsg(usMsgID, usEntityClassification, ucNumFields, sizeof(AVP_Message_GenericProjectileClientUpdate));
	RegisterFields(pxNetMsg);
	pxNetMsg->EndRegistration();
}

void AVP_Message_GenericProjectileClientUpdate::RegisterFields(class Asura_NetMsg* pxNetMsg)
{
	AVP_Message_GenericProjectileClientUpdate xDummy;
	PARENT::RegisterFields(pxNetMsg);

	Asura_NetMsg_RegisterField(pxNetMsg, xDummy, Asura_FieldType_char, m_bIsEmbedded, 1, Asura_Threshold_AnyChange, 0.0f);
}
#endif//#ifdef ASURA_SUPPORT_NETMSG_SYSTEM

void AVP_Message_DiscClientUpdate::FillDisc( const AVP_ServerProjectile_Disc* xProjectile )
{
	PARENT::FillProjectile( xProjectile );
	m_uDiscState = xProjectile->GetDiscState();
}

#ifdef ASURA_SUPPORT_NETMSG_SYSTEM
void AVP_Message_DiscClientUpdate::RegisterFields(u_short usMsgID, u_short usEntityClassification)
{
	Asura_Assert(usMsgID == ASURA_MSG_CLIENTUPDATE, "invalid msg ID");
	Asura_Assert(!Asura_NetMsg::FindNetMsgObject(usMsgID, usEntityClassification), "already exists");
	Asura_Assert(usEntityClassification == AVP_ENTITYCLASS_DISC, "unexpected classification");

	u_char ucNumFields = GetNumFields();

	Asura_NetMsg* pxNetMsg = new Asura_NetMsg(usMsgID, usEntityClassification, ucNumFields, sizeof(AVP_Message_DiscClientUpdate));
	RegisterFields(pxNetMsg);
	pxNetMsg->EndRegistration();
}

void AVP_Message_DiscClientUpdate::RegisterFields(class Asura_NetMsg* pxNetMsg)
{
	AVP_Message_DiscClientUpdate xDummy;
	PARENT::RegisterFields(pxNetMsg); 

	Asura_NetMsg_RegisterField(pxNetMsg, xDummy, Asura_FieldType_uint, m_uDiscState, 1, Asura_Threshold_AnyChange, 0.0f);
}
#endif//#ifdef ASURA_SUPPORT_NETMSG_SYSTEM
// Mine

void AVP_Message_MineClientUpdate::FillMine( const AVP_ServerProjectile_Mine* xProjectile )
{
	PARENT::FillProjectile( xProjectile );
	m_uMineState = xProjectile->GetMineState();
	m_fDetonationOffset = xProjectile->GetDetonationOffset();
}

#ifdef ASURA_SUPPORT_NETMSG_SYSTEM
void AVP_Message_MineClientUpdate::RegisterFields(u_short usMsgID, u_short usEntityClassification)
{
	Asura_Assert(usMsgID == ASURA_MSG_CLIENTUPDATE, "invalid msg ID");
	Asura_Assert(!Asura_NetMsg::FindNetMsgObject(usMsgID, usEntityClassification), "already exists");
	Asura_Assert(usEntityClassification == AVP_ENTITYCLASS_MINE, "unexpected classification");

	u_char ucNumFields = GetNumFields();

	Asura_NetMsg* pxNetMsg = new Asura_NetMsg(usMsgID, usEntityClassification, ucNumFields, sizeof(AVP_Message_MineClientUpdate));
	RegisterFields(pxNetMsg);
	pxNetMsg->EndRegistration();
}

void AVP_Message_MineClientUpdate::RegisterFields(class Asura_NetMsg* pxNetMsg)
{
	AVP_Message_MineClientUpdate xDummy;
	PARENT::RegisterFields(pxNetMsg); 

	Asura_NetMsg_RegisterField(pxNetMsg, xDummy, Asura_FieldType_uint, m_uMineState, 2, Asura_Threshold_AnyChange, 0.0f);
}
#endif//#ifdef ASURA_SUPPORT_NETMSG_SYSTEM
