Esempio n. 1
0
void CMonsterSquadManager::update(CEntity *entity)
{
	CMonsterSquad	*squad = monster_squad().get_squad(entity);
	if (squad && squad->SquadActive() && (squad->GetLeader() == entity)) {
		squad->UpdateSquadCommands();
	}
}
Esempio n. 2
0
void CMonsterSquadManager::remove_links(CObject *O)
{
	for (u32 team_id=0; team_id<team.size();team_id++) {
		for (u32 squad_id=0; squad_id<team[team_id].size(); squad_id++) {
			for (u32 group_id=0; group_id<team[team_id][squad_id].size(); group_id++) {
				CMonsterSquad *squad = team[team_id][squad_id][group_id];
				if (squad) squad->remove_links(O);
			}
		}
	}

}
Esempio n. 3
0
void CMonsterSquadManager::register_member(u8 team_id, u8 squad_id, u8 group_id, CEntity *e)
{
	CMonsterSquad *pSquad;

	// нет team - создать team, squad и group
	if (team_id >= team.size()) { 
		team.resize							(team_id + 1);
		team[team_id].resize				(squad_id + 1);
		team[team_id][squad_id].resize		(group_id + 1);
		
		for (u32 i=0; i<group_id; i++) 	
			team[team_id][squad_id][i]		= 0;

		pSquad								= xr_new<CMonsterSquad>();
		team[team_id][squad_id][group_id]	= pSquad;

	// есть team, нет squad - создать squad
	} else if (squad_id >= team[team_id].size()) { 
		
		team[team_id].resize				(squad_id + 1);
		team[team_id][squad_id].resize		(group_id + 1);
		
		for (u32 i=0; i<group_id; i++) 	
			team[team_id][squad_id][i]		= 0;

		pSquad								= xr_new<CMonsterSquad>();
		team[team_id][squad_id][group_id]	= pSquad;

	// есть team, squad, нет group 
	} else if (group_id >= team[team_id][squad_id].size()) { 
		
		u32 prev_size						= team[team_id][squad_id].size();
		team[team_id][squad_id].resize		(group_id + 1);

		for (u32 i = prev_size; i < group_id; i++)
			team[team_id][squad_id][i]		= 0;
		
		pSquad								= xr_new<CMonsterSquad>();
		team[team_id][squad_id][group_id]	= pSquad;
	} else {
		if (team[team_id][squad_id][group_id] == 0) {
			pSquad								= xr_new<CMonsterSquad>();
			team[team_id][squad_id][group_id]	= pSquad;
		} else {
			// TODO: Verify IT!
			pSquad = team[team_id][squad_id][group_id];
		}
	}

	pSquad->RegisterMember(e);
}
void CCoverEvaluator::evaluate_cover(const CCoverPoint *cover_point, float weight)
{
#ifdef DEBUG
	//DBG().level_info(this).add_item(cover_point->position(), D3DCOLOR_XRGB(0,255,0));
#endif
	CMonsterSquad *squad = monster_squad().get_squad(m_object);
	if (squad->is_locked_cover(cover_point->level_vertex_id())) return;

	if (fis_zero(weight))
		return;

	float					dest_distance	= m_dest_position.distance_to(cover_point->position());

	if ((dest_distance <= m_min_distance) && (m_current_distance > dest_distance))
		return;

	if((dest_distance >= m_max_distance) && (m_current_distance < dest_distance))
		return;

	Fvector					direction;
	float					y,p;
	direction.sub			(m_dest_position,cover_point->position());
	direction.getHP			(y,p);

	float					high_cover_value = ai().level_graph().high_cover_in_direction(y,cover_point->level_vertex_id());
	float					low_cover_value = ai().level_graph().low_cover_in_direction(y,cover_point->level_vertex_id());
	float					cover_value = _min(high_cover_value, low_cover_value);
	float					value = cover_value;
	if (ai().level_graph().neighbour_in_direction(direction,cover_point->level_vertex_id()))
		value				+= 10.f;

	value					/= weight;

	if (value >= m_best_value)
		return;

	m_selected				= cover_point;
	m_best_value			= value;
}
Esempio n. 5
0
void CAI_Rat::set_dir()
{
	if ((Device.dwTimeGlobal - m_previous_query_time > TIME_TO_GO) || !m_previous_query_time) {
		CMonsterSquad *squad	= monster_squad().get_squad(this);
		Fvector m_enemy_position = memory().enemy().selected()->Position();
		if (squad && squad->SquadActive())
		{
			float m_delta_Angle = angle_normalize((PI * 2) / squad->squad_alife_count());
			float m_heading, m_pitch;
			Fvector m_temp, m_dest_direction;
			m_temp = squad->GetLeader()->Position();
			m_dest_direction.x = (m_temp.x - m_enemy_position.x) / m_temp.distance_to(m_enemy_position);
			m_dest_direction.y = (m_temp.y - m_enemy_position.y) / m_temp.distance_to(m_enemy_position);
			m_dest_direction.z = (m_temp.z - m_enemy_position.z) / m_temp.distance_to(m_enemy_position);
			m_dest_direction.getHP(m_heading, m_pitch);
			m_heading = angle_normalize(m_heading + m_delta_Angle * squad->get_index(this));
			m_dest_direction.setHP(m_heading, m_pitch);
			m_dest_direction.mul(0.5f);
			m_enemy_position.add(m_enemy_position,m_dest_direction);
		}

		m_tGoalDir.set(m_enemy_position);
	}
}
Esempio n. 6
0
void CAI_Rat::UpdateCL			()
{

	///////////////////////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
	if (monster_squad().get_squad(this)->GetLeader() == this) {

		if (m_walk_on_way && m_path) draw_way();

	}
#endif
	///////////////////////////////////////////////////////////////////////////////////////

	if (!m_pPhysicsShell && !g_Alive())
		CreateSkeleton			();

	if (!Useful()) {
		inherited::UpdateCL		();
		Exec_Look				(Device.fTimeDelta);

		CMonsterSquad *squad	= monster_squad().get_squad(this);

		if (squad && 
			((squad->GetLeader() != this && !squad->GetLeader()->g_Alive()) ||
			squad->get_index(this) == u32(-1))
			) squad->SetLeader(this);

		if (squad &&
			squad->SquadActive() &&
			squad->GetLeader() == this &&
			m_squad_count != squad->squad_alife_count()
			) 
		{
			squad->set_rat_squad_index(squad->GetLeader());
			m_squad_count = squad->squad_alife_count();
		}
	}
	else {
		if (!H_Parent() && m_pPhysicsShell && m_pPhysicsShell->isActive())
			m_pPhysicsShell->InterpolateGlobalTransform(&XFORM());

		CPhysicsShellHolder::UpdateCL	();
		CEatableItem::UpdateCL			();
	}
}
Esempio n. 7
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);
	}
}