예제 #1
0
void CollisionSystem::IncorporateEntity(std::shared_ptr<Entity> eaterEntity,
    std::shared_ptr<Entity> eatableEntity)
{
    LOG_D("[CollisionSystem] Entity " << eaterEntity->GetId()
        << " is incorporating entity " << eatableEntity->GetId());

    auto spriteComponent = std::static_pointer_cast<SpriteComponent>(
        Engine::GetInstance().GetSingleComponentOfClass(
            eatableEntity, "SpriteComponent"));
    auto complexityComponent = std::static_pointer_cast<ComplexityComponent>(
        Engine::GetInstance().GetSingleComponentOfClass(eaterEntity, "ComplexityComponent"));

    auto maxComplexity = complexityComponent->GetMaxComplexity();
    auto complexity = complexityComponent->GetComplexity();

    if (complexity < maxComplexity)
    {
        complexity += 1;

        Vector position;
        position.SetPolar(50, 2*M_PI*complexity/maxComplexity);
        
        complexityComponent->SetComplexity(complexity);
        spriteComponent->SetPosition(position);
        Engine::GetInstance().AddComponent(spriteComponent, eaterEntity);

        DestroyEntity(eatableEntity);
    }
}
예제 #2
0
//Removes deleted entities from the entity map every frame
void EntityManager::EntityCleanup()
{
	if( m_EntityMap.empty() )
		return;
	//EntityMap is a typedef std::map<int, Entity*> EntityMap;
	EntityMap::iterator iter = m_EntityMap.begin();

	while( iter != m_EntityMap.end() ) 
	{
		//Check if it's marked to be deleted
		if( iter->second->isThisMarked() )
		{
			EntityMap::iterator iter2 = iter;

			//Removes children from parent that will be deleted. They are marked for deletion
			//In the markfordeletion function, then they each go through this process as parents. 
			//Therefore, this effectively works :D
			if( iter->second->parent )
				iter->second->parent->children.remove(iter->second);
			++iter;

			Entity *toDel = iter2->second;
			m_EntityMap.erase(iter2);
			DestroyEntity(toDel);
			
		}
		else
			++iter;
	}
}
예제 #3
0
void CPerPlayerEntity::UpdatePerPlayer()
{
    if (m_PlayersAdded.empty() && m_PlayersRemoved.empty())            // This check reduces cpu usage when loading large maps (due to recursion)
        return;

    // Remove entries that match in both added and removed lists
    RemoveIdenticalEntries(m_PlayersAdded, m_PlayersRemoved);

    // Delete us for every player in our deleted list
    std::set<CPlayer*>::const_iterator iter = m_PlayersRemoved.begin();
    for (; iter != m_PlayersRemoved.end(); iter++)
    {
        DestroyEntity(*iter);
    }

    // Add us for every player in our added list
    iter = m_PlayersAdded.begin();
    for (; iter != m_PlayersAdded.end(); iter++)
    {
        CreateEntity(*iter);
    }

    // Clear both lists
    m_PlayersAdded.clear();
    m_PlayersRemoved.clear();
}
예제 #4
0
//------------------------------------------------------------------------
CVehiclePartEntity::~CVehiclePartEntity()
{
	SafeRemoveBuddyConstraint();
	DestroyEntity();

	m_pVehicle->UnregisterVehicleEventListener(this);
}
예제 #5
0
	void Game::CleanEntities()
	{
		auto iter = std::find_if(m_entities.begin(), m_entities.end(),
			[&](Asteroids::Entity* actor) { return actor->IsColliding() || actor->IsDisappearing(); });
		if (iter != m_entities.end())
		{
			DestroyEntity(*iter);
		}
	}
