Esempio n. 1
0
void StateProduce::Update( float dt, SelectableObject* pOwner )
{
	assert(pOwner->GetType() == eObjectType_Building);

	Building* pObj = static_cast<Building*>(pOwner);
	float fProgress = pObj->GetCurProgress();
	const STRING& unitName = pOwner->GetActiveAbility()->m_param;
	SUnitData* unitData = &GameDataDefManager::GetSingleton().m_unitData[unitName];
	float timeCost = Ogre::StringConverter::parseReal(unitData->params["timecost"]);

	if (fProgress > timeCost)
	{
		//生产完毕
		pOwner->GetAi()->SetCurState(eObjectState_Idle);

		//鲜活的单位出炉了
		SelectableObject* pNewObj = static_cast<SelectableObject*>(ObjectManager::GetSingleton().CreateObject(eObjectType_Unit));
		pNewObj->setParameter("name", unitName);
		static_cast<Unit*>(pNewObj)->Init();
		pNewObj->SetPosition(pObj->GetRallyPoint());
		pNewObj->AddComponent(eComponentType_Path, new PathComponent(pNewObj));

		//新单位进入空闲状态
		pNewObj->GetAi()->SetCurState(eObjectState_Idle);
	}
}
Esempio n. 2
0
bool StateTargeting::OnInputSys_MouseReleased( const OIS::MouseEvent& arg, OIS::MouseButtonID id )
{
	SelectableObject* pObj = World::GetSingleton().GetSelectedObjects().at(0);

	if (id == OIS::MB_Left)
	{
		pObj->GetAi()->GiveCommand(arg, id);
		//退出并行状态
		pObj->GetAi()->ClearParallelState();
	}
	else if (id == OIS::MB_Right)
	{
		//退出并行状态
		pObj->GetAi()->ClearParallelState();
	}

	return true;
}
Esempio n. 3
0
bool StateTargeting::OnInputSys_MouseMove( const OIS::MouseEvent &arg )
{
	SelectableObject* pObj = World::GetSingleton().GetSelectedObjects().at(0);
	eCommandType cmd = pObj->GetActiveAbility()->m_type;

	//获取当前鼠标hover下的物体
	Ogre::MovableObject* pMovable = World::GetSingleton().GetRaySceneQueryResult(arg, QueryTypeSelectableObject);
	SelectableObject* pHoverObj = nullptr;
	if(pMovable)
	{
		pHoverObj = Ogre::any_cast<SelectableObject*>(pMovable->getUserAny());
		assert(pHoverObj);
	}

	//根据当前命令类型确定鼠标样式
	Kratos::eCursorMode mode;
	switch (cmd)
	{
	case eCommandType_Move:
		{
			//无法移动..
			if(pHoverObj)
				mode = Kratos::eCursorMode_TargetInvalid;
			else
				mode = Kratos::eCursorMode_TargetNone;
		}
		break;

	case eCommandType_Gather:
		{
			if(pHoverObj && pHoverObj->GetType() == eObjectType_Resource)
				mode = Kratos::eCursorMode_TargetAllied;
			else
				mode = Kratos::eCursorMode_TargetInvalid;
		}
		break;

	case eCommandType_Attack:
		{
			if (pHoverObj)
			{
				if(pHoverObj->GetType() == eObjectType_Resource)
					mode = Kratos::eCursorMode_TargetInvalid;
				else if(pObj->GetAi()->IsAlly(pHoverObj))
					mode = Kratos::eCursorMode_TargetAllied;
				else
					mode = Kratos::eCursorMode_TargetEnemy;
			}
			else
			{
				mode = Kratos::eCursorMode_TargetNone;
			}
		}
		break;

	default: assert(0);
	}

	GUIMANAGER.SetCursorMode(mode);

	//让其他handler继续响应
	return false;
}