Ejemplo n.º 1
0
void SMOnlineRoom::SMOnlineParse(PacketFunctions &Packet, int clientnum) {
    int command = Packet.Read1();
    switch (command) {
    case 0:
        //Login
        break;
    case 1:
        //Change Room
    {
        int command = Packet.Read1();
        MString title = Packet.ReadNT();
        MString pw = Packet.ReadNT();
        ChangeRoom(command, title, clientnum, pw);
    }
    break;
    case 2:
        //Create new room
        if (m_allowgamerooms) {
            CreateRoom(Packet);
            ChangeRoom(1, m_joinrooms[m_joinrooms.size()-1]->GetTitle(), clientnum, "", true);
        }
        break;
    case 3:
        //Additional room info
        GenAdditionalInfo(Packet.ReadNT(), clientnum);
        break;
    default:
        LOG->Write(ssprintf("Invalid SMOnline command:%d", command));
        break;
    }
}
Ejemplo n.º 2
0
void NFCPVPMatchModule::ProcessSingePlayerRoom()
{
    NFGUID xSelf;
    for (int nPVPMode = 0; nPVPMode < EPVPMODE::EPVPMODE_THREE; nPVPMode++)
    {
        for (int nGrade = 0; nGrade < EPVPDEFINE_MAXGRADE; nGrade++)
        {
            const int nHavePlayer = m_pPVPMatchRedisModule->GetSinglePlayerCount(xSelf, nPVPMode, nGrade);
            const int nNeedPlayer = 2 * GetMemberCount(nPVPMode);
            if (nNeedPlayer > nHavePlayer)
            {
                continue;;
            }

            std::vector<NFGUID> xRedPlayer;
            std::vector<NFGUID> xBluePlayer;

            m_pPVPMatchRedisModule->PopSinglePlayerList(nPVPMode, nGrade, GetMemberCount(nPVPMode), xRedPlayer);
            m_pPVPMatchRedisModule->PopSinglePlayerList(nPVPMode, nGrade, GetMemberCount(nPVPMode), xBluePlayer);

            NFGUID xRoomID = CreateRoom(xSelf, nPVPMode, nGrade);
            PlayerListEnterRoom(xRedPlayer, EPVPREDORBLUE_RED, xRoomID);
            PlayerListEnterRoom(xBluePlayer, EPVPREDORBLUE_BULE, xRoomID);
        }
    }
}
Ejemplo n.º 3
0
//-------------------- FUNCOES: GERAIS --------------------//
GLvoid Init() { //Preparacao da cena
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //cor de fundo preta
    glEnable(GL_DEPTH_TEST); //ativa teste de prfundidade
    glDepthFunc(GL_LESS); //especifica a comparação de profundidade: mostra se for menor
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_RESCALE_NORMAL); //normalização dos vetores
    glShadeModel(GL_SMOOTH); //Rendering de Gourard

    //inicia valores para câmera
    obsX = width/2;
    obsY = height/2;
    obsZ = width/3;
    centerX = width/2;
    centerY = height/2;
    centerZ = -width;

    glViewport(0.0, 0.0, width, height); //define tamanho e localização da viewport

    glMatrixMode(GL_PROJECTION);  //define que matriz é de projecao
    glLoadIdentity();
    glOrtho(0, width, 0, height, -1, width*3); //Define projecao ortogonal para mapear coordenadas do mundo para coordenadas da tela

    CreateRoom(); //cria vertices/poligonos do cenario base
    LoadObjects(); //carrega objetos

    Lighting(); //ilumina cena
    Textures(); //aplica textura à cena
}
Ejemplo n.º 4
0
bool Simple::SetupModules ()
{
  // Now get the pointer to various modules we need. We fetch them
  // from the object registry. The RequestPlugins() call we did earlier
  // registered all loaded plugins with the object registry.
  g3d = csQueryRegistry<iGraphics3D> (GetObjectRegistry());
  if (!g3d) return ReportError("Failed to locate 3D renderer!");

  engine = csQueryRegistry<iEngine> (GetObjectRegistry());
  if (!engine) return ReportError("Failed to locate 3D engine!");

  vc = csQueryRegistry<iVirtualClock> (GetObjectRegistry());
  if (!vc) return ReportError("Failed to locate Virtual Clock!");

  kbd = csQueryRegistry<iKeyboardDriver> (GetObjectRegistry());
  if (!kbd) return ReportError("Failed to locate Keyboard Driver!");

  loader = csQueryRegistry<iLoader> (GetObjectRegistry());
  if (!loader) return ReportError("Failed to locate Loader!");

  // We need a View to the virtual world.
  view.AttachNew(new csView (engine, g3d));
  iGraphics2D* g2d = g3d->GetDriver2D ();
  // We use the full window to draw the world.
  view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ());

  // Here we create our world.
  CreateRoom();

  // Let the engine prepare all lightmaps for use and also free all images 
  // that were loaded for the texture manager.
  engine->Prepare ();
  rm = engine->GetRenderManager();

  // these are used store the current orientation of the camera
  rotY = rotX = 0;

  // Now we need to position the camera in our world.
  view->GetCamera ()->SetSector (room);
  view->GetCamera ()->GetTransform ().SetOrigin (csVector3 (0, 5, -3));

  // We use some other "helper" event handlers to handle 
  // pushing our work into the 3D engine and rendering it
  // to the screen.
  //drawer.AttachNew(new FrameBegin3DDraw (GetObjectRegistry (), view));
  printer.AttachNew(new FramePrinter (GetObjectRegistry ()));

  return true;
}
Ejemplo n.º 5
0
 //------------------------------------------------------------------------------
 void State::OnInit() noexcept
 {
     GetScene()->SetClearColour(CS::Colour::k_black);
     
     auto basicEntityFactory = CS::Application::Get()->GetSystem<Common::BasicEntityFactory>();
     
     CS::EntitySPtr room = basicEntityFactory->CreateRoom();
     room->GetTransform().SetPosition(0.0f, 10.0f, 0.0f);
     GetScene()->Add(room);
     
     auto camera = basicEntityFactory->CreateThirdPersonCamera(room, CS::Vector3(0.0f, -9.0f, 0.0f));
     GetScene()->Add(std::move(camera));
     
     CreateLights(GetScene());
     AddAnimatedModel(GetScene());
 }
