Exemplo n.º 1
0
void CGameObject::update_ai_locations			(bool decrement_reference)
{
	u32								l_dwNewLevelVertexID = new_level_vertex_id();
	VERIFY							(ai().level_graph().valid_vertex_id(l_dwNewLevelVertexID));
	if (decrement_reference && (ai_location().level_vertex_id() == l_dwNewLevelVertexID))
		return;

	ai_location().level_vertex		(l_dwNewLevelVertexID);

	if (!ai().get_game_graph() && ai().get_cross_table())
		return;

	ai_location().game_vertex		(ai().cross_table().vertex(ai_location().level_vertex_id()).game_vertex_id());
	VERIFY							(ai().game_graph().valid_vertex_id(ai_location().game_vertex_id()));
}
Exemplo n.º 2
0
BOOL CLevelChanger::net_Spawn	(CSE_Abstract* DC) 
{
	m_entrance_time				= 0;
	CCF_Shape *l_pShape			= xr_new<CCF_Shape>(this);
	collidable.model			= l_pShape;
	
	CSE_Abstract				*l_tpAbstract = (CSE_Abstract*)(DC);
	CSE_ALifeLevelChanger		*l_tpALifeLevelChanger = smart_cast<CSE_ALifeLevelChanger*>(l_tpAbstract);
	R_ASSERT					(l_tpALifeLevelChanger);

	m_game_vertex_id			= l_tpALifeLevelChanger->m_tNextGraphID;
	m_level_vertex_id			= l_tpALifeLevelChanger->m_dwNextNodeID;
	m_position					= l_tpALifeLevelChanger->m_tNextPosition;
	m_angles					= l_tpALifeLevelChanger->m_tAngles;

	m_bSilentMode				= !!l_tpALifeLevelChanger->m_bSilentMode;
	if (ai().get_level_graph()) {
		//. this information should be computed in xrAI
		ai_location().level_vertex	(ai().level_graph().vertex(u32(-1),Position()));
		ai_location().game_vertex	(ai().cross_table().vertex(ai_location().level_vertex_id()).game_vertex_id());
	}

	feel_touch.clear			();
	
	for (u32 i=0; i < l_tpALifeLevelChanger->shapes.size(); ++i) {
		CSE_Shape::shape_def	&S = l_tpALifeLevelChanger->shapes[i];
		switch (S.type) {
			case 0 : {
				l_pShape->add_sphere(S.data.sphere);
				break;
			}
			case 1 : {
				l_pShape->add_box(S.data.box);
				break;
			}
		}
	}

	BOOL						bOk = inherited::net_Spawn(DC);
	if (bOk) {
		l_pShape->ComputeBounds	();
		Fvector					P;
		XFORM().transform_tiny	(P,CFORM()->getSphere().P);
		setEnabled				(TRUE);
	}
	g_lchangers.push_back		(this);
	return						(bOk);
}
Exemplo n.º 3
0
u32 CGameObject::new_level_vertex_id			() const
{
	Fvector							center;
	Center							(center);
	center.x						= Position().x;
	center.z						= Position().z;
	return							(ai().level_graph().vertex(ai_location().level_vertex_id(),center));
}
Exemplo n.º 4
0
void CGameObject::reinit	()
{
	m_visual_callback.clear	();
	if (!g_dedicated_server)
        ai_location().reinit	();

	// clear callbacks	
	for (CALLBACK_MAP_IT it = m_callbacks->begin(); it != m_callbacks->end(); ++it) it->second.clear();
}
Exemplo n.º 5
0
void CWeapon::SpawnAmmo(u32 boxCurr, LPCSTR ammoSect, u32 ParentID) 
{
	if(!m_ammoTypes.size())			return;
	if (OnClient())					return;
	m_bAmmoWasSpawned				= true;
	
	int l_type						= 0;
	l_type							%= m_ammoTypes.size();

	if(!ammoSect) ammoSect			= m_ammoTypes[l_type].c_str(); 
	
	++l_type; 
	l_type							%= m_ammoTypes.size();

	CSE_Abstract *D					= F_entity_Create(ammoSect);

	{	
		CSE_ALifeItemAmmo *l_pA		= smart_cast<CSE_ALifeItemAmmo*>(D);
		R_ASSERT					(l_pA);
		l_pA->m_boxSize				= (u16)pSettings->r_s32(ammoSect, "box_size");
		D->s_name					= ammoSect;
		D->set_name_replace			("");
//.		D->s_gameid					= u8(GameID());
		D->s_RP						= 0xff;
		D->ID						= 0xffff;
		if (ParentID == 0xffffffff)	
			D->ID_Parent			= (u16)H_Parent()->ID();
		else
			D->ID_Parent			= (u16)ParentID;

		D->ID_Phantom				= 0xffff;
		D->s_flags.assign			(M_SPAWN_OBJECT_LOCAL);
		D->RespawnTime				= 0;
		l_pA->m_tNodeID				= g_dedicated_server ? u32(-1) : ai_location().level_vertex_id();

		if(boxCurr == 0xffffffff) 	
			boxCurr					= l_pA->m_boxSize;

		while(boxCurr) 
		{
			l_pA->a_elapsed			= (u16)(boxCurr > l_pA->m_boxSize ? l_pA->m_boxSize : boxCurr);
			NET_Packet				P;
			D->Spawn_Write			(P, TRUE);
			Level().Send			(P,net_flags(TRUE));

			if(boxCurr > l_pA->m_boxSize) 
				boxCurr				-= l_pA->m_boxSize;
			else 
				boxCurr				= 0;
		}
	}
	F_entity_Destroy				(D);
}
Exemplo n.º 6
0
void CGameObject::setup_parent_ai_locations(bool assign_position)
{
//	CGameObject				*l_tpGameObject	= static_cast<CGameObject*>(H_Root());
	VERIFY					(H_Parent());
	CGameObject				*l_tpGameObject	= static_cast<CGameObject*>(H_Parent());
	VERIFY					(l_tpGameObject);

	// get parent's position
	if ( assign_position && use_parent_ai_locations() )
		Position().set		(l_tpGameObject->Position());

	//if ( assign_position && 
	//		( use_parent_ai_locations() &&
	//		!( cast_attachable_item() && cast_attachable_item()->enabled() )
	//		 ) 
	//	)
	//	Position().set		(l_tpGameObject->Position());

	// setup its ai locations
	if (!UsedAI_Locations())
		return;

	if (!ai().get_level_graph())
		return;

	if (l_tpGameObject->UsedAI_Locations() && ai().level_graph().valid_vertex_id(l_tpGameObject->ai_location().level_vertex_id()))
		ai_location().level_vertex	(l_tpGameObject->ai_location().level_vertex_id());
	else
		validate_ai_locations	(false);
//	VERIFY2						(l_tpGameObject->UsedAI_Locations(),*l_tpGameObject->cNameSect());
//	VERIFY2						(ai().level_graph().valid_vertex_id(l_tpGameObject->ai_location().level_vertex_id()),*cNameSect());
//	ai_location().level_vertex	(l_tpGameObject->ai_location().level_vertex_id());

	if (ai().game_graph().valid_vertex_id(l_tpGameObject->ai_location().game_vertex_id()))
		ai_location().game_vertex	(l_tpGameObject->ai_location().game_vertex_id());
	else
		ai_location().game_vertex	(ai().cross_table().vertex(ai_location().level_vertex_id()).game_vertex_id());
//	VERIFY2						(ai().game_graph().valid_vertex_id(l_tpGameObject->ai_location().game_vertex_id()),*cNameSect());
//	ai_location().game_vertex	(l_tpGameObject->ai_location().game_vertex_id());
}
Exemplo n.º 7
0
void CBaseMonster::net_Import(NET_Packet& P)
{
	R_ASSERT				(Remote());
	net_update				N;

	u8 flags;

	float health;
	P.r_float			(health);
	SetfHealth			(health);

	P.r_u32					(N.dwTimeStamp);
	P.r_u8					(flags);
	P.r_vec3				(N.p_pos);
	P.r_float /*r_angle8*/				(N.o_model);
	P.r_float /*r_angle8*/				(N.o_torso.yaw);
	P.r_float /*r_angle8*/				(N.o_torso.pitch);
	P.r_float /*r_angle8*/				(N.o_torso.roll	);
	id_Team					= P.r_u8();
	id_Squad				= P.r_u8();
	id_Group				= P.r_u8();

	GameGraph::_GRAPH_ID		l_game_vertex_id = ai_location().game_vertex_id();
	P.r						(&l_game_vertex_id,			sizeof(l_game_vertex_id));
	P.r						(&l_game_vertex_id,			sizeof(l_game_vertex_id));

	if (NET.empty() || (NET.back().dwTimeStamp<N.dwTimeStamp))	{
		NET.push_back			(N);
		NET_WasInterpolating	= TRUE;
	}

//	P.r						(&m_fGoingSpeed,			sizeof(m_fGoingSpeed));
//	P.r						(&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.r					(&f1,						sizeof(f1));
		f1					= Position().distance_to	(ai().game_graph().vertex(l_game_vertex_id)->level_point());
		P.r					(&f1,						sizeof(f1));
	}
	else {
		P.r					(&f1,						sizeof(f1));
		P.r					(&f1,						sizeof(f1));
	}


	setVisible				(TRUE);
	setEnabled				(TRUE);
}
Exemplo n.º 8
0
bool CBaseMonster::enemy_accessible ()
{
	if ( !m_first_tick_enemy_inaccessible )
		return							true;

	if ( EnemyMan.get_enemy() )
	{
		u32 const enemy_vertex		=	EnemyMan.get_enemy()->ai_location().level_vertex_id();
		if ( ai_location().level_vertex_id() == enemy_vertex )
			return						false;
	}

	if ( Device.dwTimeGlobal < m_first_tick_enemy_inaccessible + 3000 )
		return							true;

	return								false;
}
Exemplo n.º 9
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));
	}

}
Exemplo n.º 10
0
void   CBaseMonster::add_debug_info (debug::text_tree& root_s)
{
	if ( !g_Alive() )
	{
		return;
	}

	typedef debug::text_tree TextTree;

	//-----------------------------------------------
	// General
	//-----------------------------------------------
	TextTree& general_s = root_s.find_or_add("General");

	detail::add_debug_info(general_s, this);
	TextTree& current_visual_s = general_s.add_line("Current_Visual");
	current_visual_s.add_line(*cNameVisual());

	general_s.add_line("Health", conditions().GetHealth());
	general_s.add_line("Morale", Morale.get_morale());
	general_s.add_line("Angry", m_bAngry);
	general_s.add_line("Growling", m_bGrowling);
	general_s.add_line("Aggressive", m_bAggressive);
	general_s.add_line("Sleep", m_bSleep);

	TextTree& perceptors_s = general_s.find_or_add("Perceptors");
	TextTree& visuals_s = perceptors_s.find_or_add("Visual");

	float object_range, object_fov;
	update_range_fov (object_range,object_fov,eye_range,deg2rad(eye_fov));
	visuals_s.add_line("Eye_Range", object_range);
	visuals_s.add_line("FOV", rad2deg(object_fov));

	CActor* actor = smart_cast<CActor*>(Level().Objects.net_Find(0));
	if ( !actor ) 
	{
		actor = g_debug_actor;
	}

	if ( actor )
	{
		visuals_s.add_line("Actor_Visible",  memory().visual().visible_now(actor));
	}

	//-----------------------------------------------
	// Sounds
	//-----------------------------------------------
	TextTree& sounds_s = perceptors_s.find_or_add("Sounds");
	sounds_s.add_line("Num_Sounds", SoundMemory.GetNumSounds());

	if ( SoundMemory.IsRememberSound() )
	{
		TextTree&   last_s = sounds_s.add_line("Last");

		SoundElem	last_sound;
		bool		last_dangerous;
		SoundMemory.GetSound(last_sound, last_dangerous);
		detail::add_debug_info(last_s, last_sound, last_dangerous);

		if ( SoundMemory.GetNumSounds() > 1 )
		{
			SoundElem	first_sound;
			bool		first_dangerous;
			SoundMemory.GetFirstSound(first_sound, first_dangerous);

			TextTree&   first_s = sounds_s.add_line("First");
			detail::add_debug_info(first_s, first_sound, first_dangerous);
		}
	}
	else
	{
		sounds_s.add_text("no");
	}

	//-----------------------------------------------
	// Hits
	//-----------------------------------------------
	TextTree& hit_s = perceptors_s.add_line("Hits", HitMemory.get_num_hits());
	
	// Hit
	if ( HitMemory.is_hit() ) 
	{
		TextTree& last_hit_object_s = hit_s.add_line("Object");
		detail::add_debug_info(last_hit_object_s, smart_cast<CEntity*>(HitMemory.get_last_hit_object()));
		hit_s.add_line("Time", HitMemory.get_last_hit_time());
		hit_s.add_line("Pos", HitMemory.get_last_hit_position());
		hit_s.add_line("Dir", HitMemory.get_last_hit_dir());
	} 

	//-----------------------------------------------
	// Corpses
	//-----------------------------------------------
	TextTree& corpse_s = general_s.find_or_add("Corpse_Man");

	corpse_s.add_line("Current_Corpse",  CorpseMan.get_corpse() ? 
		                                *CorpseMan.get_corpse()->cName() : "none");
	corpse_s.add_line("Satiety",  make_xrstr("%.2f", GetSatiety()));

	//-----------------------------------------------
	// Group behavious
	//-----------------------------------------------
	TextTree& group_s = general_s.find_or_add("Group_Behaviour");
	group_s.add_line("Team", g_Team());

	TextTree& squad_s = group_s.add_line("Squad",  g_Squad());

	CMonsterSquad* squad = monster_squad().get_squad(this);
	if ( squad )
	{
		squad_s.add_line("SquadActive", squad->SquadActive());
		squad_s.add_line("Im_Leader", squad->GetLeader() == this);
		detail::add_debug_info(squad_s.add_line("Leader"), squad->GetLeader());

		int num_alive = squad->squad_alife_count();
		if ( !num_alive && g_Alive() )
		{
			num_alive++;
		}
		squad_s.add_line("Alive_Count", num_alive);

		TextTree& squad_command_s = squad_s.add_line("My_Squad_Command");
		squad_command_s.add_line("Command_Type", squad->GetCommand(this).type);

		TextTree& squad_goal_s = squad_s.add_line("My_Squad_Goal");
		squad_goal_s.add_line("Goal_Type", squad->GetGoal(this).type);
		detail::add_debug_info(squad_goal_s.add_line("Goal_Entity"), squad->GetGoal(this).entity);
	}

	group_s.add_line("Group", g_Group());

	//-----------------------------------------------
	// Brain (Fsm & Script)
	//-----------------------------------------------
	TextTree& brain_s = root_s.find_or_add("Brain");

	TextTree& fsm_s = brain_s.find_or_add("Fsm");
	StateMan->add_debug_info(fsm_s);

	TextTree& script_control_s = brain_s.add_line("Script_Control_Name");
	if ( !m_bScriptControl )
	{
		script_control_s.add_text("-");
	}
	else
	{
		script_control_s.add_text(GetScriptControlName());

		TextTree& cur_script_action_s = brain_s.add_line("Current_Script_Action");
		if ( m_tpCurrentEntityAction )
		{
			detail::add_debug_info(cur_script_action_s, m_tpCurrentEntityAction);
		}
		else
		{
			cur_script_action_s.add_text("-");
		}

		TextTree& next_script_action_s = brain_s.add_line("Next_Script_Action");
		if ( m_tpActionQueue.size() )
		{
			detail::add_debug_info(next_script_action_s, m_tpActionQueue.front());
		}
		else
		{
			next_script_action_s.add_text("-");
		}
	}

	//-----------------------------------------------
	// Control Manager
	//-----------------------------------------------
	control().add_debug_info( brain_s.add_line("Control_Manager") );

	TextTree& map_home_s = brain_s.add_line("Map_Home");
	map_home_s.add_line("min", Home->get_min_radius());
	map_home_s.add_line("mid", Home->get_mid_radius());
	map_home_s.add_line("max", Home->get_max_radius());
	
	if ( EnemyMan.get_enemy() )
	{
		map_home_s.add_line("Enemy_At_Min", Home->at_min_home( EnemyMan.get_enemy()->Position() ));
		map_home_s.add_line("Enemy_At_Mid", Home->at_mid_home( EnemyMan.get_enemy()->Position() ));
		map_home_s.add_line("Enemy_At_Max", Home->at_home    ( EnemyMan.get_enemy()->Position() ));

		map_home_s.add_line("Dist_To_Enemy", Position().distance_to( EnemyMan.get_enemy()->Position() ));
	}
	
	//-----------------------------------------------
	// Enemies
	//-----------------------------------------------
	TextTree& enemies_s = general_s.find_or_add("Enemies");
	enemies_s.add_text(EnemyMemory.get_enemies_count());

	if ( actor )
	{
		enemies_s.add_line("Actor_Is_Enemy", EnemyMan.is_enemy(actor));
	}

	TextTree& current_enemy_s = enemies_s.find_or_add("Current_Enemy");
	if ( EnemyMan.get_enemy() )
	{
		detail::add_enemy_debug_info(current_enemy_s, this, EnemyMan.get_enemy());
		current_enemy_s.add_line("Time_Last_Seen",  EnemyMan.get_enemy_time_last_seen());
		current_enemy_s.add_line("See_Duration",    EnemyMan.see_enemy_duration());
	}
	else
	{
		current_enemy_s.add_text("0");
	}

	int index = 1;
	for ( ENEMIES_MAP::const_iterator i = EnemyMemory.get_memory().begin(),
		                              e = EnemyMemory.get_memory().end();
		  i!=e; ++i )
	{
		const CEntityAlive* p_enemy = (*i).first;
		if ( p_enemy != EnemyMan.get_enemy() )
		{
			TextTree& enemy_s = enemies_s.add_line(make_xrstr("Enemy %i", index++));
			detail::add_enemy_debug_info(enemy_s, this, p_enemy);
		}			
	}

	//-----------------------------------------------
	// Animations
	//-----------------------------------------------
	TextTree& controller_s = root_s.find_or_add("Controllers");
	TextTree& animation_s = controller_s.find_or_add("Animations");

	TextTree& current_animation_s = animation_s.add_line(*anim().cur_anim_info().name);

	
	CBlend* p_blend = control().animation().current_blend();
	if ( !p_blend )
	{
		p_blend = anim().cur_anim_info().blend;
	}
	
	if ( p_blend )
	{
		detail::add_debug_info(current_animation_s, p_blend);
		current_animation_s.add_line("Script_Animation?", p_blend->motionID == m_tpScriptAnimation);
	}
	else
	{
		current_animation_s.add_text("0");
	}

	//-----------------------------------------------
	// Movement
	//-----------------------------------------------
	TextTree& movement_s = controller_s.find_or_add("Movement");
	movement_s.add_line("Actual",  control().path_builder().actual());
	movement_s.add_line("Enabled",  control().path_builder().enabled());

	CEntityAlive *entity = smart_cast<CEntityAlive *>(Level().CurrentEntity());
	if ( entity && entity->character_physics_support()->movement() ) 
	{
		movement_s.add_line("Velocity",  entity->character_physics_support()->movement()->GetVelocityActual());
	}
	movement_s.add_line("Position").add_line(Position());

	movement_s.add_line("Level_Vertex_ID", ai_location().level_vertex_id());
	movement_s.add_line("Game_Vertex_ID", ai_location().game_vertex_id());

	detail::add_debug_info(movement_s.add_line("Orientation_Current"), 
		                   movement().body_orientation().current);
	detail::add_debug_info(movement_s.add_line("Orientation_Target"), 
		                   movement().body_orientation().target);
	movement_s.add_line("Rotation_Speed", movement().body_orientation().speed);

	const char* pc_path_type = "undefined";
	switch ( movement().path_type() )
	{
		case MovementManager::ePathTypePatrolPath: pc_path_type = "Patrol_Path"; break;
		case MovementManager::ePathTypeGamePath:   pc_path_type = "Game_Path";   break;
		case MovementManager::ePathTypeLevelPath:  pc_path_type = "Level_Path";  break;
	}

	movement_s.add_line("Path_Type", pc_path_type);
	if ( movement().path_type() == MovementManager::ePathTypePatrolPath ) 
	{
		movement_s.add_line("Path_Name", *movement().patrol().path_name());
		movement_s.add_line("Completed",  movement().patrol().completed());

		movement_s.add_line("Current_Point", movement().patrol().get_current_point_index());
		if	( movement().patrol().get_path() && 
			  movement().patrol().get_path()->vertex(movement().patrol().get_current_point_index()) )
		{
			movement_s.add_line("Extrapolate", movement().patrol().extrapolate_path());
		}
		else
		{
			movement_s.add_line("Extrapolate", "unknown");
		}
	}

	if ( movement().path_type() == MovementManager::ePathTypeGamePath ) 
	{
		movement_s.add_line("Completed", movement().game_path().completed());
		movement_s.add_line("Path_Size", movement().game_path().path().size());
		movement_s.add_line("Current_Point", movement().game_path().intermediate_index());
	}

	TextTree& level_s = movement_s.add_line("Level");

	level_s.add_line("Path_Size", movement().level_path().path().size());
	level_s.add_line("Start_Vertex", movement().level_path().path().empty() ? -1 : movement().level_path().path().front());
	level_s.add_line("End_Vertex", movement().level_path().path().empty() ? -1 : movement().level_path().path().back());

	if ( !movement().detail().path().empty() ) 
	{
		TextTree& detail_s = movement_s.add_line("Detail");

		detail_s.add_line("Velocities", movement().detail().velocities().size());
		detail_s.add_line("Extrapolate", movement().detail().extrapolate_length());
		detail_s.add_line("Path_Size", movement().detail().path().size());

		detail_s.add_line("Start_Point").add_line(movement().detail().path().front().position);
		detail_s.add_line("Dest_Point").add_line(movement().detail().path().back().position);
		TextTree& current_point_s = detail_s.add_line("Current_Point");
		current_point_s.add_line("Index", movement().detail().curr_travel_point_index());
		current_point_s.add_line("Position").add_line(movement().detail().path()[movement().detail().curr_travel_point_index()].position);

		CDetailPathManager::STravelParams current_velocity = 
			movement().detail().velocity(movement().detail().path()[movement().detail().curr_travel_point_index()].velocity);
		detail_s.add_line("linear", current_velocity.linear_velocity);
		detail_s.add_line("angular", rad2deg(current_velocity.real_angular_velocity));
		detail_s.add_line("speed(calc)", movement().speed());
		detail_s.add_line("speed(physics)", movement().speed(character_physics_support()->movement()));
	}

	if ( movement().detail().use_dest_orientation() )
	{
		movement_s.add_line("Orientation", movement().detail().dest_direction());
	}
	else
	{
		movement_s.add_line("Orientation", "no");
	}
	
	TextTree& atackdist_s = controller_s.find_or_add("Attack_Distance");
	atackdist_s.add_line("Mind_Dist",  make_xrstr("%.3f", MeleeChecker.get_min_distance()));
	atackdist_s.add_line("Max_Dist",  make_xrstr("%.3f", MeleeChecker.get_max_distance()));
	atackdist_s.add_line("As_Step",  make_xrstr("%.3f", MeleeChecker.dbg_as_step()));
	atackdist_s.add_line("As_MinDist",  make_xrstr("%.3f", MeleeChecker.dbg_as_min_dist()));

	TextTree& restrictions_s = movement_s.add_line("Restrictions");

	if	( movement().restrictions().out_restrictions().size() ||
		  movement().restrictions().in_restrictions().size() ||
		  movement().restrictions().base_out_restrictions().size() ||
		  movement().restrictions().base_in_restrictions().size() )
	{
		detail::add_debug_info_restrictions(restrictions_s.add_line("out"), *movement().restrictions().out_restrictions());
		detail::add_debug_info_restrictions(restrictions_s.add_line("in"), *movement().restrictions().in_restrictions());
		detail::add_debug_info_restrictions(restrictions_s.add_line("base_out"), *movement().restrictions().base_out_restrictions());
		detail::add_debug_info_restrictions(restrictions_s.add_line("base_in"), *movement().restrictions().base_in_restrictions());

		restrictions_s.add_line("Actor_Accessible?", actor ?
			movement().restrictions().accessible(actor->Position()) : false);
	}
	else
	{
		restrictions_s.add_text("-");
	}

	//-----------------------------------------------
	// Sound Player
	//-----------------------------------------------
	TextTree& sound_player_s = controller_s.find_or_add("Sound_Player");
	sound_player_s.add_line("Num_Sounds", sound().objects().size());

	typedef CSoundPlayer::SOUND_COLLECTIONS::const_iterator SoundIterator;

	u32 object_count = 0;
	for ( SoundIterator i=sound().objects().begin(), e=sound().objects().end();
		  i!=e; ++i )
	{
		object_count += (*i).second.second->m_sounds.size();
	}

	TextTree& now_playing_s = sound_player_s.add_line("Objects", object_count);

	typedef xr_vector<CSoundPlayer::CSoundSingle>::const_iterator SoundSingleIterator;

	index = 1;
	for ( SoundSingleIterator i=sound().playing_sounds().begin(), 
		                      e=sound().playing_sounds().end();
		  i!=e; ++i )
	{
		xr_string source = (*i).m_sound->_handle() ? (*i).m_sound->_handle()->file_name() : "no source";

		xr_string status = "not yet started";
		if ( Device.dwTimeGlobal >= (*i).m_start_time )
		{
			status = (*i).m_sound->_feedback() ? "playing" : "already played";
		}

		TextTree& current_sound_s = now_playing_s.add_line(make_xrstr("Sound %i", index++));
		current_sound_s.add_line(source);
		current_sound_s.add_line(status);
	}
}
Exemplo n.º 11
0
void CGameObject::spawn_supplies()
{
	if (!spawn_ini() || ai().get_alife())
		return;

	if (!spawn_ini()->section_exist("spawn"))
		return;

	LPCSTR					N,V;
	float					p;
	bool bScope				=	false;
	bool bSilencer			=	false;
	bool bLauncher			=	false;

	for (u32 k = 0, j; spawn_ini()->r_line("spawn",k,&N,&V); k++) {
		VERIFY				(xr_strlen(N));
		j					= 1;
		p					= 1.f;
		
		float f_cond						= 1.0f;
		if (V && xr_strlen(V)) {
			int				n = _GetItemCount(V);
			string16		temp;
			if (n > 0)
				j			= atoi(_GetItem(V,0,temp)); //count
			
			if(NULL!=strstr(V,"prob="))
				p			=(float)atof(strstr(V,"prob=")+5);
			if (fis_zero(p))p = 1.f;
			if (!j)	j		= 1;
			if(NULL!=strstr(V,"cond="))
				f_cond		= (float)atof(strstr(V,"cond=")+5);
			bScope			=	(NULL!=strstr(V,"scope"));
			bSilencer		=	(NULL!=strstr(V,"silencer"));
			bLauncher		=	(NULL!=strstr(V,"launcher"));

		}
		for (u32 i=0; i<j; ++i)
			if (::Random.randF(1.f) < p){
				CSE_Abstract* A=Level().spawn_item	(N,Position(),ai_location().level_vertex_id(),ID(),true);

				CSE_ALifeInventoryItem*	pSE_InventoryItem = smart_cast<CSE_ALifeInventoryItem*>(A);
				if(pSE_InventoryItem)
						pSE_InventoryItem->m_fCondition = f_cond;

				CSE_ALifeItemWeapon* W =  smart_cast<CSE_ALifeItemWeapon*>(A);
				if (W) {
					if (W->m_scope_status			== ALife::eAddonAttachable)
						W->m_addon_flags.set(CSE_ALifeItemWeapon::eWeaponAddonScope, bScope);
					if (W->m_silencer_status		== ALife::eAddonAttachable)
						W->m_addon_flags.set(CSE_ALifeItemWeapon::eWeaponAddonSilencer, bSilencer);
					if (W->m_grenade_launcher_status == ALife::eAddonAttachable)
						W->m_addon_flags.set(CSE_ALifeItemWeapon::eWeaponAddonGrenadeLauncher, bLauncher);
				}

				NET_Packet					P;
				A->Spawn_Write				(P,TRUE);
				Level().Send				(P,net_flags(TRUE));
				F_entity_Destroy			(A);
		}
	}
}
Exemplo n.º 12
0
BOOL CGameObject::net_Spawn		(CSE_Abstract*	DC)
{
	VERIFY							(!m_spawned);
	m_spawned						= true;
	m_spawn_time					= Device.dwFrame;
	m_ai_obstacle					= xr_new<ai_obstacle>(this);

	CSE_Abstract					*E = (CSE_Abstract*)DC;
	VERIFY							(E);

	const CSE_Visual				*visual	= smart_cast<const CSE_Visual*>(E);
	if (visual) {
		cNameVisual_set				(visual_name(E));
		if (visual->flags.test(CSE_Visual::flObstacle)) {
			ISpatial				*self = smart_cast<ISpatial*>(this);
			self->spatial.type		|=	STYPE_OBSTACLE;
		}
	}

	// Naming
	cName_set						(E->s_name);
	cNameSect_set					(E->s_name);
	if (E->name_replace()[0])
		cName_set					(E->name_replace());
	bool demo_spectator = false;
	
	if (Level().IsDemoPlayStarted() && E->ID == u16(-1))
	{
		Msg("* Spawning demo spectator ...");
		demo_spectator = true;
	} else {
		R_ASSERT(Level().Objects.net_Find(E->ID) == NULL);
	}


	setID							(E->ID);
//	if (GameID() != eGameIDSingle)
//		Msg ("CGameObject::net_Spawn -- object %s[%x] setID [%d]", *(E->s_name), this, E->ID);
	
	// XForm
	XFORM().setXYZ					(E->o_Angle);
	Position().set					(E->o_Position);
#ifdef DEBUG
	if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0)
	{
		Msg("CGameObject::net_Spawn obj %s Position set from CSE_Abstract %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z);
	}
#endif
	VERIFY							(_valid(renderable.xform));
	VERIFY							(!fis_zero(DET(renderable.xform)));
	CSE_ALifeObject					*O = smart_cast<CSE_ALifeObject*>(E);
	if (O && xr_strlen(O->m_ini_string)) {
#pragma warning(push)
#pragma warning(disable:4238)
		m_ini_file					= xr_new<CInifile>(
			&IReader				(
				(void*)(*(O->m_ini_string)),
				O->m_ini_string.size()
			),
			FS.get_path("$game_config$")->m_Path
		);
#pragma warning(pop)
	}

	m_story_id						= ALife::_STORY_ID(-1);
	if (O)
		m_story_id					= O->m_story_id;

	// Net params
	setLocal						(E->s_flags.is(M_SPAWN_OBJECT_LOCAL));
	if (Level().IsDemoPlay()) //&& OnClient())
	{
		if (!demo_spectator)
		{
			setLocal(FALSE);
		}
	};

	setReady						(TRUE);
	if (!demo_spectator)
		g_pGameLevel->Objects.net_Register	(this);

	m_server_flags.one				();
	if (O) {
		m_server_flags					= O->m_flags;
		if (O->m_flags.is(CSE_ALifeObject::flVisibleForAI))
			spatial.type				|= STYPE_VISIBLEFORAI;
		else
			spatial.type				= (spatial.type | STYPE_VISIBLEFORAI) ^ STYPE_VISIBLEFORAI;
	}

	reload						(*cNameSect());
	if(!g_dedicated_server)
		CScriptBinder::reload	(*cNameSect());
	
	reinit						();
	if(!g_dedicated_server)
		CScriptBinder::reinit	();
#ifdef DEBUG
	if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0)
	{
		Msg("CGameObject::net_Spawn obj %s After Script Binder reinit %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z);
	}
#endif
	//load custom user data from server
	if(!E->client_data.empty())
	{	
//		Msg				("client data is present for object [%d][%s], load is processed",ID(),*cName());
		IReader			ireader = IReader(&*E->client_data.begin(), E->client_data.size());
		net_Load		(ireader);
	}
	else {
//		Msg				("no client data for object [%d][%s], load is skipped",ID(),*cName());
	}

	// if we have a parent
	if ( ai().get_level_graph() ) {
		if ( E->ID_Parent == 0xffff ) {
			CSE_ALifeObject* l_tpALifeObject	= smart_cast<CSE_ALifeObject*>(E);
			if (l_tpALifeObject && ai().level_graph().valid_vertex_id(l_tpALifeObject->m_tNodeID))
				ai_location().level_vertex		(l_tpALifeObject->m_tNodeID);
			else {
				CSE_Temporary* l_tpTemporary	= smart_cast<CSE_Temporary*>	(E);
				if (l_tpTemporary && ai().level_graph().valid_vertex_id(l_tpTemporary->m_tNodeID))
					ai_location().level_vertex	(l_tpTemporary->m_tNodeID);
			}

			if (l_tpALifeObject && ai().game_graph().valid_vertex_id(l_tpALifeObject->m_tGraphID))
				ai_location().game_vertex		(l_tpALifeObject->m_tGraphID);

			validate_ai_locations				(false);

			// validating position
			if	(
					UsedAI_Locations() && 
					ai().level_graph().inside(
						ai_location().level_vertex_id(),
						Position()
					) &&
					can_validate_position_on_spawn()
				)
				Position().y					= EPS_L + ai().level_graph().vertex_plane_y(*ai_location().level_vertex(),Position().x,Position().z);
		}
		else {
			CSE_ALifeObject* const alife_object	= smart_cast<CSE_ALifeObject*>(E);
			if ( alife_object && ai().level_graph().valid_vertex_id(alife_object->m_tNodeID) ) {
				ai_location().level_vertex		(alife_object->m_tNodeID);
				ai_location().game_vertex		(alife_object->m_tGraphID);
			}
		}
	}
	inherited::net_Spawn		(DC);

	m_bObjectRemoved			= false;

	spawn_supplies				();
#ifdef DEBUG
	if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0)
	{
		Msg("CGameObject::net_Spawn obj %s Before CScriptBinder::net_Spawn %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z);
	}
	BOOL ret =CScriptBinder::net_Spawn(DC);
#else
	return						(CScriptBinder::net_Spawn(DC));
#endif

#ifdef DEBUG
	if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0)
	{
		Msg("CGameObject::net_Spawn obj %s Before CScriptBinder::net_Spawn %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z);
	}
	return ret;
#endif
}
Exemplo n.º 13
0
void CBaseMonster::update_pos_by_grouping_behaviour ()
{
	if ( !m_grouping_behaviour )
	{
		return;
	}

	Fvector acc = get_steer_manager()->calc_acceleration();

	acc.y = 0; // remove vertical component

	if ( !m_last_grouping_behaviour_update_tick )
	{
		m_last_grouping_behaviour_update_tick = Device.dwTimeGlobal;
	}	

	const float dt = 0.001f * (Device.dwTimeGlobal - m_last_grouping_behaviour_update_tick);
	
	m_last_grouping_behaviour_update_tick = Device.dwTimeGlobal;

	const Fvector old_pos  = Position();
	Fvector       offs     = acc*dt;
	const float   offs_mag = magnitude(offs);

	if ( offs_mag < 0.000001f )
	{
		// too little force applied, ignore it and save cpu
		return;
	}

	// this control maximum offset
	// higher values allow stronger forces, but can lead to jingling
	const float max_offs = 0.005f;
	if ( offs_mag > max_offs )
	{
		offs.set_length(0.005f);
	}

	Fvector   new_pos    = old_pos + offs;


	const u32 old_vertex = ai_location().level_vertex_id();
	u32       new_vertex = ai().level_graph().check_position_in_direction(old_vertex, old_pos, new_pos);

	if ( !ai().level_graph().valid_vertex_id(new_vertex) )
	{
		// aiming out of ai-map, ignore
		return;
	}

	// use physics simulation to slide along obstacles
	character_physics_support()->movement()->VirtualMoveTo(new_pos, new_pos);

	if ( !ai().level_graph().valid_vertex_position(new_pos) )
	{
		// aiming out of ai-map, ignore
		return;
	}

	new_vertex = ai().level_graph().check_position_in_direction(old_vertex, old_pos, new_pos);

	if ( !ai().level_graph().valid_vertex_id(new_vertex) )
	{
		return;
	}

	// finally, new position is valid on the ai-map, we can use it
	character_physics_support()->movement()->SetPosition(new_pos);
	Position() = new_pos;
	ai_location().level_vertex(new_vertex);
}