示例#1
0
bool CStructure::CanAutoCloseMenu() const
{
	CPlayerCharacter* pOwner = GetOwner()->GetPlayerCharacter();

	if (!pOwner)
		return false;

	if (GetOwner()->IsInBlockPlaceMode())
		return true;

	if (GetOwner()->IsInBlockDesignateMode())
		return true;

	if (GetOwner()->IsInConstructionMode())
		return true;

	TVector vecPlayerEyes = pOwner->GetLocalOrigin() + pOwner->EyeHeight() * DoubleVector(pOwner->GetLocalUpVector());
	TVector vecOwnerProjectionPoint = GetLocalOrigin() + GetLocalTransform().TransformVector(GameData().GetCommandMenuRenderOffset());

	Vector vecToPlayerEyes = (vecPlayerEyes - vecOwnerProjectionPoint).GetMeters();
	float flDistanceToPlayerEyes = vecToPlayerEyes.Length();
	Vector vecProjectionDirection = vecToPlayerEyes/flDistanceToPlayerEyes;

	float flViewAngleDot = AngleVector(pOwner->GetViewAngles()).Dot(vecProjectionDirection);

	if (GameData().GetCommandMenu() && (GameData().GetCommandMenu()->WantsToClose() || flDistanceToPlayerEyes > 5 || flViewAngleDot > -0.7))
		return true;

	return false;
}
示例#2
0
void CStructure::PostSetLocalTransform(const TMatrix& m)
{
	BaseClass::PostSetLocalTransform(m);

	CPlanet* pPlanet = GameData().GetPlanet();
	if (!pPlanet)
		return;

	if (!pPlanet->GetChunkManager()->HasGroupCenter())
		return;

	TMatrix mLocalTransform = m;

	CBaseEntity* pMoveParent = GetMoveParent();
	if (pMoveParent)
	{
		while (pMoveParent != pPlanet)
		{
			mLocalTransform = pMoveParent->GetLocalTransform() * mLocalTransform;
			pMoveParent = pMoveParent->GetMoveParent();
		}
	}
	else
		mLocalTransform = pPlanet->GetGlobalToLocalTransform() * m;

	GameData().SetGroupTransform(pPlanet->GetChunkManager()->GetPlanetToGroupCenterTransform() * mLocalTransform.GetMeters());
}
示例#3
0
move boardCalc::getMoveUncoverDeepest(PIECE p)
{
	vector<move> moves = GameData()->board.getDeepestPiecesMoves(p);

	int randomMove = GameData()->randInt(0, moves.size()-1);
	return moves.at(randomMove);
}
示例#4
0
void CStructure::PerformStructureTask(class CSPCharacter* pCharacter)
{
	if (IsUnderConstruction() && !m_flConstructionTurnTime)
	{
		if (pCharacter->GetControllingPlayer())
			pCharacter->GetControllingPlayer()->Instructor_LessonLearned("develop-structures");

		m_flConstructionTurnTime = GameServer()->GetGameTime();

		CPlayer* pPlayer = pCharacter->GetControllingPlayer();
		if (pPlayer)
		{
			CSPPlayer* pSPPlayer = static_cast<CSPPlayer*>(pPlayer);

			if (!pSPPlayer->GetActiveCommandMenu())
				GameData().CreateCommandMenu(pSPPlayer->GetPlayerCharacter());

			// If it's a player who's building this structure then close any other command menus and activate this one.
			if (pSPPlayer->GetActiveCommandMenu()->GetOwner() != this)
			{
				pSPPlayer->GetActiveCommandMenu()->GetOwner()->GameData().CloseCommandMenu();
				GameData().CreateCommandMenu(pSPPlayer->GetPlayerCharacter());
			}
		}

		if (GameData().GetCommandMenu())
			SetupMenuButtons();
	}

	if (!IsUnderConstruction())
	{
		if (pCharacter->GetControllingPlayer())
			pCharacter->GetControllingPlayer()->Instructor_LessonLearned("interact-with-structures");
	}
}
示例#5
0
void CStructure::SetPhysicsTransform(const Matrix4x4& m)
{
	CPlanet* pPlanet = GameData().GetPlanet();
	if (!pPlanet)
	{
		SetLocalTransform(TMatrix(m));
		return;
	}

	if (!pPlanet->GetChunkManager()->HasGroupCenter())
	{
		SetLocalTransform(TMatrix(m));
		return;
	}

	GameData().SetGroupTransform(m);

	TMatrix mLocalTransform(pPlanet->GetChunkManager()->GetGroupCenterToPlanetTransform() * m);

	CBaseEntity* pMoveParent = GetMoveParent();
	TAssert(pMoveParent);
	if (pMoveParent)
	{
		while (pMoveParent != pPlanet)
		{
			mLocalTransform = pMoveParent->GetLocalTransform().InvertedRT() * mLocalTransform;
			pMoveParent = pMoveParent->GetMoveParent();
		}
	}

	SetLocalTransform(mLocalTransform);
}
示例#6
0
void CStructure::PostRender() const
{
	BaseClass::PostRender();

	if (!GameServer()->GetRenderer()->IsRenderingTransparent())
		return;

	if (GameData().GetCommandMenu())
		GameData().GetCommandMenu()->Render();
}
示例#7
0
void CStructure::SetPowerCord(CPowerCord* pCord)
{
	if (m_hPowerCord)
		m_hPowerCord->Delete();

	m_hPowerCord = pCord;

	if (GameData().GetCommandMenu())
		GameData().CloseCommandMenu();
}
示例#8
0
move boardCalc::getRandomMove(PIECE p)
{
	vector<move> moves = GameData()->board.getPossibleMoves(p);
	if(moves.size() > 0)
	{
		int i = GameData()->randInt(0, moves.size()-1);
		return moves.at(i);
	}
	return MOVE_NULL;

}
示例#9
0
const Matrix4x4 CStructure::GetPhysicsTransform() const
{
	CPlanet* pPlanet = GameData().GetPlanet();
	if (!pPlanet)
		return GetLocalTransform();

	if (!pPlanet->GetChunkManager()->HasGroupCenter())
		return GetLocalTransform();

	return GameData().GetGroupTransform();
}
示例#10
0
int boardCalc::getTallestStackSize(PIECE p)
{
	vector<move> moves = GameData()->board.getPossibleMoves(p);
	int tallest = 0;
	for(int i = 0; i < moves.size(); i++)
	{
		int thisheight = GameData()->board.GetSizeOfStack(moves.at(i).beginpos);
		if(thisheight > tallest)
			tallest = thisheight; 
	}
	return tallest;
}
示例#11
0
void AIStateRegular::onBoardChange()
{
	vector<int> possibleActiveMoves;

	if (GameData()->board.IsPieceOnTop(this->stateMachine->player->piece, 6) || GameData()->board.IsPieceOnTop(this->stateMachine->player->piece, 7))
	{
		if (GameData()->board.GetSizeOfStack(6) == 4 || GameData()->board.GetSizeOfStack(7) == 3)
		{
			this->stateMachine->setState(ST_ADVST);
			return;
		}
		else
			return;
	}

	if(GameData()->board.IsPieceOnTop(this->stateMachine->player->piece, MAX_GAME_POSITIONS-1))
	{
		this->stateMachine->setState(ST_RUSH_TO_END);
		return;
	}
	if(GameData()->board.IsPieceOnTop(this->stateMachine->player->piece, MAX_GAME_POSITIONS-2))
	{	
		this->stateMachine->setState(ST_RUSH_TO_END);
		return;
	}
	if(GameData()->board.IsPieceOnTop(this->stateMachine->player->piece, MAX_GAME_POSITIONS-3))
	{	
		this->stateMachine->setState(ST_RUSH_TO_END);
		return;
	}
	


	vector<move> moves = GameData()->board.getPossibleMoves(this->stateMachine->player->piece);//getting all possible moves.
	vector<move> noDuplicateMoves;

	for(int i = 0; i < moves.size(); i++)
	{
		if(i == 0)
			noDuplicateMoves.push_back(moves.at(i));
		if (!(i == 0) && !(moves.at(i -1).beginpos == moves.at(i).beginpos))
			noDuplicateMoves.push_back(moves.at(i));
	}

	
	if (noDuplicateMoves.size() < ableToMovePiece)
	{
		cout<<"I got attack!?!?!?!>!>!>"<<endl;
		ableToMovePiece--;
		emotion++;
	}
	cout<<"emotion                     : "<<emotion<<endl;
	cout<<"noDuplicateMoves            : "<<noDuplicateMoves.size()<<endl;
	cout<<"ableToMove in Privious turn : "<<ableToMovePiece<<endl;
	


	if (emotion > 2)
		this->stateMachine->setState(ST_ANGRY);
}
示例#12
0
bool boardCalc::canMove(PIECE p)
{
	vector<move> moves = GameData()->board.getPossibleMoves(p);
	if(moves.size() > 0)
		return true;
	return false;
}
示例#13
0
bool CStructure::CanAutoOpenMenu() const
{
	CPlayerCharacter* pOwner = GetOwner()->GetPlayerCharacter();

	if (!pOwner)
		return false;

	if (GetOwner()->IsInBlockPlaceMode())
		return false;

	if (GetOwner()->IsInBlockDesignateMode())
		return false;

	if (GetOwner()->IsInConstructionMode())
		return false;

	TVector vecPlayerEyes = pOwner->GetLocalOrigin() + pOwner->EyeHeight() * DoubleVector(pOwner->GetLocalUpVector());
	TVector vecOwnerProjectionPoint = GetLocalOrigin() + GetLocalTransform().TransformVector(GameData().GetCommandMenuRenderOffset());

	Vector vecToPlayerEyes = (vecPlayerEyes - vecOwnerProjectionPoint).GetMeters();
	float flDistanceToPlayerEyes = vecToPlayerEyes.Length();
	Vector vecProjectionDirection = vecToPlayerEyes/flDistanceToPlayerEyes;

	float flViewAngleDot = AngleVector(pOwner->GetViewAngles()).Dot(vecProjectionDirection);

	CSPPlayer* pPlayerOwner = static_cast<CSPPlayer*>(pOwner->GetControllingPlayer());

	if (!GameData().GetCommandMenu() && flDistanceToPlayerEyes < 4 && flViewAngleDot < -0.8 && !pPlayerOwner->GetActiveCommandMenu())
		return true;

	return false;
}
示例#14
0
// The main render function (can be used to call other rendering functions)
void RenderMainBoard()
{
	// Render the board
	GameData()->board.Render();

	// Render player scores?
}
示例#15
0
void AIStateHint6::doTurn(Player player)
{
	move m = boardCalc::getMoveUncoverDeepest(player.piece);
	if(!m.isNull())
		GameData()->board.MovePiece(m.beginpos, m.endpos);

}
示例#16
0
move boardCalc::getFarthestMove(PIECE p)
{
	vector<move> moves = GameData()->board.getPossibleMoves(p);
	int tallest = 0;
	move best = MOVE_NULL;

	for(int i = 0; i < moves.size(); i++)
	{
		int thisheight = GameData()->board.GetSizeOfStack(moves.at(i).beginpos);
		if(thisheight > tallest)
		{
			tallest = thisheight; 
			best = moves.at(i);
		}
	}
	return best;
}
示例#17
0
std::shared_ptr<GameData> GameData::getInstance() {
    std::shared_ptr<GameData> ptr = m_instance.lock();
    if (!ptr) {
        ptr = std::make_shared<GameData>(GameData());
        m_instance = std::weak_ptr<GameData>(ptr);
    }
    return ptr;
}
示例#18
0
//Moved -> State 7
//Cannot Move -> SkipTurn, State 7
void AIStateHint4::doTurn(Player player)
{	
	move m = boardCalc::getMoveStackHighest(player.piece);
	if(!m.isNull())
	{
		GameData()->board.MovePiece(m.beginpos, m.endpos);
	}

	this->stateMachine->setState(ST_HINT_7);
}
示例#19
0
move boardCalc::getMoveSetBounce(PIECE p)
{
	vector<move> goodmoves = vector<move>();
	//search for any move that will land in front of trampoline and remember end points.
	vector<int> search = vector<int>();
	for(int si = 0; si < GameData()->numplayers; si++)
	{
		vector<move> moves = GameData()->board.getPossibleMoves(
			GameData()->players.at(si).piece
		);
		for (int i = 0; i < moves.size(); i++)
		{
			move m = moves.at(i);
			if(m.endpos == 9) //land on trampoline
			{
				if(m.endpos - m.beginpos >= 2) //distance of 2 or more
					search.push_back(m.beginpos);
			}
		}
	}

	//GET OUR MOVES THAT WILL LAND ON A POTENTIAL TRAMPOLINE!
	//All our valid moves
	vector<move> ourmoves = GameData()->board.getPossibleMoves(p);
	for (int i = 0; i < ourmoves.size(); i++)
	{
		move m = ourmoves.at(i);

		//We wanna land on one of those tiles
		for(int j = 0; j < search.size(); j++)
		{
			if(m.endpos == search.at(j)) //land on trampoline
			{
				goodmoves.push_back(m);
			}
		}
	}

	//Do the piece that is closest to start to setup that move.
	if(goodmoves.size() > 0)
		return goodmoves.at(goodmoves.size()-1);
	return MOVE_NULL;
}
示例#20
0
Game* Engine::CreateGame()
{
	// Create a new game
	if (!AddSystem(new Game(GameData()))) { return nullptr; }
	Game* game = GetSystem<Game>(SystemType::Sys_Game);
	if (!game) { return nullptr; }
	if (!game->Initialize()) { return nullptr; }

	return game;
}
示例#21
0
Game* Engine::CreateGame(){
	if (!AddSystem(new Game(GameData())))
		return nullptr;
	Game* game = GetSystem<Game>(SystemType::Sys_Game);
	if (!game)
		return nullptr;
	/*if (!game->Initialize());
	return nullptr;*/

	return game;
}
示例#22
0
 void Game::newGame(GameData::PlayerID originatorID)
 {
   if (mPlayers.count(originatorID))
   {
     mGameData = GameData();
     mOriginatorID = originatorID;
     mCurrentPlayerID = originatorID;
     InputData input(mPlayers[originatorID]->getInput(InputData::NEED_NEW_SECRET_NUMBER));
     mSecretNumber = input.guess;
   }
 }
