Пример #1
0
//обновление состояния
float CEntity::CalcCondition(float hit)
{

	// If Local() - perform some logic
	if (Local() && g_Alive()) {
		SetfHealth			(GetfHealth()-hit);
		SetfHealth			((GetfHealth()<-1000)?-1000:GetfHealth());
	}
	return hit;
}
Пример #2
0
void CPhantom::net_Export	(NET_Packet& P)					// export to server
{
	// export 
	R_ASSERT			(Local());

	u8					flags = 0;
	P.w_float			(GetfHealth());

	P.w_float			(0);
	P.w_u32				(0);
	P.w_u32				(0);

	P.w_u32				(Device.dwTimeGlobal);
	P.w_u8				(flags);

	float				yaw, pitch, bank;
	XFORM().getHPB		(yaw,pitch,bank);
	P.w_float /*w_angle8*/			(yaw);
	P.w_float /*w_angle8*/			(yaw);
	P.w_float /*w_angle8*/			(pitch);
	P.w_float /*w_angle8*/			(0);
	P.w_u8				(u8(g_Team()));
	P.w_u8				(u8(g_Squad()));
	P.w_u8				(u8(g_Group()));
}
Пример #3
0
// Core events
void CAI_Crow::net_Export	(NET_Packet& P)					// export to server
{
	// export 
	R_ASSERT			(Local());

	u8					flags = 0;
	P.w_float			(GetfHealth());

	P.w_float			(0);
	P.w_u32				(0);
	P.w_u32				(0);

	P.w_u32				(Level().timeServer());
	P.w_u8				(flags);
	
	float				yaw, pitch, bank;
	XFORM().getHPB		(yaw,pitch,bank);
	P.w_float /*w_angle8*/			(yaw);
	P.w_float /*w_angle8*/			(yaw);
	P.w_float /*w_angle8*/			(pitch);
	P.w_float /*w_angle8*/			(0);
	P.w_u8				(u8(g_Team()));
	P.w_u8				(u8(g_Squad()));
	P.w_u8				(u8(g_Group()));
}
Пример #4
0
//void CCar::Hit(float P,Fvector &dir,CObject * who,s16 element,Fvector p_in_object_space, float impulse, ALife::EHitType hit_type)
void	CCar::Hit							(SHit* pHDS)
{

	SHit	HDS = *pHDS;
	//if(CDelayedActionFuse::isActive()||Initiator()==u16(-1)&&HDS.hit_type==ALife::eHitTypeStrike)
	//{
	//	HDS.power=0.f;
	//}

	//if(HDS.who->ID()!=ID())
	//{
	//	CExplosive::SetInitiator(HDS.who->ID());
	//}
	WheelHit(HDS.damage(),HDS.bone(),HDS.hit_type);
	DoorHit(HDS.damage(),HDS.bone(),HDS.hit_type);
	float hitScale=1.f,woundScale=1.f;
	if(HDS.hit_type!=ALife::eHitTypeStrike) CDamageManager::HitScale(HDS.bone(), hitScale, woundScale);
	HDS.power *= GetHitImmunity(HDS.hit_type)*hitScale;

	inherited::Hit(&HDS);
	if(!CDelayedActionFuse::isActive())
	{
		CDelayedActionFuse::CheckCondition(GetfHealth());
	}
	CDamagableItem::HitEffect();
//	if(Owner()&&Owner()->ID()==Level().CurrentEntity()->ID())
//		CurrentGameUI()->UIMainIngameWnd->CarPanel().SetCarHealth(GetfHealth());
}
Пример #5
0
void CCar::SaveNetState(NET_Packet& P)
{

	CPHSkeleton::SaveNetState	   (P);
	P.w_vec3(Position());
	Fvector Angle;
	XFORM().getXYZ(Angle);
	P.w_vec3(Angle);
	{
		xr_map<u16,SDoor>::iterator i,e;
		i=m_doors.begin();
		e=m_doors.end();
		P.w_u16(u16(m_doors.size()));
		for(;i!=e;++i)
			i->second.SaveNetState(P);
	}

	{
		xr_map<u16,SWheel>::iterator i,e;
		i=m_wheels_map.begin();
		e=m_wheels_map.end();
		P.w_u16(u16(m_wheels_map.size()));
		for(;i!=e;++i)
			i->second.SaveNetState(P);
	}
	P.w_float(GetfHealth());
}
Пример #6
0
void CActorMP::fill_state	(actor_mp_state &state)
{
	if (OnClient())
	{
		//R_ASSERT						(g_Alive());
		//R_ASSERT2						(PHGetSyncItemsNumber() == 1,make_string("PHGetSyncItemsNumber() returned %d, health = %.2f",PHGetSyncItemsNumber(),GetfHealth()));
	}

	SPHNetState						State;
	PHGetSyncItem(0)->get_State		(State);

//	static test = false;
//	if (test) {
#if 0
		Msg							("Frame [%d], object [%d]",Device.dwFrame,ID());
//		Msg							("quaternion   : [%f][%f][%f][%f]",State.quaternion.x,State.quaternion.y,State.quaternion.z,State.quaternion.w);
//		Msg							("angular      : [%f][%f][%f]",State.angular_vel.x,State.angular_vel.y,State.angular_vel.z);
		Msg							("linear       : [%f][%f][%f]",State.linear_vel.x,State.linear_vel.y,State.linear_vel.z);
//		Msg							("force        : [%f][%f][%f]",State.force.x,State.force.y,State.force.z);
//		Msg							("torque       : [%f][%f][%f]",State.torque.x,State.torque.y,State.torque.z);
//		Msg							("acceleration : [%f][%f][%f]",NET_SavedAccel.x,NET_SavedAccel.y,NET_SavedAccel.z);
		Msg							("model_yaw    : [%f]",angle_normalize(r_model_yaw));
		Msg							("camera_yaw   : [%f]",angle_normalize(unaffected_r_torso.yaw));
//		Msg							("camera_pitch : [%f]",angle_normalize(unaffected_r_torso.pitch));
//		Msg							("camera_roll  : [%f]",angle_normalize(unaffected_r_torso.roll));
//	}
#endif // 0

	state.physics_quaternion		= State.quaternion;
	state.physics_angular_velocity	= State.angular_vel;
	state.physics_linear_velocity	= State.linear_vel;
	state.physics_force				= State.force;
	state.physics_torque			= State.torque;
	state.physics_position			= State.position;

	state.position					= Position();

	state.logic_acceleration		= NET_SavedAccel;

	state.model_yaw					= angle_normalize(r_model_yaw);
	state.camera_yaw				= angle_normalize(unaffected_r_torso.yaw);
	state.camera_pitch				= angle_normalize(unaffected_r_torso.pitch);
	state.camera_roll				= angle_normalize(unaffected_r_torso.roll);

	state.time						= Level().timeServer();

	state.inventory_active_slot		= inventory().GetActiveSlot();
	state.body_state_flags			= mstate_real & 0x0000ffff;
	state.health					= GetfHealth();
	//because after packing to 1 byte, this value can be positive...
	if (state.health < EPS)
		state.health = 0;

	state.radiation					= g_Radiation()/100.0f;
	state.physics_state_enabled		= State.enabled ? 1 : 0;
}
Пример #7
0
void	CHelicopter::Hit							(SHit* pHDS)
{
//	inherited::Hit(pHDS);


	if(GetfHealth()<0.005f)
		return;

	if(state() == CHelicopter::eDead ) return;

	if(pHDS->who==this)
		return;

	bonesIt It = m_hitBones.find(pHDS->bone());
	if(It != m_hitBones.end() && pHDS->hit_type==ALife::eHitTypeFireWound) {
		float curHealth = GetfHealth();
		curHealth -= pHDS->damage()*It->second*1000.0f;
		SetfHealth(curHealth);
#ifdef DEBUG
		if (bDebug)	Log("----Helicopter::PilotHit(). health=",curHealth);
#endif
	}else {
		float hit_power		= pHDS->damage();
		hit_power			*= m_HitTypeK[pHDS->hit_type];

		SetfHealth(GetfHealth()-hit_power);
#ifdef DEBUG
		if (bDebug)
			Log("----Helicopter::Hit(). health=",GetfHealth());
#endif
	};
	if (pHDS->who&&
		( pHDS->who->CLS_ID==CLSID_OBJECT_ACTOR	||
		smart_cast<CAI_Stalker*>(pHDS->who)		||
		smart_cast<CCustomZone*>(pHDS->who) )
		){
			callback(GameObject::eHelicopterOnHit)(pHDS->damage(),pHDS->impulse,pHDS->hit_type,pHDS->who->ID());
		}

	CPHDestroyable::SetFatalHit(*pHDS);

}
Пример #8
0
void CCar::shedule_Update(u32 dt)
{
	inherited::shedule_Update(dt);
	if(CPHDestroyable::Destroyed())CPHDestroyable::SheduleUpdate(dt);
	else	CPHSkeleton::Update(dt);
	
	if(CDelayedActionFuse::isActive()&&CDelayedActionFuse::Update(GetfHealth()))
	{
		//CarExplode();
	}
	if(b_exploded&&!m_explosion_flags.test(flExploding)&&!getEnabled())//!m_bExploding
										setEnabled(TRUE);
#ifdef DEBUG
	DbgSheduleUpdate();
#endif
}
Пример #9
0
void CCustomMonster::net_Export(NET_Packet& P)					// export to server
{
	R_ASSERT				(Local());

	// export last known packet
	R_ASSERT				(!NET.empty());
	net_update& N			= NET.back();
	P.w_float				(GetfHealth());
	P.w_u32					(N.dwTimeStamp);
	P.w_u8					(0);
	P.w_vec3				(N.p_pos);
	P.w_float /*w_angle8*/				(N.o_model);
	P.w_float /*w_angle8*/				(N.o_torso.yaw);
	P.w_float /*w_angle8*/				(N.o_torso.pitch);
	P.w_float /*w_angle8*/				(N.o_torso.roll);
	P.w_u8					(u8(g_Team()));
	P.w_u8					(u8(g_Squad()));
	P.w_u8					(u8(g_Group()));
}
Пример #10
0
void CCar::ApplyDamage(u16 level)
{
	CDamagableItem::ApplyDamage(level);
	switch(level)
	{
		case 1: m_damage_particles.Play1(this);break;
		case 2: 
			{
				if(!CDelayedActionFuse::isActive())
				{
					CDelayedActionFuse::CheckCondition(GetfHealth());
				}
				m_damage_particles.Play2(this);
			}
											   break;
		case 3: m_fuel=0.f;
			
	}

}
Пример #11
0
void CBaseMonster::net_Export(NET_Packet& P) 
{
	R_ASSERT				(Local());

	// export last known packet
	R_ASSERT				(!NET.empty());
	net_update& N			= NET.back();
	P.w_float				(GetfHealth());
	P.w_u32					(N.dwTimeStamp);
	P.w_u8					(0);
	P.w_vec3				(N.p_pos);
	P.w_float /*w_angle8*/				(N.o_model);
	P.w_float /*w_angle8*/				(N.o_torso.yaw);
	P.w_float /*w_angle8*/				(N.o_torso.pitch);
	P.w_float /*w_angle8*/				(N.o_torso.roll);
	P.w_u8					(u8(g_Team()));
	P.w_u8					(u8(g_Squad()));
	P.w_u8					(u8(g_Group()));

	GameGraph::_GRAPH_ID		l_game_vertex_id = ai_location().game_vertex_id();
	P.w						(&l_game_vertex_id,			sizeof(l_game_vertex_id));
	P.w						(&l_game_vertex_id,			sizeof(l_game_vertex_id));
//	P.w						(&m_fGoingSpeed,			sizeof(m_fGoingSpeed));
//	P.w						(&m_fGoingSpeed,			sizeof(m_fGoingSpeed));
	float					f1 = 0;
	if (ai().game_graph().valid_vertex_id(l_game_vertex_id)) {
		f1					= Position().distance_to	(ai().game_graph().vertex(l_game_vertex_id)->level_point());
		P.w					(&f1,						sizeof(f1));
		f1					= Position().distance_to	(ai().game_graph().vertex(l_game_vertex_id)->level_point());
		P.w					(&f1,						sizeof(f1));
	}
	else {
		P.w					(&f1,						sizeof(f1));
		P.w					(&f1,						sizeof(f1));
	}

}
void CActorMP::net_Import	( NET_Packet &P)
{
	net_update			N;

	m_state_holder.read	(P);
	R_ASSERT2(valid_pos(m_state_holder.state().position), "imported bad position");

	
	/*if (m_i_am_dead)
		return;*/

	if (OnClient())
	{
/*#ifdef DEBUG
		if (GetfHealth() != m_state_holder.state().health)
			Msg("net_Import: [%d][%s], is going to set health to %2.04f", this->ID(), Name(), m_state_holder.state().health);
#endif*/
		
		game_PlayerState* ps = Game().GetPlayerByGameID(this->object_id());
		float new_health = m_state_holder.state().health;
		if (GetfHealth() < new_health)
		{
			SetfHealth(new_health);
		} else
		{
			if (!ps || !ps->testFlag(GAME_PLAYER_FLAG_INVINCIBLE))
			{
				SetfHealth(new_health);
			}
		}
	}

	if (PPhysicsShell() != NULL)
	{
		return;
	}
	

	if (OnClient())
		SetfRadiation	(m_state_holder.state().radiation*100.0f);

	u16		ActiveSlot = m_state_holder.state().inventory_active_slot;

	if (OnClient() && (inventory().GetActiveSlot()!=ActiveSlot) )
	{
#ifdef DEBUG
		Msg("Client-SetActiveSlot[%d][%d]",ActiveSlot, Device.dwFrame);
#endif // #ifdef DEBUG
		inventory().SetActiveSlot(ActiveSlot);
	}

	N.mstate			= m_state_holder.state().body_state_flags;

	N.dwTimeStamp		= m_state_holder.state().time;
	N.p_pos				= m_state_holder.state().position;

	N.o_model			= m_state_holder.state().model_yaw;
	N.o_torso.yaw		= m_state_holder.state().camera_yaw;
	N.o_torso.pitch		= m_state_holder.state().camera_pitch;
	N.o_torso.roll		= m_state_holder.state().camera_roll;

	if (N.o_torso.roll > PI)
		N.o_torso.roll	-= PI_MUL_2;

	{
		if (Level().IsDemoPlay() || OnServer() || Remote())
		{
			unaffected_r_torso.yaw		= N.o_torso.yaw;
			unaffected_r_torso.pitch	= N.o_torso.pitch;
			unaffected_r_torso.roll		= N.o_torso.roll;

			cam_Active()->yaw	= -N.o_torso.yaw;
			cam_Active()->pitch = N.o_torso.pitch;
		};
	};

	//CSE_ALifeCreatureActor
	N.p_accel				= m_state_holder.state().logic_acceleration;

	process_packet			(N);

	net_update_A			N_A;
	m_States.clear			();

	N_A.State.enabled		= m_state_holder.state().physics_state_enabled;
	N_A.State.angular_vel	= m_state_holder.state().physics_angular_velocity;
	N_A.State.linear_vel	= m_state_holder.state().physics_linear_velocity;
	N_A.State.force			= m_state_holder.state().physics_force;
	N_A.State.torque		= m_state_holder.state().physics_torque;
	N_A.State.position		= m_state_holder.state().physics_position;
	N_A.State.quaternion	= m_state_holder.state().physics_quaternion;

	// interpolcation
	postprocess_packet		(N_A);
}
Пример #13
0
void CCar::Init()
{

	CPHCollisionDamageReceiver::Init();

	//get reference wheel radius
	IKinematics* pKinematics=smart_cast<IKinematics*>(Visual());
	CInifile* ini = pKinematics->LL_UserData();
	R_ASSERT2(ini,"Car has no description !!! See ActorEditor Object - UserData");
	///SWheel& ref_wheel=m_wheels_map.find(pKinematics->LL_BoneID(ini->r_string("car_definition","reference_wheel")))->second;

	if(ini->section_exist("air_resistance"))
	{
		PPhysicsShell()->SetAirResistance(default_k_l*ini->r_float("air_resistance","linear_factor"),default_k_w*ini->r_float("air_resistance","angular_factor"));
	}
	if(ini->line_exist("car_definition","steer"))
	{
		
		
		m_bone_steer=pKinematics->LL_BoneID(ini->r_string("car_definition","steer"));
		VERIFY2(fsimilar(DET(pKinematics->LL_GetTransform(m_bone_steer)),1.f,EPS_L),"BBADD MTX");
		pKinematics->LL_GetBoneInstance(m_bone_steer).set_callback(bctPhysics,cb_Steer,this);
	}
	m_steer_angle=0.f;
	//ref_wheel.Init();
	m_ref_radius=ini->r_float("car_definition","reference_radius");//ref_wheel.radius;
	b_exploded						=false;
	b_engine_on						=false;
	b_clutch						=false;
	b_starting						=false;
	b_stalling						=false;
	b_transmission_switching		=false;
	m_root_transform.set(bone_map.find(pKinematics->LL_GetBoneRoot())->second.element->mXFORM);
	m_current_transmission_num=0;
	m_pPhysicsShell->set_DynamicScales(1.f,1.f);
	CDamagableItem::Init(GetfHealth(),3);
	float l_time_to_explosion=READ_IF_EXISTS(ini,r_float,"car_definition","time_to_explosion",120.f);
	CDelayedActionFuse::Initialize(l_time_to_explosion,CDamagableItem::DamageLevelToHealth(2));
	{
		xr_map<u16,SWheel>::iterator i,e;
		i=m_wheels_map.begin();
		e=m_wheels_map.end();
		for(;i!=e;++i)
		{
			i->second.Init();
			i->second.CDamagableHealthItem::Init(100.f,2);
		}
	}

	{
		xr_vector<SWheelDrive>::iterator i,e;
		i=m_driving_wheels.begin();
		e=m_driving_wheels.end();
		for(;i!=e;++i)
			i->Init();
	}

	{
		xr_vector<SWheelBreak>::iterator i,e;
		i=m_breaking_wheels.begin();
		e=m_breaking_wheels.end();
		for(;i!=e;++i)
			i->Init();
	}

	{
		xr_vector<SWheelSteer>::iterator i,e;
		i=m_steering_wheels.begin();
		e=m_steering_wheels.end();
		for(;i!=e;++i)
			i->Init();
	}

	{
		xr_vector<SExhaust>::iterator i,e;
		i=m_exhausts.begin();
		e=m_exhausts.end();
		for(;i!=e;++i)
			i->Init();
	}

	{
		xr_map<u16,SDoor>::iterator i,e;
		i=m_doors.begin();
		e=m_doors.end();
		for(;i!=e;++i)
		{
			i->second.Init();
			i->second.CDamagableHealthItem::Init(100,1);
		}
			
	}

	if(ini->section_exist("damage_items"))
	{
		CInifile::Sect& data		= ini->r_section("damage_items");
		for (CInifile::SectCIt		I=data.Data.begin(); I!=data.Data.end(); I++){
			const CInifile::Item& item	= *I;
			u16 index				= pKinematics->LL_BoneID(*item.first); 
			R_ASSERT3(index != BI_NONE, "Wrong bone name", *item.first);
			xr_map   <u16,SWheel>::iterator i=m_wheels_map.find(index);
			
			if(i!=m_wheels_map.end())
					i->second.CDamagableHealthItem::Init(float(atof(*item.second)),2);
			else 
			{
				xr_map   <u16,SDoor>::iterator i=m_doors.find(index);
				R_ASSERT3(i!=m_doors.end(),"only wheel and doors bones allowed for damage defs",*item.first);
				i->second.CDamagableHealthItem::Init(float(atof(*item.second)),1);
			}

		}
	}
	

	if(ini->section_exist("immunities"))
	{
		LoadImmunities("immunities",ini);
	}

	CDamageManager::reload("car_definition","damage",ini);
	
	HandBreak();
	Transmission(1);

}