Ejemplo n.º 6
0
void MapGenerator::Generate()
{
	// first, make the map solid rock.
	memset(map.data(), '#', map.num_elements());

	// create some random rooms
	Position a, b;
	int i;
	int rooms = rng.nDice(3, 3)-1;
	for (i = 0; i < rooms; i++)
	{
		int width = rng.nDice(3, 4) + std::max(5-rooms, 0);
		int height = rng.nDice(2, 4) + std::max(4-rooms, 0);

		a.x = rng.rnd(map_width-width-2)+1;
		b.x = a.x + width;
		a.y = rng.rnd(map_height-height-2)+1;
		b.y = a.y + height;

		CreateRoom(a, b);
	}

	// and join them up, however
	for (int j = 0, i = 1; i < rooms; i++)
	{
		if (j == i)
			j--; // j cannot overtake i.
		JoinRooms(j, i);
		j+=rng.rnd(3);
	}
	GenerateDoors();

	// add a random '>', and '<'
	do
	{
		a.x = rng.rnd(map_width);
		a.y = rng.rnd(map_height);
	} while (map[a.x][a.y] != '.');
	map[a.x][a.y] = '>';
	do
	{
		a.x = rng.rnd(map_width);
		a.y = rng.rnd(map_height);
	} while (map[a.x][a.y] != '.');
	map[a.x][a.y] = '<';
}
Ejemplo n.º 7
0
void SimpleDungeonMapGenerator::ProcessOneStep(Map* theMap)
{
	enum type{ room , hallway };
	Vec2i location;
	int locateTime = 0;
	int numOfAirInOrthogonal = 0;

	while(locateTime < 10000)
	{
		location = Vec2i((int)(getRandomPercent() * theMap->m_mapSize.x) , (int)(getRandomPercent() * theMap->m_mapSize.y));
		numOfAirInOrthogonal = theMap->GetNumOfTypeInOrthogonal(location.x,location.y,1,AIR);
		
		if(numOfAirInOrthogonal == 1)
		{
			type rollType = getRandomPercent() < 0.5 ? room : hallway;
			Vec2i oppositeDirection = theMap->GetDirectionOfTypeInOrthogonal(location.x,location.y,1,AIR) * -1;
			bool generated = false;

			if( rollType == room)
			{
				Vec2i roomSize = Vec2i((int)(m_halfOfMaximumSizeOfARoom.x * getRandomPercent() + 2),(int)(m_halfOfMaximumSizeOfARoom.y * getRandomPercent() + 2));
				generated = CreateRoom(theMap,location,roomSize);
			}
			
			if(rollType == hallway)
			{
				int length = (int)(m_maximumOfLength * getRandomPercent() + 3);
				generated = CreateHallway(theMap,location,oppositeDirection,length);
			}
			
			if(generated)
				break;
		}

		locateTime++;
	}
}
Ejemplo n.º 8
0
//==============================================================
// 区画を分ける
//==============================================================
void CDunHard::SplitRect(int nParentRectIndex, int nFlagHV)
{
	DUNRECT *pParent, *pChild;
	RECT *pRect;
	int nChildIndex1 = 0, nChildIndex2 = 0;

	// わける区画情報を取得
	pParent = &m_Rect[nParentRectIndex];
	pRect   = &pParent->Rect;

	//---------
	// 分割する
	//---------
	if((nFlagHV & 1) == 0) {
		// 横に分割する
		nFlagHV |= 1;

		// 区分を分割できるか?チェック
		if(RECT_W(*pRect) >= (MIN_ROOM_SIZE + 3) * 2 + 1) {
			int a, b, ab, p;
			// 左端のA点を求める
			a = MIN_ROOM_SIZE + 3;

			// 右端のB点を求める
			b = RECT_W(*pRect) - MIN_ROOM_SIZE - 4;

			// ABの距離を求める
			ab = b - a;

			// AB間のどこかに決定する
			p = a + GetRand(ab + 1);

			// 新しく右の区画を作成する
			pChild = CreateRect(pRect->left + p,
								pRect->top,
								pRect->right,
								pRect->bottom);

			// 元の区画の右を p 地点に移動させて、左側の区画とする
			pParent->Rect.right = pChild->Rect.left;

			// 子の部屋をさらに分割する
			nChildIndex1 = DunrectToIndex(pChild);
			SplitRect(nChildIndex1, 0);
		}
	}

	if((nFlagHV & 2) == 0) {
		// 縦に分割する
		nFlagHV |= 2;

		// 区分を分割できるか?チェック
		if( RECT_H(*pRect) >= (MIN_ROOM_SIZE+3)*2+1 ) {
			int a, b, ab, p;
			a = MIN_ROOM_SIZE + 3;
			b = RECT_H(*pRect) - MIN_ROOM_SIZE - 4;
			ab = b - a;

			p = a + GetRand(ab + 1);

			// 新しく下の区画を作成する
			pChild = CreateRect(pRect->left,
								pRect->top + p,
								pRect->right,
								pRect->bottom);

			// 元の区画の下を p 地点に移動させて、上側の区画とする
			pParent->Rect.bottom = pChild->Rect.top;

			// 子の部屋をさらに分割する
			nChildIndex2 = DunrectToIndex(pChild);
			SplitRect(nChildIndex2, 0);
		}
	}

	// 部屋を作る
	CreateRoom(nParentRectIndex);

	// 子供とつなげる
	if(nChildIndex1) {
		CreateRoad( nParentRectIndex, nChildIndex1 );
	}
	if(nChildIndex2) {
		CreateRoad( nParentRectIndex, nChildIndex2 );
	}
}
Ejemplo n.º 9
0
bool NFCPVPMatchModule::TeamApplyPVP(const NFGUID& xTeam, const NFIDataList& varMemberList, int nPVPMode, const int nScore)
{
    int nMemberCount = varMemberList.GetCount();
    std::vector<NFGUID> xPlayerList;
    for (int i = 0; i < varMemberList.GetCount(); i++)
    {
        const NFGUID& xPlayerID = varMemberList.Object(i);
        if (xPlayerID.IsNull())
        {
            return false;
        }

        xPlayerList.push_back(xPlayerID);
    }

    int nGrade = GetGradeByScore(nScore);

    int nPVPModeMaxMember = GetMemberCount(nPVPMode);
    if (nPVPModeMaxMember < 0)
    {
        return false;
    }

    if (nMemberCount > nPVPModeMaxMember)
    {
        return false;
    }

    NFGUID xFindRoomID;
    int bRed = EPVPREDORBLUE_RED;
    std::vector<NFGUID> xRoomIDList;
    if (m_pPVPMatchRedisModule->GetStatusRoomID(nPVPMode, nGrade, EPVPROOMSTATUS_WAIT, xRoomIDList))
    {
        for (int i = 0; i < xRoomIDList.size(); i++)
        {
            const NFGUID& xRoomID = xRoomIDList[i];
            NFMsg::PVPRoomInfo xRoomInfo;
            if (m_pPVPMatchRedisModule->GetRoomInfo(xRoomID, xRoomInfo))
            {
                if ((xRoomInfo.xredplayer_size() + nMemberCount) < xRoomInfo.maxpalyer())
                {
                    xFindRoomID = xRoomID;
                    bRed = EPVPREDORBLUE_RED;
                    break;
                }
                else if ((xRoomInfo.xblueplayer_size() + nMemberCount) < xRoomInfo.maxpalyer())
                {
                    xFindRoomID = xRoomID;
                    bRed = EPVPREDORBLUE_BULE;
                    break;
                }
            }
        }
    }

    if (xFindRoomID.IsNull())
    {
        xFindRoomID = CreateRoom(NFGUID(), nPVPMode, nGrade);
        if (xFindRoomID.IsNull())
        {
            return false;
        }

        m_pPVPMatchRedisModule->SetStatusRoomID(nPVPMode, nGrade, EPVPROOMSTATUS_WAIT, xFindRoomID);
    }

    return PlayerListEnterRoom(xPlayerList, bRed, xFindRoomID);
}
Ejemplo n.º 10
0
bool AvatarTest::Application ()
{
  if (!OpenApplication (GetObjectRegistry ()))
    return ReportError ("Error opening system!");

  g3d = csQueryRegistry<iGraphics3D> (GetObjectRegistry ());
  if (!g3d) return ReportError("Failed to locate 3D renderer!");

  engine = csQueryRegistry<iEngine> (GetObjectRegistry ());
  if (!engine) return ReportError("Failed to locate 3D engine!");

  vc = csQueryRegistry<iVirtualClock> (GetObjectRegistry ());
  if (!vc) return ReportError("Failed to locate Virtual Clock!");

  kbd = csQueryRegistry<iKeyboardDriver> (GetObjectRegistry ());
  if (!kbd) return ReportError("Failed to locate Keyboard Driver!");

  loader = csQueryRegistry<iLoader> (GetObjectRegistry ());
  if (!loader) return ReportError("Failed to locate Loader!");

  g2d = csQueryRegistry<iGraphics2D> (GetObjectRegistry ());
  if (!g2d) return ReportError("Failed to locate 2D renderer!");

  lookAtManager = csQueryRegistry<iSkeletonLookAtManager2> (GetObjectRegistry ());
  if (!lookAtManager) return ReportError("Failed to locate iLookAtManager plugin!");

  basicNodesManager =
    csQueryRegistry<iSkeletonBasicNodesManager2> (GetObjectRegistry ());
  if (!basicNodesManager)
    return ReportError("Failed to locate iSkeletonBasicNodesManager2 plugin!");

  printer.AttachNew (new FramePrinter (GetObjectRegistry ()));

  csRef<iFontServer> fs = g3d->GetDriver2D()->GetFontServer ();
  if (fs)
    courierFont = fs->LoadFont (CSFONT_COURIER);
  else return ReportError ("Failed to locate font server!");

  // Create the dynamic system
  if (physicsEnabled)
  {
    dynamicSystem = dynamics->CreateSystem ();
    if (!dynamicSystem) 
    {
      ReportWarning
	("Can't create dynamic system, continuing with reduced functionalities");
      physicsEnabled = false;
    }

    else
    {
      // Load the ragdoll plugin
      csRef<iPluginManager> plugmgr = 
	csQueryRegistry<iPluginManager> (GetObjectRegistry ());
      ragdollManager = csLoadPlugin<iSkeletonRagdollManager2>
	(plugmgr, "crystalspace.mesh.animesh.controllers.ragdoll");
      if (!ragdollManager)
      {
	ReportWarning
	  ("Can't load ragdoll plugin, continuing with reduced functionalities");
	physicsEnabled = false;
      }
    }
  }

  // Create sector
  room = engine->CreateSector ("room");

  // Initialize camera
  view = csPtr<iView> (new csView (engine, g3d));
  view->GetCamera ()->SetSector (room);
  iGraphics2D* g2d = g3d->GetDriver2D ();
  view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ());

  // Create scene
  CreateRoom ();

  // Create avatar
  if (avatarModel == MODEL_KRYSTAL)
    avatarScene = new KrystalScene (this);
  else
    avatarScene = new FrankieScene (this);
  if (!avatarScene->CreateAvatar ())
    return false;

  // Initialize camera position
  view->GetCamera ()->GetTransform ().SetOrigin (avatarScene->GetCameraStart ());

  // Run the application
  Run();

  return true;
}