Example #1
0
	GLvoid CImp::checkGoldLevels()
	{
		if(this->getGold() >= this->maxgold)
		{
			path.clear();
			CBlock *destBlock;
			destBlock = CV_GAME_MANAGER->getRoomManager()->getRoom(CV_BLOCK_TYPE_TREASURE_ROOM_ID, this->getOwner());

			if(destBlock != NULL)
			{
				rooms::CRoom *currRoom = CV_GAME_MANAGER->getRoomManager()->getRoom(destBlock->getRoomIndex());

				for (std::vector<CBlock*>::iterator rmIter = currRoom->getRoomTilesVector()->begin(); rmIter != currRoom->getRoomTilesVector()->end(); rmIter++)
				{
					CBlock *thisBlock = *rmIter;
					bool found = false;

					for (std::vector<block_objects::CBlockObject*>::iterator rmIter = thisBlock->getBlockObjects()->begin(); rmIter != thisBlock->getBlockObjects()->end(); rmIter++)
					{
						block_objects::CBlockObject *bObject = *rmIter;

						if (bObject->getName() == "MODEL_GOLD250")
							found = true;

					}
					if(!found)
					{
						currBlock = thisBlock;
						break;
					}
				}

				if(currBlock)
				{
					cml::vector2i currPos = cml::vector2i((int)floor(position[0]/CV_BLOCK_WIDTH),(int)floor(position[2]/CV_BLOCK_DEPTH));
					if(CV_GAME_MANAGER->getPathManager()->findPath(currPos,currBlock->getLogicalPosition(),&path))
					{
						impState = IS_GOING_TO_DEPOSITING_GOLD_DESTINATION;
						return;
					}
				}
			}
			currBlock->addModel("MODEL_GOLD250",position);
			this->setGold(0);
		}
	}
Example #2
0
	void CImp::depositGold()
	{
		path.clear();
		CBlock *destBlock;
		destBlock = CV_GAME_MANAGER->getRoomManager()->getRoom(CV_BLOCK_TYPE_TREASURE_ROOM_ID, this->getOwner());

		if(destBlock != NULL)
		{
			rooms::CRoom *currRoom = CV_GAME_MANAGER->getRoomManager()->getRoom(destBlock->getRoomIndex());

			for (std::vector<CBlock*>::iterator rmIter = currRoom->getRoomTilesVector()->begin(); rmIter != currRoom->getRoomTilesVector()->end(); rmIter++)
			{
				CBlock *thisBlock = *rmIter;
				bool found = false;

				block_objects::CBlockObject *bObject = thisBlock->GetBlockByName( "MODEL_GOLD250" );
				if (bObject != NULL)
				{
					found = true;
					mCurrentBlock = (game_objects::CBlock *)bObject;
					break;
				}
			}

			if(mCurrentBlock)
			{
				cml::vector2i currPos = cml::vector2i((int)floor(mPosition[0]/CV_BLOCK_WIDTH),(int)floor(mPosition[2]/CV_BLOCK_DEPTH));
				if(CV_GAME_MANAGER->getPathManager()->findPath(currPos,mCurrentBlock->getLogicalPosition(),&path))
				{
					m_impState = IS_GOING_TO_DEPOSITING_GOLD_DESTINATION;
					return;
				}
			}
		}
		mCurrentBlock->addModel("MODEL_GOLD250",mPosition);
		this->setGold(0);
	}
Example #3
0
		GLvoid CRoomManager::addRoomTile(CBlock *block)
		{
			CLevelManager *lManager = CV_GAME_MANAGER->getLevelManager();

			vector2i pos = block->getLogicalPosition();

			vector2i posses[] = {vector2i(-1,0),vector2i(1,0),vector2i(0,-1),vector2i(0,1)};

			bool nbrs[4];

			nbrs[0] = lManager->isSameTypeAndOwner(pos[0]-1,pos[1],block);
			nbrs[1] = lManager->isSameTypeAndOwner(pos[0]+1,pos[1],block);
			nbrs[2] = lManager->isSameTypeAndOwner(pos[0],pos[1]-1,block);
			nbrs[3] = lManager->isSameTypeAndOwner(pos[0],pos[1]+1,block);

			GLint cnt = 0;

			cnt+=nbrs[0]?1:0;
			cnt+=nbrs[1]?1:0;
			cnt+=nbrs[2]?1:0;
			cnt+=nbrs[3]?1:0;

			if (cnt==0)
			{
				// create a new room
				CRoom *newRoom = new CRoom();
				newRoom->getRoomTilesVector()->push_back(block);
				newRoom->reownTiles();
				allRooms[newRoom->getIndex()] = newRoom;
				roomColors[newRoom->getIndex()] = vector3f((GLfloat)(rand()%101)/100.0f,(GLfloat)(rand()%101)/100.0f,(GLfloat)(rand()%101)/100.0f);

				CV_GAME_MANAGER->getConsole()->writeLine("A new room!");
			}
			else
			{
				GLint owner = -1;
				GLint roomIndex = -1;
				GLint type = -1;
				bool set = false;

				bool ok[] = {true, true, true};

				CBlock *testBlock = NULL;

				for (int i=0; i<4; i++)
				{
					if (nbrs[i])
					{
						testBlock = lManager->getBlock(pos+posses[i]);
						if (!set)
						{
							set = true;
							owner = testBlock->getOwner();
							roomIndex = testBlock->getRoomIndex();
							type = testBlock->getType();
						}
						else
						{
							ok[0] &= (owner == testBlock->getOwner());
							ok[1] &= (roomIndex == testBlock->getRoomIndex());
							ok[2] &= (type == testBlock->getType());
						}
					}
				}

				if (ok[0]&&ok[1]&&ok[2])
				{
					// all of same type, owner and room. just add this tile to this existing room
					allRooms[testBlock->getRoomIndex()]->getRoomTilesVector()->push_back(block);
					allRooms[testBlock->getRoomIndex()]->reownTiles();

					CV_GAME_MANAGER->getConsole()->writeLine("Tile added to the existing room.");
				}
				else
				{
					std::map<GLint, CBlock*> blockPerRoom;

					// we must make some merging
					for (int i=0; i<4; i++)
					{
						if (nbrs[i])
						{
							testBlock = lManager->getBlock(pos+posses[i]);
							blockPerRoom[testBlock->getRoomIndex()] = testBlock;
						}
					}

					// on this stage there are at least 2 elements in blockPerRoom.
					// take the first room and add it it all other room tiles.
					// then delete other rooms

					std::map<GLint, CBlock*>::iterator irIter = blockPerRoom.begin();

					CRoom *targetRoom = allRooms[irIter->first];

					irIter++;

					for (irIter; irIter!=blockPerRoom.end(); irIter++)
					{
						CRoom *room = allRooms[irIter->first];

						for (GLuint t=0; t<room->getRoomTilesVector()->size(); t++)
						{
							targetRoom->getRoomTilesVector()->push_back((*room->getRoomTilesVector())[t]);
						}

						// delete the unwanted room
						allRooms.erase(allRooms.find(irIter->first));
					}

					targetRoom->getRoomTilesVector()->push_back(block);

					targetRoom->reownTiles();

					CV_GAME_MANAGER->getConsole()->writeLine("Rooms merged.");
				}
			}
		}