Esempio n. 1
0
bool LevelWorkerAddRoom::AddFeature(Level* pLevel)
{
  int numRooms = m_roomNames.size();

  if (numRooms == 0)
  {
#ifdef _DEBUG
    std::cout << "Adding a room.\n";
#endif
    // In this case, just add a new empty room.
    int roomId = pLevel->GetNumberOfRooms();
    Room* pRoom = new Room(roomId);
    pRoom->Load("empty.room");
    pLevel->AddRoom(pRoom);
    pLevel->SetRoomId(roomId);
    std::cout << pLevel << " Level rooms (add feature): " << pLevel->GetNumberOfRooms() << "\n";
    return true;
  }

  for (int r = 0; r < numRooms; r++)
  {
    int roomId = r + pLevel->GetNumberOfRooms();
    Room* pRoom = new Room(roomId); 

    // Add scenery to room. This will depend on the level ID.
    std::string roomFileName = m_roomNames[r]; 
    pRoom->Load(roomFileName);
    pLevel->AddRoom(pRoom); 
    pLevel->SetRoomId(roomId);
  }

  return true;
} 
Esempio n. 2
0
static Vec2f GetRoomSize(int dest)
{
  // Expensive - only done when we are definitely changing room
  std::string filename = MakeRoomFilename(dest);
  File f;
  if (!f.OpenRead(filename))
  {
    Assert(0);
    return Vec2f();
  }
  std::string s;
  if (!f.GetDataLine(&s))
  {
    Assert(0);
    return Vec2f();
  }
  GameObject* go = TheGameObjectFactory::Instance()->Create(s);
  Room* room = dynamic_cast<Room*>(go);
  if (!room)
  {
    Assert(0);
    return Vec2f();
  }
  room->Load(&f);
  return room->GetSize();
}
Esempio n. 3
0
World::World( std::string Filename, int GameID )
{
  std::string workingkey;

  DataFilename = Filename;
	gameid = GameID;

	gamedb = new SQLiteDB( Filename.c_str() );

	int counter;

	// Load Combatant Skins
	counter = gamedb->QueryIntegerValue( "SELECT COUNT(*) FROM `CombatantSkins`;" );
  for( int i = 1; i <= counter; i++ )
  {
		std::string filename = gamedb->QueryStringValue( "SELECT Filename FROM `CombatantSkins` WHERE SkinID = " + Strings::FromNumber( i ) + ";" );
		ALLEGRO_BITMAP* skin = BitmapCache::LoadBitmap(filename);
		Palette::ApplyColourOverrides( skin );
		GameResources::CombatantGraphics.push_back( new PalettedBitmap( skin ) );
  }

	// Load Panel Sheets
	GameResources::ObjectGraphics = new PanelSheet();
	counter = gamedb->QueryIntegerValue( "SELECT COUNT(*) FROM `PanelSheets`;" );
  for( int i = 1; i <= counter; i++ )
  {
		std::string filename = gamedb->QueryStringValue( "SELECT Filename FROM `PanelSheets` WHERE SheetID = " + Strings::FromNumber( i ) + ";" );
		Palette::ApplyColourOverrides( BitmapCache::LoadBitmap(filename) );
		GameResources::ObjectGraphics->AddFromFile( filename );
  }

	Script_OnUpdate = gamedb->QueryStringValue( "SELECT OnUpdate FROM `World` WHERE GameID = " + Strings::FromNumber( GameID ) + ";" );

	Start_RoomID = gamedb->QueryIntegerValue( "SELECT StartRoomID FROM `World` WHERE GameID = " + Strings::FromNumber( GameID ) + ";" );
	Start_ScreenX = gamedb->QueryIntegerValue( "SELECT StartX FROM `World` WHERE GameID = " + Strings::FromNumber( GameID ) + ";" );
	Start_ScreenY = gamedb->QueryIntegerValue( "SELECT StartY FROM `World` WHERE GameID = " + Strings::FromNumber( GameID ) + ";" );
	Start_Facing = gamedb->QueryIntegerValue( "SELECT StartFacing FROM `World` WHERE GameID = " + Strings::FromNumber( GameID ) + ";" );

	TotalRooms = gamedb->QueryIntegerValue( "SELECT COUNT(*) FROM `Rooms` WHERE GameID = " + Strings::FromNumber( GameID ) + ";" );
  for( int i = 0; i < TotalRooms; i++ )
  {
    Room* r = new Room();
    r->Load( gamedb, GameID, i );
    Rooms.push_back( r );
  }

}
Esempio n. 4
0
void
Game::LoadMap( const std::string & filename )
{
  XMLDocument doc;
  doc.LoadFile(filename.c_str());


  if ( doc.ErrorID() != XML_NO_ERROR )
  {
    ostringstream ss;
    ss << "Loadfile:" << g_TinyXmlErrors[doc.ErrorID()] << " " << doc.GetErrorStr1() << " " << doc.GetErrorStr2();
    throw XmlParsingException(ss.str());

  }

  // Load rooms
  XMLElement *pElem = doc.FirstChildElement( "Room");
  
  while( pElem != NULL )
  {
    g_Log << "loading..." << pElem->Attribute("id");
    Room *pRoom  = NULL;
    // Custom rooms
    if ( pElem->Attribute("class")) 
    {
      std::string classID = pElem->Attribute("class");
      pRoom = RoomFactory::Create(classID);
    } 
    else 
    {
      pRoom = new Room();	
    }
    pRoom->Load( *pElem );
    if ( m_Rooms.find(pRoom->GetId()) != m_Rooms.end()) 
    {
      throw DuplicateRoomIdException(pRoom->GetId());
    }
    m_Rooms[pRoom->GetId()] = pRoom;
    pElem = pElem->NextSiblingElement("Room");
  }
  // Load transitions

  pElem = doc.FirstChildElement( "Transitions");
  if ( pElem != NULL ) 
  {
    pElem = pElem->FirstChildElement("Transition");
  
    while( pElem != NULL )
    {
      const char * from = pElem->Attribute("from");
      const char * to = pElem->Attribute("to");
      const char * direction = pElem->Attribute("direction");
      const char * oneway = pElem->Attribute("oneway");

      if ( direction == NULL ) throw AttributeMissingException("Direction is missing from transition");
      if ( from == NULL ) throw AttributeMissingException("From attribute is missing from transition!");
      if ( to == NULL )   throw AttributeMissingException("To attribute is missing from transition!");
    
      // check is from a proper id
      if ( m_Rooms.find(from) == m_Rooms.end() ) 
      { 
	ostringstream ss;
	ss << from << " is not a proper room id";
	throw InvalidAttributeException(ss.str());
      }
      // check is to a proper id
      if ( m_Rooms.find(to) == m_Rooms.end() ) 
      { 
	ostringstream ss;
	ss << to << " is not a proper room id";
	throw InvalidAttributeException(ss.str());
      }
      string tmp = direction;
      transform(tmp.begin(),tmp.end(), tmp.begin(), [] (char c){ return tolower(c);});    
      Direction dir = kNumDirs;
      if ( tmp == "east" ) dir = East;
      else if ( tmp == "north" ) dir = North;
      else if ( tmp == "south" ) dir = South;
      else if ( tmp == "west" ) dir = West;
      else throw InvalidAttributeException("Direction is not properly set");
   
      m_Rooms[from]->SetNextRoom(dir, m_Rooms[to]);
      if ( !oneway )
      {
	m_Rooms[to]->SetNextRoom(g_Opposite[dir], m_Rooms[from]);
      }
      pElem = pElem->NextSiblingElement("Transition");
    }
  } 
  else 
  {
    throw ElementMissingException("Transitions is missing!");
  }
  
  // set current room
  pElem = doc.FirstChildElement("OnStart");
  if ( pElem == NULL ) throw ElementMissingException("No OnStart defined");

  pElem = pElem->FirstChildElement("CurrentRoom");
  if ( pElem == NULL ) 
  {
    cout << "No current room set, problems might arise\n";
  } 
  else 
  {
    const char *szRoomId = pElem->Attribute("id");
    if ( szRoomId == NULL) throw InvalidAttributeException("Bad format CurrentRoom");
    string tmp = szRoomId;
    if ( m_Rooms.find(tmp) == m_Rooms.end() ) 
    {
      ostringstream ss;
      ss << "No room " << tmp << " found!";
      throw ElementMissingException(ss.str());
    }
    SetCurrentRoom(m_Rooms[tmp]);
  }
  pElem = doc.FirstChildElement("OnStart");
  pElem = pElem->FirstChildElement("Story");
  if ( pElem == NULL ) throw ElementMissingException("Story");
  m_Story = (pElem->GetText() == NULL) ? "" : pElem->GetText();

  pElem = doc.FirstChildElement("Player");
  if ( !pElem ) throw new ElementMissingException("Player");
  m_Player.Load(*pElem);
}