示例#23
0
//Moved, Stack of > 1 Exists -> State 7
//Moved, no >1 Stacks -> Stay in this State
void AIStateHint5::doTurn(Player player)
{	
	move m = boardCalc::getRandomMove(player.piece);
	if(!m.isNull())
		GameData()->board.MovePiece(m.beginpos, m.endpos);

	if(boardCalc::getTallestStackSize(player.piece) > 1)
	{
		this->stateMachine->setState(ST_HINT_7);
		return;
	}
}
示例#24
0
bool CStructure::ShouldRenderTransparent() const
{
	if (SPGame()->GetSPRenderer()->GetRenderingScale() != SCALE_RENDER)
		return false;

	if (IsUnderConstruction())
		return true;

	if (GameData().GetCommandMenu())
		return true;

	return BaseClass::ShouldRenderTransparent();
}
示例#25
0
文件: gameflow.cpp 项目: ggj/reapers
bool GameFlow::Initialize()
{
	IGameApp::Initialize();
	return cPres.Load("configs/game.config", [&](Presentation *, Viewport *aborted)
	{
		if (!aborted)
		{
			pSoundSystem->SetMusicVolume(0.6f);
			pSoundSystem->SetSfxVolume(0.5f);

			// Create the State Machine Data
			gGameData = sdNew(GameData());

			if (this->SaveSystemFlow())
				pSaveSystem->Load(0, &gGameData->sPlayer, &gGameData->sOptions);

			// Create the transitions
			cMenuToGame.Initialize(&cMenu, &cOnGame, &cGame);
			cMenuToOptions.Initialize(&cMenu, &cOnOptions, &cOptions);
			cMenuToCredits.Initialize(&cMenu, &cOnCredits, &cCredits);
			cOptionsToMenu.Initialize(&cOptions, &cOnMenu, &cMenu);
			cCreditsToMenu.Initialize(&cCredits, &cOnMenu, &cMenu);
			cGameToMenu.Initialize(&cGame, &cOnMenu, &cMenu);
			cGameToLoad.Initialize(&cGame, &cOnLoad, &cLoad);
			cLoadToGame.Initialize(&cLoad, &cOnGame, &cGame);

			// Create the State Machine.
			cFlow.RegisterTransition(&cMenuToGame);
			cFlow.RegisterTransition(&cMenuToOptions);
			cFlow.RegisterTransition(&cMenuToCredits);
			cFlow.RegisterTransition(&cOptionsToMenu);
			cFlow.RegisterTransition(&cCreditsToMenu);
			cFlow.RegisterTransition(&cGameToMenu);
			cFlow.RegisterTransition(&cGameToLoad);
			cFlow.RegisterTransition(&cLoadToGame);

			pSystem->AddListener(this);
			pInput->AddKeyboardListener(this);

			auto viewport = cPres.GetViewportByName("MainView");
			pScene = viewport->GetScene();
			pCamera = viewport->GetCamera();

			sdNew(GuiManager());
			gGui->Initialize();
			pScene->Add(gGui->GetSceneObject());

			cFlow.Initialize(&cMenu);
		}
	});
}
示例#26
0
//Pile it high!
move boardCalc::getMoveStackHighest(PIECE p)
{
	vector<move> moves = GameData()->board.getPossibleMoves(p);
	int highest = 1; //so that it is 2 or more
	move bestmove = move(-1,-1);


	//get good moves
	for (int i = 0; i < moves.size(); i++)
	{
		move m = moves.at(i);
		int size = GameData()->board.GetSizeOfStack(m.endpos);
		if(size > highest)
		{
			highest = size;	
			bestmove.beginpos = m.beginpos;
			bestmove.endpos = m.endpos;
		}
	}

	if(bestmove.endpos != -1)
		return bestmove;
	return MOVE_NULL;
}
示例#27
0
int boardCalc::getUncoveredCount(PIECE p)
{
	vector<move> moves = GameData()->board.getPossibleMoves(p);

	int lastbegin = -100;
	int count = 0;
	for(int i = 0; i < moves.size(); i++)
	{
		if(lastbegin != moves.at(i).beginpos)
		{
			count++;
			lastbegin = moves.at(i).beginpos;
		}
	}
	return count;
}
示例#28
0
	void Initialize(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS * pPP) {
		device = pDevice;
		device->GetCreationParameters(&cparams);
		GetClientRect(cparams.hFocusWindow, &gameWindow);
		heightModifier = gameWindow.bottom / 1080.0;
		widthModifier = gameWindow.right / 1920.0;
		D3DXCreateFont(device, (int)(40 * heightModifier * (heightModifier + .85 * (1-heightModifier))), 0, FW_NORMAL, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 5, DEFAULT_PITCH | FF_DONTCARE, L"Verdana", &pFont);
		textColor = D3DXCOLOR(207, 210, 232, 1);
		rectColor = D3DCOLOR_XRGB(32, 32, 32);
		memory = GameData();

		int left = (int)(855 * widthModifier);
		int top = (int)(304 * heightModifier);
		int right = (int)(left + 285 * widthModifier);
		int bottom = (int)(top + 50 * heightModifier);
		rectangle = { left, top, right, bottom};
		textrect = { left, top, right, bottom};
	}
示例#29
0
void CStructure::ConstructionTurn()
{
	if (!m_flConstructionTurnTime)
		return;

	m_flConstructionTurnTime = 0;

	if (m_iTurnsToConstruct <= 0)
		return;

	m_iTurnsToConstruct--;

	if (GameData().GetCommandMenu())
		SetupMenuButtons();

	if (!m_iTurnsToConstruct)
		FinishConstruction();
}
示例#30
0
void CStructure::Spawn()
{
	m_bTakeDamage = true;

	m_flConstructionTurnTime = 0;

	m_eStructureType = StructureType();
	TAssert(m_eStructureType);

	GameData().SetCommandMenuParameters(Vector(0, 1, 0), 0.5f, 1.0f);

	BaseClass::Spawn();

	SetTotalHealth(50);

	m_iBatteryLevel = 0;
	m_iMaxBatteryLevel = MaxBatteryLevel();
}