예제 #6
0
void CGameServer::Delete(CBaseEntity* pEntity)
{
	TAssert(GameNetwork()->IsHost() || IsLoading());
	if (!(GameNetwork()->IsHost() || IsLoading()))
		TMsg("WARNING: CGameServer::Delete() when not host or not loading.\n");

	if (GameNetwork()->IsHost())
		GameNetwork()->CallFunction(NETWORK_TOCLIENTS, "DestroyEntity", pEntity->GetHandle());

	CNetworkParameters p;
	p.i1 = (int)pEntity->GetHandle();
	DestroyEntity(CONNECTION_GAME, &p);
}
예제 #7
0
void CollisionSystem::CombatEntities(std::shared_ptr<Entity> entity1,
        std::shared_ptr<Entity> entity2)
{
    auto combatComponent1 = std::static_pointer_cast<CombatComponent>(Engine::GetInstance().GetSingleComponentOfClass(entity1, "CombatComponent"));
    auto combatComponent2 = std::static_pointer_cast<CombatComponent>(Engine::GetInstance().GetSingleComponentOfClass(entity2, "CombatComponent"));

    int power1 = combatComponent1->GetPower();
    int power2 = combatComponent2->GetPower();

    LOG_D("[CollisionSystem] Combat between entity " << entity1->GetId()
        << " and " << entity2->GetId());

    if (power1 > power2)
    {
        LOG_D("[CollisionSystem] Entity " << entity1->GetId()
            << " wins the combat");

        if (Engine::GetInstance().HasComponent(entity1, "GrowthComponent"))
            EatEntity(entity1, entity2);
        else
            DestroyEntity(entity2);
    }
    else if (power2 > power1)
    {
        LOG_D("[CollisionSystem] Entity " << entity2->GetId()
            << " wins the combat");

        if (Engine::GetInstance().HasComponent(entity2, "GrowthComponent"))
            EatEntity(entity2, entity1);
        else
            DestroyEntity(entity1);
    }
    else
    {
        LOG_D("[CollisionSystem] Tied combat");
        CollideBodies(entity1, entity2);
    }
}
예제 #8
0
void EntityManager::EmptyEntityList(void)
{
	if( m_EntityMap.empty() )
		return;
	EntityMap::iterator iter = m_EntityMap.begin();
	// Note: Deletion of components taken care of by engines.


	while( iter != m_EntityMap.end() )
	{
		
		DestroyEntity(iter->second);
	}

	m_EntityMap.clear();
}
// Call all entity update functions. Pass the time since last update
void CEntityManager::UpdateAllEntities( float updateTime )
{
	TUInt32 entity = 0;
	while (entity < m_Entities.size())
	{
		// Update entity, if it returns false, then destroy it
		if (!m_Entities[entity]->Update( updateTime ))
		{
			DestroyEntity(m_Entities[entity]->GetUID());
		}
		else
		{
			++entity;
		}
	}
}
예제 #10
0
bool CPerPlayerEntity::Sync(bool bSync)
{
    // Are we getting synced but not already synced or vice versa?
    if (bSync != m_bIsSynced)
    {
        // Create it for everyone we're visible if it's synced, otherwise destroy
        if (bSync)
        {
            m_bIsSynced = true;
            CreateEntity(NULL);
        }
        else
        {
            DestroyEntity(NULL);
            m_bIsSynced = false;
        }
    }

    return true;
}
예제 #11
0
void CollisionSystem::EatEntity(std::shared_ptr<Entity> eaterEntity,
    std::shared_ptr<Entity> eatableEntity)
{
    LOG_D("[CollisionSystem] Entity " << eaterEntity->GetId() << " is eating entity " << eatableEntity->GetId());

    if (Engine::GetInstance().HasComponent(eaterEntity, "InfectionComponent"))
    {
        auto infectionComponent = std::static_pointer_cast<InfectionComponent>(Engine::GetInstance().GetSingleComponentOfClass(eaterEntity, "InfectionComponent"));

        if (infectionComponent->GetInfectionType() == CannotEat)
            return;
    }

    auto growthComponent = std::static_pointer_cast<GrowthComponent>(Engine::GetInstance().GetSingleComponentOfClass(eaterEntity, "GrowthComponent"));
    auto energy = growthComponent->GetEnergy();
    ++energy;
    growthComponent->SetEnergy(energy);
    DestroyEntity(eatableEntity);

    Engine::GetInstance().PlaySoundEffect(CFG_GETP("EAT_SOUND_EFFECT"));
}
예제 #12
0
Treenity::Treenity(QWidget *parent)
	: QMainWindow(parent), m_running(true)
{
	//Set some utility init things
	Utils::GetInstance()->setParent(this);
	Utils::GetInstance()->setFloating(true);

	// Setup component names in the editor.
	m_componentNames[RootForce::ComponentType::RENDERABLE]			= "Renderable";
	m_componentNames[RootForce::ComponentType::TRANSFORM]			= "Transform";
	m_componentNames[RootForce::ComponentType::POINTLIGHT]			= "Point Light";
	m_componentNames[RootForce::ComponentType::CAMERA]				= "Camera";
	m_componentNames[RootForce::ComponentType::HEALTH]				= "Health";
	m_componentNames[RootForce::ComponentType::PLAYERCONTROL]		= "Player Control";
	m_componentNames[RootForce::ComponentType::PHYSICS]				= "Physics";
	m_componentNames[RootForce::ComponentType::NETWORK]				= "Network";
	m_componentNames[RootForce::ComponentType::LOOKATBEHAVIOR]		= "Look-At Behaviour";
	m_componentNames[RootForce::ComponentType::THIRDPERSONBEHAVIOR] = "Third Person Behaviour";
	m_componentNames[RootForce::ComponentType::SCRIPT]				= "Script";
	m_componentNames[RootForce::ComponentType::COLLISION]			= "Physics";	// Required since the component list searches on name.
	m_componentNames[RootForce::ComponentType::COLLISIONRESPONDER]	= "Collision Responder";
	m_componentNames[RootForce::ComponentType::PLAYER]				= "Player";
	m_componentNames[RootForce::ComponentType::ANIMATION]			= "Animation";
	m_componentNames[RootForce::ComponentType::PARTICLE]			= "Particle";
	m_componentNames[RootForce::ComponentType::TDMRULES]			= "Team-Deathmatch Rules";
	m_componentNames[RootForce::ComponentType::PLAYERACTION]		= "Player Action";
	m_componentNames[RootForce::ComponentType::PLAYERPHYSICS]		= "Player Physics";
	m_componentNames[RootForce::ComponentType::ENTITYSTATE]			= "Entity State";
	m_componentNames[RootForce::ComponentType::SHADOWCASTER]		= "Shadowcaster";
	m_componentNames[RootForce::ComponentType::DIRECTIONALLIGHT]	= "Directional Light";
	m_componentNames[RootForce::ComponentType::SERVERINFORMATION]	= "Server Information";
	m_componentNames[RootForce::ComponentType::CLIENT]				= "Client";
	m_componentNames[RootForce::ComponentType::RAGDOLL]				= "Ragdoll";
	m_componentNames[RootForce::ComponentType::WATERCOLLIDER]		= "Water Collider";
	m_componentNames[RootForce::ComponentType::ABILITYSPAWN]		= "Ability Spawn";
	m_componentNames[RootForce::ComponentType::TRYPICKUPCOMPONENT]	= "Try Pickup";
	m_componentNames[RootForce::ComponentType::SOUND]				= "Sound";
	m_componentNames[RootForce::ComponentType::TIMER]				= "Timer";
	m_componentNames[RootForce::ComponentType::FOLLOW]				= "Follow";
	m_componentNames[RootForce::ComponentType::HOMING]				= "Homing";
	m_componentNames[RootForce::ComponentType::RAY]					= "Ray";
	m_componentNames[RootForce::ComponentType::DAMAGEANDKNOCKBACK]	= "Damage and Knockback";
	m_componentNames[RootForce::ComponentType::SCALABLE]			= "Scalable";
	m_componentNames[RootForce::ComponentType::STATCHANGE]			= "Stat Change";
	m_componentNames[RootForce::ComponentType::KILLANNOUNCEMENT]	= "Kill Announcement";
	m_componentNames[RootForce::ComponentType::CONTROLLERACTIONS]	= "Controller Action";

	// Setup the main UI.
	ui.setupUi(this);

	setCorner( Qt::TopRightCorner, Qt::RightDockWidgetArea );
	setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea );

	m_compView = new ComponentView();
	m_scrollArea = new VerticalScrollArea();
	m_scrollArea->setWidget(m_compView);
	m_scrollArea->setFrameStyle(QFrame::Plain);
	// Setup the component view and its items.
	
	ui.verticalLayout->addWidget(m_scrollArea);
	m_componentViews[RootForce::ComponentType::TRANSFORM]			= new TransformView();
	m_componentViews[RootForce::ComponentType::RENDERABLE]			= new RenderableView();	
	m_componentViews[RootForce::ComponentType::COLLISION]			= new PhysicsView();
	m_componentViews[RootForce::ComponentType::WATERCOLLIDER]		= new WaterColliderView();
	m_componentViews[RootForce::ComponentType::SCRIPT]				= new ScriptView();
	m_componentViews[RootForce::ComponentType::COLLISIONRESPONDER]	= new CollisionResponderView();
	m_componentViews[RootForce::ComponentType::PARTICLE]			= new ParticleView();

	// Block component views from updates while in game mode.
	m_componentViews[RootForce::ComponentType::RENDERABLE]->SetReceiveUpdates(false);

	for (auto it : m_componentViews)
	{
		it.second->SetEditorInterface(this);
	}
	
	ui.treeView_entityOutliner->SetEditorInterface(this);

	//Set up water tool
	m_waterToolDockable = new WaterTool(this);

	// Match signals with slots.
	connect(ui.actionNew,							SIGNAL(triggered()),		this,					SLOT(New()));
	connect(ui.actionOpen_Project,					SIGNAL(triggered()),		this,					SLOT(OpenProject()));
	connect(ui.action_saveAs,						SIGNAL(triggered()),		this,					SLOT(SaveAs()));
	connect(ui.action_save,							SIGNAL(triggered()),		this,					SLOT(Save()));
	connect(ui.actionExit,							SIGNAL(triggered()),		this,					SLOT(close()));
	connect(ui.actionLog,							SIGNAL(triggered()),		Utils::GetInstance(),	SLOT(Show()));
	connect(ui.action_addEntity,					SIGNAL(triggered()),		this,					SLOT(CreateEntity()));
	connect(ui.action_removeEntity,					SIGNAL(triggered()),		this,					SLOT(DestroyEntity()));
	connect(ui.lineEdit_entityName,					SIGNAL(editingFinished()),	this,					SLOT(RenameEntity()));
	connect(ui.action_addRenderable,				SIGNAL(triggered()),		this,					SLOT(AddRenderable()));
	connect(ui.action_addPhysics,					SIGNAL(triggered()),		this,					SLOT(AddPhysics()));
	connect(ui.action_addWaterCollider,				SIGNAL(triggered()),		this,					SLOT(AddWaterCollider()));
	connect(ui.action_addScript,					SIGNAL(triggered()),		this,					SLOT(AddScriptComponent()));
	connect(ui.action_collisionResponder,			SIGNAL(triggered()),		this,					SLOT(AddCollisionResponder()));
	connect(ui.action_addParticle,					SIGNAL(triggered()),		this,					SLOT(AddParticleComponent()));
	connect(ui.actionPlay,							SIGNAL(triggered()),		this,					SLOT(Play()));
	connect(ui.pushButton_translateMode,			SIGNAL(clicked()),			this,					SLOT(SetTranslateTool()));
	connect(ui.pushButton_rotateMode,				SIGNAL(clicked()),			this,					SLOT(SetRotateTool()));
	connect(ui.pushButton_scaleMode,				SIGNAL(clicked()),			this,					SLOT(SetResizeTool()));
	connect(ui.comboBox_mode,						SIGNAL(currentIndexChanged(int)), this,				SLOT(ChangeToolMode(int)));
	connect(ui.actionWaterSetting,					SIGNAL(triggered()),		m_waterToolDockable,	SLOT(Show()));

	connect(m_componentViews[RootForce::ComponentType::RENDERABLE],			SIGNAL(deleted(ECS::Entity*)), this, SLOT(RemoveRenderable(ECS::Entity*)));
	connect(m_componentViews[RootForce::ComponentType::COLLISION],			SIGNAL(deleted(ECS::Entity*)), this, SLOT(RemovePhysics(ECS::Entity*))); 
	connect(m_componentViews[RootForce::ComponentType::WATERCOLLIDER],		SIGNAL(deleted(ECS::Entity*)), this, SLOT(RemoveWaterCollider(ECS::Entity*))); 
	connect(m_componentViews[RootForce::ComponentType::SCRIPT],				SIGNAL(deleted(ECS::Entity*)), this, SLOT(RemoveScriptComponent(ECS::Entity*))); 
	connect(m_componentViews[RootForce::ComponentType::COLLISIONRESPONDER], SIGNAL(deleted(ECS::Entity*)), this, SLOT(RemoveCollisionResponder(ECS::Entity*))); 

	// Setup Qt-to-SDL keymatching.
	InitialiseKeymap();

	ui.widget_canvas3D->SetEditorInterface(this);
	// Set tool mode.
	m_toolMode = ToolMode::LOCAL;
}
예제 #13
0
bool CollisionSystem::TransmitInfection(std::shared_ptr<Entity> transmitterEntity,
    std::shared_ptr<Entity> receiverEntity)
{
    auto transmitterInfectionComponent = std::static_pointer_cast<InfectionComponent>(Engine::GetInstance().GetSingleComponentOfClass(transmitterEntity, "InfectionComponent"));
    auto receiverInfectionComponent = std::static_pointer_cast<InfectionComponent>(Engine::GetInstance().GetSingleComponentOfClass(receiverEntity, "InfectionComponent"));

    // Only transmit to healthy entities
    if (receiverInfectionComponent->GetInfectionType() != NoInfection)
        return false;

    if (transmitterInfectionComponent->GetTransmissible())
    {
        receiverInfectionComponent->SetInfectionType(
            transmitterInfectionComponent->GetInfectionType());

        // Avoid epidemies by blocking further transmissions
        receiverInfectionComponent->SetTransmissible(false);
        receiverInfectionComponent->SetRemainingTime(
            transmitterInfectionComponent->GetRemainingTime());
        receiverInfectionComponent->SetTemporary(true);

        if (transmitterInfectionComponent->GetInfectionType() == CannotInput)
        {
            if (Engine::GetInstance().HasComponent(receiverEntity, "PlayerComponent"))
                Engine::GetInstance().PlaySoundEffect(CFG_GETP("FROZEN_SOUND_EFFECT"));

            auto spriteComponents = Engine::GetInstance().GetComponentsOfClass(receiverEntity, "SpriteComponent");
            Engine::GetInstance().GetEntityManager()->DeleteComponentsOfClass(receiverEntity, "SpriteComponent");
            Engine::GetInstance().AddComponent(
            std::make_shared<SpriteComponent>(CFG_GETP("CELL_FROZEN_IMAGE"),
                Vector(0, 0), 0, 0, true,
                CFG_GETF("CELL_FROZEN_SCALE")), receiverEntity);
            for (unsigned int i = 1; i < spriteComponents.size(); ++i)
                Engine::GetInstance().AddComponent(spriteComponents[i], receiverEntity);
        }
        else if (transmitterInfectionComponent->GetInfectionType() == StrongImpulses)
        {
            if (Engine::GetInstance().HasComponent(receiverEntity, "PlayerComponent"))
                Engine::GetInstance().PlaySoundEffect(CFG_GETP("IMPULSES_SOUND_EFFECT"));

            auto spriteComponents = Engine::GetInstance().GetComponentsOfClass(receiverEntity, "SpriteComponent");
            Engine::GetInstance().GetEntityManager()->DeleteComponentsOfClass(receiverEntity, "SpriteComponent");
            Engine::GetInstance().AddComponent(
            std::make_shared<SpriteComponent>(CFG_GETP("CELL_ERRACTIC_IMAGE"),
                Vector(0, 0), 0, CFG_GETF("CELL_ERRACTIC_ROTATION_SPEED"),
                true, CFG_GETF("CELL_ERRACTIC_SCALE")), receiverEntity);
            for (unsigned int i = 1; i < spriteComponents.size(); ++i)
                Engine::GetInstance().AddComponent(spriteComponents[i], receiverEntity);
        }
        else if (transmitterInfectionComponent->GetInfectionType() == CannotEat)
        {
            if (Engine::GetInstance().HasComponent(receiverEntity, "PlayerComponent"))
                Engine::GetInstance().PlaySoundEffect(CFG_GETP("IMPULSES_SOUND_EFFECT"));

            auto spriteComponents = Engine::GetInstance().GetComponentsOfClass(receiverEntity, "SpriteComponent");
            Engine::GetInstance().GetEntityManager()->DeleteComponentsOfClass(receiverEntity, "SpriteComponent");
            Engine::GetInstance().AddComponent(
            std::make_shared<SpriteComponent>(CFG_GETP("CELL_CANNOT_EAT_IMAGE"),
                Vector(0, 0), 0, 0, true,
                CFG_GETF("CELL_CANNOT_EAT_SCALE")), receiverEntity);
            for (unsigned int i = 1; i < spriteComponents.size(); ++i)
                Engine::GetInstance().AddComponent(spriteComponents[i], receiverEntity);
        }

        DestroyEntity(transmitterEntity);
        return true;
    }

    return false;
}
예제 #14
0
//------------------------------------------------------------------------
void CVehiclePartEntity::OnVehicleEvent(EVehicleEvent event, const SVehicleEventParams &params)
{
	switch(event)
	{
		case eVE_Destroyed:
		{
			if (m_shouldDetachInsteadOfDestroy)
			{
				TryDetachPart(params);
			}
			else
			{
				DestroyEntity();
			}

			break;
		}

		case eVE_TryDetachPartEntity:
		{
			if(params.iParam == m_index)
			{
				TryDetachPart(params);
			}

			break;
		}

		case eVE_OnDetachPartEntity:
		{
			if( m_entityAttached && params.entityId	== m_entityId )
			{
				m_entityAttached = false;

				SafeRemoveBuddyConstraint();
			}

			break;
		}

		case eVE_TryAttachPartEntityNetID:
		{
			if( params.iParam == m_entityNetId && params.entityId != 0 )
			{
				//Can only attach an entity if we currently don't have one
				if( m_entityId == 0 )
				{
					if( IEntity* pEntity = gEnv->pEntitySystem->GetEntity( params.entityId ) )
					{
						m_entityId = params.entityId;
						//Create an entity link so the entity can find the Vehicle if it needs to
						m_pLink = pEntity->AddEntityLink( "VehiclePartLink", m_pVehicle->GetEntityId() );

						m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);

						pEntity->Hide(m_hidden);

						if( m_CollideWithParent == false )
						{
							m_createBuddyConstraint = true;
						}

						m_entityAttached = true;

						CryLog( "VehiclePartEntity: Successfully attached part %d to entity %d", m_index, m_entityId );
					}
				}
				else
				{
					CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CVehiclePartEntity::OnVehicleEvent trying to attach an entity but part already has one");
				}
			}

			break;
		}

		case eVE_Hide:
		{
			m_hidden = !!params.iParam;

			if(m_entityAttached)
			{
				if(IEntity *pEntity = GetPartEntity())
				{
					pEntity->Hide(m_hidden);
				}
			}

			break;
		}
	}
}