Esempio n. 1
0
void BuildActionEx::HandleMessage(RtsGame& game, Message* p_msg, bool& p_consumed)
{
    if(PlanStepEx::State() == ESTATE_Executing && p_msg->MessageTypeID() == MSG_EntityCreate) 
    {
        EntityCreateMessage* pMsg = static_cast<EntityCreateMessage*>(p_msg);
        TID buildingId;
        GameEntity *pGameBuilding;
        Vector2 msgBuildPosition;

        if (pMsg->Data()->OwnerId != PLAYER_Self)
            return;

        assert(pMsg && pMsg->Data());
        buildingId = pMsg->Data()->EntityId;

        pGameBuilding = game.Self()->GetEntity(buildingId);
        assert(pGameBuilding);

        msgBuildPosition.X = pMsg->Data()->X;
        msgBuildPosition.Y = pMsg->Data()->Y;

        if (msgBuildPosition.X == _buildArea.Pos().X &&
            msgBuildPosition.Y == _buildArea.Pos().Y &&
            pGameBuilding->Type() == _params[PARAM_EntityClassId])
        {
            _buildingId = pGameBuilding->Id();
            _buildStarted = true;
            assert(!_requiredResources.IsNull());
            _requiredResources.Unlock(this);
        }
    }
}
Esempio n. 2
0
//-------------------------`---------------------------------------------------------------------
void BuildActionEx::HandleMessage(Message* p_pMsg, bool& p_consumed)
{
	if(State() == ESTATE_Executing && p_pMsg->MessageTypeID() == MSG_EntityCreate) 
	{
		EntityCreateMessage* pMsg = static_cast<EntityCreateMessage*>(p_pMsg);
		TID	buildingId;
		GameEntity	*pGameBuilding;
		Vector2		msgBuildPosition;

		if (pMsg->Data()->OwnerId != PLAYER_Self)
			return;

		assert(pMsg && pMsg->Data());
		buildingId = pMsg->Data()->EntityId;

		pGameBuilding = g_Game->Self()->GetEntity(buildingId);
		assert(pGameBuilding);

		msgBuildPosition.X = pMsg->Data()->X;
		msgBuildPosition.Y = pMsg->Data()->Y;

		if (msgBuildPosition.X == _buildPosition.X &&
			msgBuildPosition.Y == _buildPosition.Y)
		{
			_buildingId = pGameBuilding->Id();
			_buildStarted = true;
		}
	}
}
void GamePlayer::OnEntityCreate(Message* p_pMessage)
{
    GameEntity *pEntity = nullptr;
    TID entityId;
    EntityCreateMessage *pCreateMsg = nullptr;

    pCreateMsg = (EntityCreateMessage*)p_pMessage;

    if (pCreateMsg->Data()->OwnerId == m_id)
    {
        entityId = pCreateMsg->Data()->EntityId;

        if (m_entities.Contains(entityId))
        {
            LogError("Entity %d already exist in Player %s units", entityId, Enums[m_id]);
            return;
        }

        pEntity = FetchEntity(entityId);
        assert(pEntity);
        
        m_entities[entityId] = pEntity;

        LogInfo("[%s] Unit '%s':%d created at <%d, %d>",
            Enums[m_id], Enums[pEntity->Type()], pEntity->Id(), pEntity->Attr(EOATTR_PosX), pEntity->Attr(EOATTR_PosY));

        g_IMSysMgr.RegisterGameObj(entityId, pCreateMsg->Data()->OwnerId);
    }

}
Esempio n. 4
0
//----------------------------------------------------------------------------------------------
void TrainAction::HandleMessage(RtsGame& game, Message* pMsg, bool& consumed)
{
    if (PlanStepEx::State() == ESTATE_Executing && pMsg->MessageTypeID() == MSG_EntityCreate)
    {
        EntityCreateMessage* pEntityMsg = static_cast<EntityCreateMessage*>(pMsg);
        _ASSERTE(pEntityMsg && pEntityMsg->Data());

        if (pEntityMsg->Data()->OwnerId != PLAYER_Self)
            return;

        TID entityId = pEntityMsg->Data()->EntityId;
        GameEntity *pEntity = game.Self()->GetEntity(entityId);
        _ASSERTE(pEntity);

        // We are interested only in free trainees that have not been locked before
        if (!m_trainStarted &&
			m_traineeId == INVALID_TID &&
			pEntity->Type() == _params[PARAM_EntityClassId] &&
            !pEntity->IsLocked())
        {
            // Check if the trainer is training that entity
            GameEntity* pTrainer = game.Self()->GetEntity(m_trainerId);
            _ASSERTE(pTrainer);

            if (pTrainer->IsTraining(entityId))
            {
                m_trainStarted = true;
                m_traineeId = entityId;

                m_pTrainee = pEntity;

                // Lock that trainee and bound it to this action because if we don't
                // other ready actions in the same update cycle will receive the same message
                // and they may bind to the same trainee
                pEntity->Lock(this);
                consumed = true;
                LogInfo("Action %s has bound trainee=%d to trainer=%d", ToString().c_str(), m_traineeId, m_trainerId);
            }
        }
    }
}
Esempio n. 5
0
void BuildActionEx::HandleMessage(RtsGame& game, Message* p_msg, bool& p_consumed)
{
    if (PlanStepEx::GetState() == ESTATE_Executing &&
        (p_msg->TypeId() == MSG_EntityCreate ||
        p_msg->TypeId() == MSG_EntityRenegade))
    {
        EntityCreateMessage* pMsg = static_cast<EntityCreateMessage*>(p_msg);
        TID buildingId;
        GameEntity *pGameBuilding;
        Vector2 msgBuildPosition;

        if (pMsg->Data()->OwnerId != PLAYER_Self)
            return;

        _ASSERTE(pMsg && pMsg->Data());
        buildingId = pMsg->Data()->EntityId;

        pGameBuilding = game.Self()->GetEntity(buildingId);
        _ASSERTE(pGameBuilding);

        msgBuildPosition.X = pMsg->Data()->X;
        msgBuildPosition.Y = pMsg->Data()->Y;

        if (pGameBuilding->TypeId() == _params[PARAM_EntityClassId] &&
            ((msgBuildPosition.X == _buildArea.Pos().X && msgBuildPosition.Y == _buildArea.Pos().Y) ||
            game.GetEntityType(pGameBuilding->TypeId())->P(TP_IsSpecialBuilding)))
        {
            _buildingId = pGameBuilding->Id();
            _buildStarted = true;
            _ASSERTE(!_requiredResources.IsNull());
            _requiredResources.Unlock(this);
            p_consumed = true;
            LogInfo("%s started actual building of %s", ToString().c_str(), pGameBuilding->ToString().c_str());
        }
    }
}